bit_vector Class Reference

An array of bits with operations for manipulating and querying individual bits. More...

#include <bit_vector.h>

Collaboration diagram for bit_vector:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 bit_vector ()
 creates a zero length bit_vector.
 bit_vector (int size, const byte *initial=NIL)
 creates a bit_vector able to store "size" bits.
 bit_vector (const bit_vector &to_copy)
 ~bit_vector ()
bit_vectoroperator= (const bit_vector &to_copy)
int bits () const
 returns the number of bits in the vector.
bool operator[] (int position) const
 returns the value of the bit at the position specified.
bool on (int position) const
 returns true if the bit at "position" is set.
bool off (int position) const
 returns true if the bit at "position" is clear.
void set_bit (int position, bool value)
 sets the bit at "position" to a particular "value".
bool whole () const
 returns true if entire vector is set.
bool empty () const
 returns true if entire vector is unset.
int find_first (bool to_find) const
 Seeks the first occurrence of "to_find".
void light (int position)
 sets the value of the bit at "position".
void clear (int position)
 clears the value of the bit at "position".
void resize (int size)
 Changes the size of the bit_vector to "size" bits.
void reset (int size)
 resizes the bit_vector and clears all bits in it.
bool compare (const bit_vector &that, int start, int stop) const
 true if "this" is the same as "that" between "start" and "stop".
bool operator== (const bit_vector &that) const
 returns true if "this" is equal to "that".
bool operator!= (const bit_vector &that) const
 returns true if "this" is not equal to "that".
istring text_form () const
 prints a nicely formatted list of bits to a string.
bit_vector subvector (int start, int end) const
 Extracts a chunk of the vector between "start" and "end".
bool overwrite (int start, const bit_vector &to_write)
 Stores bits from "to_write" into "this" at "start".
u_int get (int start, int size) const
 gets a portion of the vector as an unsigned integer.
bool set (int start, int size, u_int source)
 puts the "source" value into the vector at "start".
 operator const byte_array & () const
 returns a copy of the low-level implementation of the bit vector.

Classes

struct  two_dim_location

Detailed Description

An array of bits with operations for manipulating and querying individual bits.

Definition at line 22 of file bit_vector.h.


Constructor & Destructor Documentation

bit_vector::bit_vector (  ) 

creates a zero length bit_vector.

Definition at line 35 of file bit_vector.cpp.

Referenced by subvector().

bit_vector::bit_vector ( int  size,
const byte initial = NIL 
)

creates a bit_vector able to store "size" bits.

if initial is NIL, the vector is initialized to zero. otherwise, the bits are copied from "initial". "initial" must be large enough for the copying to succeed.

Definition at line 39 of file bit_vector.cpp.

References BITS_PER_BYTE, number_of_packets(), array< contents >::reset(), and reset().

bit_vector::bit_vector ( const bit_vector to_copy  ) 

Definition at line 48 of file bit_vector.cpp.

bit_vector::~bit_vector (  ) 

Definition at line 53 of file bit_vector.cpp.

References WHACK().


Member Function Documentation

bit_vector & bit_vector::operator= ( const bit_vector to_copy  ) 

Definition at line 55 of file bit_vector.cpp.

References _implementation, and _number_of_bits.

int bit_vector::bits (  )  const

returns the number of bits in the vector.

Definition at line 65 of file bit_vector.cpp.

Referenced by get(), span_manager::make_missing_list(), span_manager::make_received_list(), overwrite(), span_manager::received_sequence(), resize(), set(), set_bit(), byte_format::shifted_string_to_bytes(), subvector(), and span_manager::update().

bool bit_vector::operator[] ( int  position  )  const

returns the value of the bit at the position specified.

Definition at line 142 of file bit_vector.cpp.

References bounds_return.

bool bit_vector::on ( int  position  )  const

returns true if the bit at "position" is set.

Definition at line 77 of file bit_vector.cpp.

Referenced by compare(), linked_buffer::detailed_form(), buffer::detailed_form(), find_first(), main(), span_manager::make_missing_list(), span_manager::make_received_list(), off(), buffer::store_packet(), subvector(), and text_form().

bool bit_vector::off ( int  position  )  const

returns true if the bit at "position" is clear.

Definition at line 80 of file bit_vector.cpp.

References on().

void bit_vector::set_bit ( int  position,
bool  value 
)

sets the bit at "position" to a particular "value".

Definition at line 129 of file bit_vector.cpp.

References bits(), and bounds_return.

Referenced by clear(), light(), overwrite(), byte_format::shifted_string_to_bytes(), and subvector().

bool bit_vector::whole (  )  const

returns true if entire vector is set.

Definition at line 67 of file bit_vector.cpp.

References find_first(), and negative().

Referenced by buffer::whole().

bool bit_vector::empty (  )  const

returns true if entire vector is unset.

Definition at line 69 of file bit_vector.cpp.

References find_first(), and negative().

