00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Bit_Vector.h 00006 * 00007 * $Id: Bit_Vector.h 71526 2006-03-14 06:14:35Z jtc $ 00008 * 00009 * This is a basic bit vector class. 00010 * 00011 * @author Jonathan Pollack <pollack_j@ociweb.com> 00012 */ 00013 //============================================================================= 00014 00015 #ifndef BIT_VECTOR_H 00016 #define BIT_VECTOR_H 00017 #include /**/ "ace/pre.h" 00018 00019 #include "orbsvcs/Notify/notify_serv_export.h" 00020 00021 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00022 #pragma once 00023 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00024 00025 #include "tao/Versioned_Namespace.h" 00026 00027 #include "ace/Vector_T.h" 00028 #include "ace/Basic_Types.h" 00029 00030 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00031 00032 namespace TAO_Notify 00033 { 00034 00035 /// \brief Simple bit vector. 00036 /// 00037 /// Written to support block allocation from persistent storage. 00038 /// Should be promoted to the ACE level to make it generally usable. 00039 class TAO_Notify_Serv_Export Bit_Vector 00040 { 00041 typedef ACE_UINT32 BASIC_UINT_TYPE; 00042 typedef ACE_Vector<BASIC_UINT_TYPE> VECTOR_TYPE; 00043 enum { 00044 BITS_PER_WORD = 32, 00045 BPW_LOG_2 = 5 00046 }; 00047 public: 00048 00049 /// The constructor. 00050 Bit_Vector(); 00051 /// The destructor. 00052 ~Bit_Vector(); 00053 00054 /// \brief Determine if a bit at location is set. 00055 bool is_set(const size_t location) const; 00056 /// \brief Set or unset a bit at location, growing the vector as needed. 00057 void set_bit(const size_t location, bool set); 00058 00059 /// \brief Find the first bit that is either set or unset in an O(1). 00060 size_t find_first_bit(bool set) const; 00061 00062 private: 00063 /// Update our first set and unset bits. 00064 void evaluate_firsts(const size_t location, bool set); 00065 /// Iterate from location to the end, finding the first bit that 00066 /// matches the requested set or unset value. 00067 size_t find_first_bit_of(const size_t location, bool set); 00068 00069 private: 00070 VECTOR_TYPE bitvec_; 00071 size_t size_; 00072 size_t first_set_bit_; 00073 size_t first_cleared_bit_; 00074 }; 00075 00076 } 00077 00078 TAO_END_VERSIONED_NAMESPACE_DECL 00079 00080 #include /**/ "ace/post.h" 00081 #endif /* BIT_VECTOR_H */