Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bitvec.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Filename: bitvec.c
3 ** Purpose: Routines for manipulating bit vectors
4 ** Author: Dan Johnson
5 ** History: Thu Mar 15 10:37:27 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
19 /*-----------------------------------------------------------------------------
20 Include Files and Type Defines
21 -----------------------------------------------------------------------------*/
22 #include "bitvec.h"
23
24 #include <stdio.h>
25
26 #include "emalloc.h"
27 #include "freelist.h"
28 #include "tprintf.h"
29
30 /*-----------------------------------------------------------------------------
31 Public Code
32 -----------------------------------------------------------------------------*/
33 /*---------------------------------------------------------------------------*/
48 BIT_VECTOR ExpandBitVector(BIT_VECTOR Vector, int NewNumBits) {
49 return ((BIT_VECTOR) Erealloc(Vector,
50 sizeof(Vector[0]) * WordsInVectorOfSize(NewNumBits)));
51 } /* ExpandBitVector */
52
53
54 /*---------------------------------------------------------------------------*/
55 void FreeBitVector(BIT_VECTOR BitVector) {
70 if (BitVector) {
71 Efree(BitVector);
72 }
73 } /* FreeBitVector */
74
75
80 /*--------------------------------------------------------------------------*/
81 int hamming_distance(uinT32* array1, uinT32* array2, int length) {
82 register uinT32 diff; /*bit difference */
83 register int dist; /*total distance */
84
85 dist = 0;
86 for (; length > 0; length--) {
87 diff = *array1++ ^ *array2++;/*different bits */
88 while (diff) {
89 diff &= diff - 1; /*lose a bit */
90 dist++;
91 }
92 }
93 return dist; /*total distance */
94 }
95
96
97 /*---------------------------------------------------------------------------*/
111 BIT_VECTOR NewBitVector(int NumBits) {
112 return ((BIT_VECTOR) Emalloc(sizeof(uinT32) *
113 WordsInVectorOfSize(NumBits)));
114 } /* NewBitVector */