Public Member Functions | Private Types | Private Member Functions | Private Attributes

TAO_Notify::Bit_Vector Class Reference

Simple bit vector. More...

#include <Bit_Vector.h>

Collaboration diagram for TAO_Notify::Bit_Vector:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Bit_Vector ()
 The constructor.
 ~Bit_Vector ()
 The destructor.
bool is_set (const size_t location) const
 Determine if a bit at location is set.
void set_bit (const size_t location, bool set)
 Set or unset a bit at location, growing the vector as needed.
size_t find_first_bit (bool set) const
 Find the first bit that is either set or unset in an O(1).

Private Types

enum  { BITS_PER_WORD = 32, BPW_LOG_2 = 5 }
typedef ACE_UINT32 BASIC_UINT_TYPE
typedef ACE_Vector
< BASIC_UINT_TYPE
VECTOR_TYPE

Private Member Functions

void evaluate_firsts (const size_t location, bool set)
 Update our first set and unset bits.
size_t find_first_bit_of (const size_t location, bool set)

Private Attributes

VECTOR_TYPE bitvec_
size_t size_
size_t first_set_bit_
size_t first_cleared_bit_

Detailed Description

Simple bit vector.

Written to support block allocation from persistent storage. Should be promoted to the ACE level to make it generally usable.

Definition at line 39 of file Bit_Vector.h.


Member Typedef Documentation

typedef ACE_UINT32 TAO_Notify::Bit_Vector::BASIC_UINT_TYPE [private]

Definition at line 41 of file Bit_Vector.h.

Definition at line 42 of file Bit_Vector.h.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
BITS_PER_WORD 
BPW_LOG_2 

Definition at line 43 of file Bit_Vector.h.

       {
    BITS_PER_WORD = 32,
    BPW_LOG_2 = 5
  };


Constructor & Destructor Documentation

TAO_Notify::Bit_Vector::Bit_Vector (  ) 

The constructor.

Definition at line 10 of file Bit_Vector.cpp.

TAO_Notify::Bit_Vector::~Bit_Vector (  ) 

The destructor.

Definition at line 17 of file Bit_Vector.cpp.

{
}


Member Function Documentation

void TAO_Notify::Bit_Vector::evaluate_firsts ( const size_t  location,
bool  set 
) [private]

Update our first set and unset bits.

Definition at line 71 of file Bit_Vector.cpp.

{
  if (set)
  {
    if (this->first_cleared_bit_ == location)
    {
      this->first_cleared_bit_ = this->find_first_bit_of(location, false);
    }
    if (this->first_set_bit_ > location)
    {
      this->first_set_bit_ = location;
    }
  }
  else if (!set)
  {
    if (this->first_set_bit_ == location)
    {
      this->first_set_bit_ = this->find_first_bit_of(location, true);
    }
    if (this->first_cleared_bit_ > location)
    {
      this->first_cleared_bit_ = location;
    }
  }
}

size_t TAO_Notify::Bit_Vector::find_first_bit ( bool  set  )  const

Find the first bit that is either set or unset in an O(1).

Definition at line 56 of file Bit_Vector.cpp.

{
  size_t result = 0;
  if (set)
  {
    result = this->first_set_bit_;
  }
  else
  {
    result = this->first_cleared_bit_;
  }
  return result;
}

size_t TAO_Notify::Bit_Vector::find_first_bit_of ( const size_t  location,
bool  set 
) [private]

Iterate from location to the end, finding the first bit that matches the requested set or unset value.

Definition at line 98 of file Bit_Vector.cpp.

{
  size_t newloc = 0;
  size_t idx = 0;
  for (idx = location; (newloc == 0) && (idx < this->size_ + 1); idx++)
  {
    if (is_set(idx) == set)
    {
      newloc = idx;
    }
  }
  return newloc;
}

bool TAO_Notify::Bit_Vector::is_set ( const size_t  location  )  const

Determine if a bit at location is set.

Definition at line 22 of file Bit_Vector.cpp.

{
  bool result = false;
  if (location < this->size_)
  {
    result = (0 != (this->bitvec_[location >> BPW_LOG_2] & (1 << (location % BITS_PER_WORD))));
  }
  return result;
}

void TAO_Notify::Bit_Vector::set_bit ( const size_t  location,
bool  set 
)

Set or unset a bit at location, growing the vector as needed.

Definition at line 33 of file Bit_Vector.cpp.

{
  if (location >= this->size_)
  {
    if ((location >> BPW_LOG_2) >= (this->size_ >> BPW_LOG_2))
    {
      size_t need = (location >> BPW_LOG_2) - (this->size_ >> BPW_LOG_2);
      this->bitvec_.resize(this->bitvec_.size() + need + 1, 0);
    }
    this->size_ = location + 1;
  }
  if (set)
  {
    this->bitvec_[location >> BPW_LOG_2] |= (1 << (location % BITS_PER_WORD));
  }
  else
  {
    this->bitvec_[location >> BPW_LOG_2] &= ~(1 << (location % BITS_PER_WORD));
  }
  this->evaluate_firsts(location, set);
}


Member Data Documentation

Definition at line 70 of file Bit_Vector.h.

Definition at line 73 of file Bit_Vector.h.

Definition at line 72 of file Bit_Vector.h.

Definition at line 71 of file Bit_Vector.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines