tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
bitvec.h
1 /******************************************************************************
2  ** Filename: bitvec.h
3  ** Purpose: Routines for manipulating bit vectors
4  ** Author: Dan Johnson
5  ** History: Wed Mar 7 17:52:45 1990, DSJ, Created.
6  **
7  ** (c) Copyright Hewlett-Packard Company, 1988.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  ******************************************************************************/
18 #ifndef BITVEC_H
19 #define BITVEC_H
20 
21 #include "host.h"
22 
23 /*-----------------------------------------------------------------------------
24  Include Files and Type Defines
25 -----------------------------------------------------------------------------*/
26 // TODO(rays) Rename BITSINLONG to BITSINuint32_t, and use sizeof.
27 #define BITSINLONG 32
28 using BIT_VECTOR = uint32_t *;
29 
30 /*-----------------------------------------------------------------------------
31  Public Function Prototypes
32 -----------------------------------------------------------------------------*/
33 #define zero_all_bits(array, length) \
34  { \
35  int index; /*temporary index*/ \
36  \
37  for (index = 0; index < length; index++) \
38  array[index] = 0; /*zero all bits*/ \
39  }
40 
41 #define set_all_bits(array, length) \
42  { \
43  int index; /*temporary index*/ \
44  \
45  for (index = 0; index < length; index++) \
46  array[index] = ~0; /*set all bits*/ \
47  }
48 
49 #define copy_all_bits(source, dest, length) \
50  { \
51  int index; /*temporary index*/ \
52  \
53  for (index = 0; index < length; index++) \
54  dest[index] = source[index]; /*copy all bits*/ \
55  }
56 
57 #define SET_BIT(array,bit) (array[bit/BITSINLONG]|=1<<(bit&(BITSINLONG-1)))
58 
59 #define reset_bit(array,bit) (array[bit/BITSINLONG]&=~(1<<(bit&(BITSINLONG-1))))
60 
61 #define test_bit(array,bit) (array[bit/BITSINLONG] & (1<<(bit&(BITSINLONG-1))))
62 
63 #define WordsInVectorOfSize(NumBits) \
64 (((NumBits) + BITSINLONG - 1) / BITSINLONG)
65 
66 /*--------------------------------------------------------------------------
67  Public Function Prototypes
68 --------------------------------------------------------------------------*/
69 BIT_VECTOR ExpandBitVector(BIT_VECTOR Vector, int NewNumBits);
70 
71 void FreeBitVector(BIT_VECTOR BitVector);
72 
73 BIT_VECTOR NewBitVector(int NumBits);
74 
75 #endif