Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

bitvector.h

Go to the documentation of this file.
00001 
00002 /*
00003 ** Copyright (C) 2002 Russell Leighton
00004 **
00005 ** This program is free software; you can redistribute it and/or modify
00006 ** it under the terms of the GNU General Public License as published by
00007 ** the Free Software Foundation; either version 2 of the License, or
00008 ** (at your option) any later version.
00009 **
00010 ** This program is distributed in the hope that it will be useful,
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ** GNU General Public License for more details.
00014 **
00015 ** You should have received a copy of the GNU General Public License
00016 ** along with this program; if not, write to the Free Software
00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 
00021 #ifndef __AW_BITVECTOR__
00022 #define __AW_BITVECTOR__
00023 
00030 #include "sys.h"
00031 
00032 /* manging the bitvector */
00033 
00034 #define AW_BITVECTOR_CALC_VECTOR_SIZE(nbits)\
00035 ( ((nbits) / (sizeof(u_int32_t)*8) + 1) * sizeof(u_int32_t))
00036 
00037 #define AW_BITVECTOR_CORE_SIZE(nbits)\
00038 ( sizeof(aw_bitvector_t) + AW_BITVECTOR_CALC_VECTOR_SIZE( nbits ) )
00039 
00040 #define AW_BITVECTOR_DO_SIZE(nbits) \
00041 ( \
00042   AW_BITVECTOR_CORE_SIZE( nbits ) + \
00043   AW_ALIGN_PADDING( AW_BITVECTOR_CORE_SIZE( nbits ) ) \
00044 )
00045 
00046 #define AW_BITVECTOR_GET_VECTOR_SIZE(bv) ( (bv)->vectorsize )
00047 
00048 #define AW_BITVECTOR_GET_VECTOR(bv) \
00049 ( (u_int32_t *)( ((caddr_t)bv) + sizeof(aw_bitvector_t))  ) 
00050 
00051 /* the following are for setting/un-setting bits in the bitvector */
00052 
00053 /* set all bits to 0 */
00054 #define AW_BITVECTOR_CLEAR(bv) \
00055 ( memset( AW_BITVECTOR_GET_VECTOR(bv), 0 , bv->vectorsize ) )
00056 
00057 /* set all bits to 1 */
00058 #define AW_BITVECTOR_UNCLEAR(bv) \
00059 ( memset( AW_BITVECTOR_GET_VECTOR(bv), ~0 , bv->vectorsize ) )
00060 
00061 /* return val in index location of tbl */
00062 #define AW_BITVECTOR_IS_SELECTED(index, bv) \
00063 ( (*( AW_BITVECTOR_GET_VECTOR(bv) + ((index) / (sizeof(u_int32_t)*8) )) >> \
00064    ((index) & ( (sizeof(u_int32_t)*8) - 1) )) & 0x1)
00065 
00066 /* set value */
00067 #define AW_BITVECTOR_SELECTED(index, bv) \
00068 (*( AW_BITVECTOR_GET_VECTOR(bv) + ((index) / (sizeof(u_int32_t)*8) ) ) |= \
00069  0x1 << ((index) & ( (sizeof(u_int32_t)*8) - 1) ))
00070 
00071 /* unset value */
00072 #define AW_BITVECTOR_NOT_SELECTED(index, bv) \
00073 (*( AW_BITVECTOR_GET_VECTOR(bv) + ((index) / (sizeof(u_int32_t)*8) ) ) &= \
00074  ~(0x1 << ((index) & ( (sizeof(u_int32_t)*8) - 1) )))
00075 
00076 typedef struct {
00077 
00078   u_int32_t
00079    vectorsize;                     /* size in bytes for the vector holding the bits */
00080 
00081   /* an array of 'size' u_in32_t follows */
00082 
00083 } aw_bitvector_t;
00084 
00085 
00091 aw_bitvector_t *aw_bitvector_create(u_int32_t nbits);
00092 
00097 void aw_bitvector_destroy(aw_bitvector_t *bv);
00098 
00105 int32_t aw_bitvector_ormerge(aw_bitvector_t *bv1, aw_bitvector_t *bv2);
00106 
00107 
00114 int32_t aw_bitvector_andmerge(aw_bitvector_t *bv1, aw_bitvector_t *bv2);
00115 
00122 int32_t aw_bitvector_findfirstbit(u_int32_t start_index, aw_bitvector_t *bv);
00123 
00124 
00125 #endif
Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)