cutil/bitvec.cpp File Reference

#include "bitvec.h"
#include "emalloc.h"
#include "freelist.h"
#include "callcpp.h"
#include <stdio.h>

Go to the source code of this file.

Functions

Variables


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 */


Variable Documentation

int BitVectorCount = 0 [static]

Note:
File: bitvec.cpp
Routines for manipulating bit vectors
Author:
Dan Johnson
Date:
Thu Mar 15 10:37:27 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 33 of file bitvec.cpp.

Referenced by FreeBitVector(), and NewBitVector().


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