Tesseract
3.02
|
00001 /****************************************************************************** 00002 ** Filename: bitvec.h 00003 ** Purpose: Routines for manipulating bit vectors 00004 ** Author: Dan Johnson 00005 ** History: Wed Mar 7 17:52:45 1990, DSJ, Created. 00006 ** 00007 ** (c) Copyright Hewlett-Packard Company, 1988. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 ******************************************************************************/ 00018 #ifndef BITVEC_H 00019 #define BITVEC_H 00020 00021 #include "host.h" 00022 00023 /*----------------------------------------------------------------------------- 00024 Include Files and Type Defines 00025 -----------------------------------------------------------------------------*/ 00026 // TODO(rays) Rename BITSINLONG to BITSINuinT32, and use sizeof. 00027 #define BITSINLONG 32 00028 typedef uinT32 *BIT_VECTOR; 00029 00030 /*----------------------------------------------------------------------------- 00031 Public Function Prototypes 00032 -----------------------------------------------------------------------------*/ 00033 #define zero_all_bits(array,length) \ 00034 {\ 00035 register int index; /*temporary index*/\ 00036 \ 00037 for (index=0;index<length;index++)\ 00038 array[index]=0; /*zero all bits*/\ 00039 } 00040 00041 #define set_all_bits(array,length) \ 00042 {\ 00043 register int index; /*temporary index*/\ 00044 \ 00045 for (index=0;index<length;index++)\ 00046 array[index]= ~0; /*set all bits*/\ 00047 } 00048 00049 #define copy_all_bits(source,dest,length) \ 00050 {\ 00051 register int index; /*temporary index*/\ 00052 \ 00053 for (index=0;index<length;index++)\ 00054 dest[index]=source[index]; /*copy all bits*/\ 00055 } 00056 00057 #define SET_BIT(array,bit) (array[bit/BITSINLONG]|=1<<(bit&(BITSINLONG-1))) 00058 00059 #define reset_bit(array,bit) (array[bit/BITSINLONG]&=~(1<<(bit&(BITSINLONG-1)))) 00060 00061 #define test_bit(array,bit) (array[bit/BITSINLONG] & (1<<(bit&(BITSINLONG-1)))) 00062 00063 #define WordsInVectorOfSize(NumBits) \ 00064 (((NumBits) + BITSINLONG - 1) / BITSINLONG) 00065 00066 /*-------------------------------------------------------------------------- 00067 Public Function Prototypes 00068 --------------------------------------------------------------------------*/ 00069 BIT_VECTOR ExpandBitVector(BIT_VECTOR Vector, int NewNumBits); 00070 00071 void FreeBitVector(BIT_VECTOR BitVector); 00072 00073 int hamming_distance(uinT32* array1, uinT32* array2, int length); 00074 00075 BIT_VECTOR NewBitVector(int NumBits); 00076 00077 #endif