Tesseract
3.02
|
#include "bitvec.h"
#include <stdio.h>
#include "emalloc.h"
#include "freelist.h"
#include "tprintf.h"
Go to the source code of this file.
Functions | |
BIT_VECTOR | ExpandBitVector (BIT_VECTOR Vector, int NewNumBits) |
void | FreeBitVector (BIT_VECTOR BitVector) |
int | hamming_distance (uinT32 *array1, uinT32 *array2, int length) |
BIT_VECTOR | NewBitVector (int NumBits) |
BIT_VECTOR ExpandBitVector | ( | BIT_VECTOR | Vector, |
int | NewNumBits | ||
) |
This routine uses realloc to increase the size of the specified bit vector.
Globals:
Vector | bit vector to be expanded |
NewNumBits | new size of bit vector |
Definition at line 48 of file bitvec.cpp.
{ return ((BIT_VECTOR) Erealloc(Vector, sizeof(Vector[0]) * WordsInVectorOfSize(NewNumBits))); } /* ExpandBitVector */
void FreeBitVector | ( | BIT_VECTOR | BitVector | ) |
This routine frees a bit vector. It also decrements the global counter that keeps track of the number of bit vectors allocated. If BitVector is NULL, then the count is printed to stderr.
Globals:
BitVector | bit vector to be freed |
Definition at line 55 of file bitvec.cpp.
{ if (BitVector) { Efree(BitVector); } } /* FreeBitVector */
hamming_distance(array1,array2,length) computes the hamming distance between two bit strings.
Definition at line 81 of file bitvec.cpp.
{ register uinT32 diff; /*bit difference */ register int dist; /*total distance */ dist = 0; for (; length > 0; length--) { diff = *array1++ ^ *array2++;/*different bits */ while (diff) { diff &= diff - 1; /*lose a bit */ dist++; } } return dist; /*total distance */ }
BIT_VECTOR NewBitVector | ( | int | NumBits | ) |
Allocate and return a new bit vector large enough to hold the specified number of bits.
Globals:
NumBits | number of bits in new bit vector |
Definition at line 111 of file bitvec.cpp.
{ return ((BIT_VECTOR) Emalloc(sizeof(uinT32) * WordsInVectorOfSize(NumBits))); } /* NewBitVector */