cutil/bitvec.cpp

Go to the documentation of this file.
00001 
00020 /* =================
00021           Include Files and Type Defines
00022  ==================== */
00023 #include "bitvec.h"
00024 #include "emalloc.h"
00025 #include "freelist.h"
00026 #include "callcpp.h"
00027 
00028 #include <stdio.h>
00029 
00030 /* =================
00031  Global Data Definitions and Declarations
00032  ==================== */
00033 static int BitVectorCount = 0;
00034 
00035 /* =================
00036               Public Code
00037  ==================== */
00038 /* =============================== */
00048 BIT_VECTOR ExpandBitVector(BIT_VECTOR Vector, int NewNumBits) { 
00049   return ((BIT_VECTOR) Erealloc (Vector,
00050     sizeof (unsigned long) *
00051     WordsInVectorOfSize (NewNumBits)));
00052 
00053 }                                /* ExpandBitVector */
00054 
00055 
00056 /* =============================== */
00069 void FreeBitVector(BIT_VECTOR BitVector) { 
00070   if (BitVector) {
00071     memfree(BitVector); 
00072     BitVectorCount--;
00073   }
00074   else {
00075     cprintf ("%6d BITVECTOR elements in use\n", BitVectorCount);
00076   }
00077 
00078 }                                /* FreeBitVector */
00079 
00080 
00081 /* =============================== */
00090 int hamming_distance(
00091                      register unsigned long *array1,
00092                      register unsigned long *array2,
00093                      register int length) {
00094   register unsigned long diff;   /*bit difference */
00095   register int dist;             /*total distance */
00096 
00097   dist = 0;
00098   for (; length > 0; length--) {
00099     diff = *array1++ ^ *array2++;/*different bits */
00100     while (diff) {
00101       diff &= diff - 1;          /*lose a bit */
00102       dist++;
00103     }
00104   }
00105   return dist;                   /*total distance */
00106 }
00107 
00108 
00109 /* =============================== */
00120 BIT_VECTOR NewBitVector(int NumBits) { 
00121   BitVectorCount++;
00122   return ((BIT_VECTOR) Emalloc (sizeof (unsigned long) *
00123     WordsInVectorOfSize (NumBits)));
00124 
00125 }                                /* NewBitVector */

Generated on Wed Feb 28 19:49:10 2007 for Tesseract by  doxygen 1.5.1