tesseract  5.0.0-alpha-619-ge9db
bitvec.h
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: bitvec.h
3  ** Purpose: Routines for manipulating bit vectors
4  ** Author: Dan Johnson
5  **
6  ** (c) Copyright Hewlett-Packard Company, 1988.
7  ** Licensed under the Apache License, Version 2.0 (the "License");
8  ** you may not use this file except in compliance with the License.
9  ** You may obtain a copy of the License at
10  ** http://www.apache.org/licenses/LICENSE-2.0
11  ** Unless required by applicable law or agreed to in writing, software
12  ** distributed under the License is distributed on an "AS IS" BASIS,
13  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  ** See the License for the specific language governing permissions and
15  ** limitations under the License.
16  ******************************************************************************/
17 
18 #ifndef BITVEC_H
19 #define BITVEC_H
20 
21 #include <cstddef> // for size_t
22 #include <cstdint> // for uint32_t
23 
24 /*-----------------------------------------------------------------------------
25  Include Files and Type Defines
26 -----------------------------------------------------------------------------*/
27 
28 using BIT_VECTOR = uint32_t*;
29 
30 //< no of bits in a BIT_VECTOR element
31 const size_t BITSINLONG = 8 * sizeof(uint32_t);
32 
33 /*-----------------------------------------------------------------------------
34  Public Function Prototypes
35 -----------------------------------------------------------------------------*/
36 
37 static inline void zero_all_bits(BIT_VECTOR array, size_t length) {
38  for (size_t index = 0; index < length; index++) {
39  array[index] = 0;
40  }
41 }
42 
43 static inline void set_all_bits(BIT_VECTOR array, size_t length) {
44  for (size_t index = 0; index < length; index++) {
45  array[index] = ~0;
46  }
47 }
48 
49 static inline void copy_all_bits(BIT_VECTOR source, BIT_VECTOR dest, size_t length) {
50  for (size_t index = 0; index < length; index++) {
51  dest[index] = source[index];
52  }
53 }
54 
55 #define SET_BIT(array,bit) (array[bit/BITSINLONG]|=1<<(bit&(BITSINLONG-1)))
56 
57 #define reset_bit(array,bit) (array[bit/BITSINLONG]&=~(1<<(bit&(BITSINLONG-1))))
58 
59 #define test_bit(array,bit) (array[bit/BITSINLONG] & (1<<(bit&(BITSINLONG-1))))
60 
61 static inline size_t WordsInVectorOfSize(size_t NumBits) {
62  return (NumBits + BITSINLONG - 1) / BITSINLONG;
63 }
64 
71 static inline void FreeBitVector(BIT_VECTOR BitVector) {
72  delete[] BitVector;
73 }
74 
75 /*---------------------------------------------------------------------------*/
84 static inline BIT_VECTOR NewBitVector(size_t NumBits) {
85  return new uint32_t[WordsInVectorOfSize(NumBits)];
86 }
87 
88 #endif
BITSINLONG
const size_t BITSINLONG
Definition: bitvec.h:30
BIT_VECTOR
uint32_t * BIT_VECTOR
Definition: bitvec.h:27
tesstrain_utils.dest
dest
Definition: tesstrain_utils.py:139