cutil/bitvec.h File Reference

Go to the source code of this file.

Defines

Typedefs

Functions


Define Documentation

#define BITSINLONG   32

Note:
File: bitvec.h
Routines for manipulating bit vectors
Author:
Dan Johnson
Date:
Wed Mar 7 17:52:45 1990, DSJ, Created.
 **	(c) Copyright Hewlett-Packard Company, 1988.
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
 ** You may obtain a copy of the License at
 ** http://www.apache.org/licenses/LICENSE-2.0
 ** Unless required by applicable law or agreed to in writing, software
 ** distributed under the License is distributed on an "AS IS" BASIS,
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ** See the License for the specific language governing permissions and
 ** limitations under the License.

Definition at line 25 of file bitvec.h.

Referenced by ReadTempConfig().

#define copy_all_bits ( source,
dest,
length   ) 

Value:

{\
   register int         index;                  /*temporary index*/\
\
for (index=0;index<length;index++)\
   dest[index]=source[index];                   /*copy all bits*/\
}

Definition at line 52 of file bitvec.h.

Referenced by MakeNewTemporaryConfig().

#define reset_bit ( array,
bit   )     (array[bit/BITSINLONG]&=~(1<<(bit&(BITSINLONG-1))))

Definition at line 62 of file bitvec.h.

Referenced by AddProtoToClass().

#define set_all_bits ( array,
length   ) 

Value:

{\
   register int         index;                  /*temporary index*/\
\
for (index=0;index<length;index++)\
   array[index]= ~0;                         /*set all bits*/\
}

Definition at line 44 of file bitvec.h.

Referenced by compare_tess_blobs(), and InitAdaptiveClassifier().

#define SET_BIT ( array,
bit   )     (array[bit/BITSINLONG]|=1<<(bit&(BITSINLONG-1)))

Definition at line 60 of file bitvec.h.

Referenced by ConvertConfig(), FillPPCircularBits(), FillPPLinearBits(), MakeNewAdaptedClass(), MakeNewTemporaryConfig(), MakeNewTempProtos(), and SplitProto().

#define test_bit ( array,
bit   )     (array[bit/BITSINLONG] & (1<<(bit&(BITSINLONG-1))))

Definition at line 64 of file bitvec.h.

Referenced by ClassConfigLength(), ConvertConfig(), MakeTempProtoPerm(), ReadAdaptedClass(), SplitProto(), WriteAdaptedClass(), and WriteOldConfigFile().

#define WordsInVectorOfSize ( NumBits   )     (((NumBits) + BITSINLONG - 1) / BITSINLONG)

Definition at line 66 of file bitvec.h.

Referenced by AddConfigToClass(), compare_tess_blobs(), config_mask_to_proto_mask(), ExpandBitVector(), InitAdaptiveClassifier(), MakeNewTemporaryConfig(), NewAdaptedClass(), NewBitVector(), NewTempConfig(), ReadAdaptedClass(), ReadConfigs(), SetUpForFloat2Int(), WriteAdaptedClass(), and WriteConfigs().

#define zero_all_bits ( array,
length   ) 

Value:

{\
   register int         index;                  /*temporary index*/\
\
for (index=0;index<length;index++)\
   array[index]=0;                              /*zero all bits*/\
}

Definition at line 36 of file bitvec.h.

Referenced by AddConfigToClass(), config_mask_to_proto_mask(), InitAdaptiveClassifier(), MakeNewTemporaryConfig(), NewAdaptedClass(), and NewTempConfig().


Typedef Documentation

BIT_VECTOR

Pointer to an unsigned long, to be operated on with eg: SET_BIT.

Definition at line 31 of file bitvec.h.


Function Documentation

BIT_VECTOR ExpandBitVector ( BIT_VECTOR  Vector,
int  NewNumBits 
)

Uses realloc to increase the size of the specified bit vector.

Parameters:
Vector Bit vector to be expanded
NewNumBits New size of bit vector
Returns:
New expanded bit vector.
Note:
Exceptions: none
Date:
Fri Nov 16 10:11:16 1990, DSJ, Created.

Definition at line 48 of file bitvec.cpp.

References Erealloc(), and WordsInVectorOfSize.

Referenced by AddProtoToClass().

00048                                                               { 
00049   return ((BIT_VECTOR) Erealloc (Vector,
00050     sizeof (unsigned long) *
00051     WordsInVectorOfSize (NewNumBits)));
00052 
00053 }                                /* ExpandBitVector */

void FreeBitVector ( BIT_VECTOR  BitVector  ) 

Frees a bit vector & decrements the global counter that keeps track of the number of bit vectors allocated.

Parameters:
BitVector Bit vector to be freed
Note:
Globals: BitVectorCount Count of number of bit vectors allocated
Returns:
none
If BitVector is NULL, then the count is printed to stderr.
Note:
Exceptions: none
Date:
Tue Oct 23 16:46:09 1990, DSJ, Created.

Definition at line 69 of file bitvec.cpp.

References BitVectorCount, cprintf(), and memfree().

Referenced by compare_tess_blobs(), EndAdaptiveClassifier(), free_adapted_class(), FreeClassFields(), and FreeTempConfig().

00069                                          { 
00070   if (BitVector) {
00071     memfree(BitVector); 
00072     BitVectorCount--;
00073   }
00074   else {
00075     cprintf ("%6d BITVECTOR elements in use\n", BitVectorCount);
00076   }
00077 
00078 }                                /* FreeBitVector */

int hamming_distance ( register unsigned long *  array1,
register unsigned long *  array2,
register int  length 
)

Computes the hamming distance between two bit strings.

Parameters:
array1 First array to compare
array2 Second array to compare
length Length of arrays
Returns:
distance

Definition at line 90 of file bitvec.cpp.

Referenced by delete_search().

00093                                           {
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 }

BIT_VECTOR NewBitVector ( int  NumBits  ) 

Allocate and return a new bit vector large enough to hold the specified number of bits.

Parameters:
NumBits Number of bits in new bit vector
Note:
Globals: BitVectorCount Number of bit vectors allocated
Returns:
New bit vector.
Note:
Exceptions: none
Date:
Tue Oct 23 16:51:27 1990, DSJ, Created.

Definition at line 120 of file bitvec.cpp.

References BitVectorCount, Emalloc(), and WordsInVectorOfSize.

Referenced by AddConfigToClass(), compare_tess_blobs(), InitAdaptiveClassifier(), NewAdaptedClass(), NewTempConfig(), ReadAdaptedClass(), ReadConfigs(), ReadTempConfig(), and SetUpForFloat2Int().

00120                                      { 
00121   BitVectorCount++;
00122   return ((BIT_VECTOR) Emalloc (sizeof (unsigned long) *
00123     WordsInVectorOfSize (NumBits)));
00124 
00125 }                                /* NewBitVector */


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