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 00026 #define BITSINLONG 32 /*no of bits in a long */ 00027 typedef uinT32 *BIT_VECTOR; 00028 00032 #define zero_all_bits(array,length) \ 00033 {\ 00034 register int index; /*temporary index*/\ 00035 \ 00036 for (index=0;index<length;index++)\ 00037 array[index]=0; /*zero all bits*/\ 00038 } 00039 00040 #define set_all_bits(array,length) \ 00041 {\ 00042 register int index; /*temporary index*/\ 00043 \ 00044 for (index=0;index<length;index++)\ 00045 array[index]= ~0; /*set all bits*/\ 00046 } 00047 00048 #define copy_all_bits(source,dest,length) \ 00049 {\ 00050 register int index; /*temporary index*/\ 00051 \ 00052 for (index=0;index<length;index++)\ 00053 dest[index]=source[index]; /*copy all bits*/\ 00054 } 00055 00056 #define SET_BIT(array,bit) (array[bit/BITSINLONG]|=1<<(bit&(BITSINLONG-1))) 00057 00058 #define reset_bit(array,bit) (array[bit/BITSINLONG]&=~(1<<(bit&(BITSINLONG-1)))) 00059 00060 #define test_bit(array,bit) (array[bit/BITSINLONG] & (1<<(bit&(BITSINLONG-1)))) 00061 00062 #define WordsInVectorOfSize(NumBits) \ 00063 (((NumBits) + BITSINLONG - 1) / BITSINLONG) 00064 00065 /*-------------------------------------------------------------------------- 00066 Public Function Prototypes 00067 --------------------------------------------------------------------------*/ 00068 BIT_VECTOR ExpandBitVector(BIT_VECTOR Vector, int NewNumBits); 00069 00070 void FreeBitVector(BIT_VECTOR BitVector); 00071 00072 int hamming_distance(uinT32* array1, uinT32* array2, int length); 00073 00074 BIT_VECTOR NewBitVector(int NumBits); 00075 /* 00076 #if defined(__STDC__) || defined(__cplusplus) 00077 # define _ARGS(s) s 00078 #else 00079 # define _ARGS(s) () 00080 #endif*/ 00081 00082 /* bitvec.c 00083 BIT_VECTOR ExpandBitVector 00084 _ARGS((BIT_VECTOR Vector, 00085 int NewNumBits)); 00086 00087 void FreeBitVector 00088 _ARGS((BIT_VECTOR BitVector)); 00089 00090 int hamming_distance 00091 _ARGS((unsigned long *array1, 00092 unsigned long *array2, 00093 int length)); 00094 00095 BIT_VECTOR NewBitVector 00096 _ARGS((int NumBits)); 00097 00098 #undef _ARGS 00099 */ 00100 #endif