Referenced by buffer::empty().

int bit_vector::find_first ( bool  to_find  )  const

Seeks the first occurrence of "to_find".

locates the position at which a bit equal to to_find is located or it returns common::NOT_FOUND if no bit of that value is in the vector.

Definition at line 160 of file bit_vector.cpp.

References BITS_PER_BYTE, array< contents >::get(), array< contents >::length(), minimum(), common::NOT_FOUND, and on().

Referenced by empty(), main(), span_manager::make_missing_list(), span_manager::make_received_list(), span_manager::missing_sequence(), span_manager::received_sequence(), and whole().

void bit_vector::light ( int  position  ) 

sets the value of the bit at "position".

Definition at line 148 of file bit_vector.cpp.

References bounds_return, and set_bit().

Referenced by main(), buffer::store_packet(), and span_manager::update().

void bit_vector::clear ( int  position  ) 

clears the value of the bit at "position".

Definition at line 154 of file bit_vector.cpp.

References bounds_return, and set_bit().

Referenced by main(), buffer::release(), and resize().

void bit_vector::resize ( int  size  ) 

Changes the size of the bit_vector to "size" bits.

This keeps any bits that still fit. Any new bits are set to zero.

Definition at line 82 of file bit_vector.cpp.

References bits(), BITS_PER_BYTE, clear(), negative(), number_of_packets(), array< contents >::resize(), and array< contents >::use().

Referenced by get(), main(), span_manager::reset(), reset(), set(), and byte_format::shifted_string_to_bytes().

void bit_vector::reset ( int  size  ) 

resizes the bit_vector and clears all bits in it.

Definition at line 107 of file bit_vector.cpp.

References array< contents >::access(), array< contents >::length(), and resize().

Referenced by bit_vector().

bool bit_vector::compare ( const bit_vector that,
int  start,
int  stop 
) const

true if "this" is the same as "that" between "start" and "stop".

Definition at line 178 of file bit_vector.cpp.

References on().

Referenced by operator==().

bool bit_vector::operator== ( const bit_vector that  )  const

returns true if "this" is equal to "that".

neither vector is changed. if the vectors do not have the same size, false is returned.

Definition at line 71 of file bit_vector.cpp.

References compare().

bool bit_vector::operator!= ( const bit_vector that  )  const

returns true if "this" is not equal to "that".

Definition at line 74 of file bit_vector.cpp.

istring bit_vector::text_form (  )  const

prints a nicely formatted list of bits to a string.

Definition at line 186 of file bit_vector.cpp.

References BITS_PER_BYTE, on(), and log_base::platform_ending().

Referenced by get().

bit_vector bit_vector::subvector ( int  start,
int  end 
) const

Extracts a chunk of the vector between "start" and "end".

Returns a bit_vector that is copied from this one starting at "start" and running until "end". An empty bit vector is returned if the indices are out of range.

Definition at line 212 of file bit_vector.cpp.

References bit_vector(), bits(), bounds_return, on(), and set_bit().

Referenced by get().

bool bit_vector::overwrite ( int  start,
const bit_vector to_write 
)

Stores bits from "to_write" into "this" at "start".

overwrites the contents of this bit_vector with the contents of "to_write", beginning at "start" in this bit_vector. true is returned for a successful write. false will be returned if the "start" is out of range or if "to_write" is too large.

Definition at line 222 of file bit_vector.cpp.

References bits(), bounds_return, and set_bit().

Referenced by set().

u_int bit_vector::get ( int  start,
int  size 
) const

gets a portion of the vector as an unsigned integer.

returns an integer (as interpreted by the operating system) where the pattern of bits in that integer is identical to the bits in this bit_vector, beginning at "start" and including enough bits for an integer of "size" bits.

Definition at line 254 of file bit_vector.cpp.

References _implementation, bits(), BITS_PER_BYTE, array< contents >::get(), LEFT_ENDIAN, LOG, minimum(), number_of_packets(), resize(), istring::s(), SET(), subvector(), and text_form().

bool bit_vector::set ( int  start,
int  size,
u_int  source 
)

puts the "source" value into the vector at "start".

sets the pattern of bits in this bit_vector beginning at "start" identically to how they are stored in the integer "source", where the integer is expected to be using "size" of its bits. the bits are copied starting from the low end of "source", where the operating system defines what the low end is. true is returned for a successful copying.

Definition at line 238 of file bit_vector.cpp.

References _implementation, bits(), bounds_return, common::NEW_AT_BEGINNING, overwrite(), resize(), and array< contents >::resize().

bit_vector::operator const byte_array & (  )  const

returns a copy of the low-level implementation of the bit vector.

the first bit is stored at the bit in first byte, and so forth.

Definition at line 63 of file bit_vector.cpp.


The documentation for this class was generated from the following files:
Generated on Fri Aug 29 04:30:19 2008 for HOOPLE Libraries by  doxygen 1.5.1