feisty meow concerns codebase
2.140
|
An array of bits with operations for manipulating and querying individual bits. More...
#include <bit_vector.h>
Public Member Functions | |
bit_vector () | |
creates a zero length bit_vector. More... | |
bit_vector (int size, const basis::abyte *initial=NULL_POINTER) | |
creates a bit_vector able to store "size" bits. More... | |
bit_vector (const bit_vector &to_copy) | |
~bit_vector () | |
bit_vector & | operator= (const bit_vector &to_copy) |
int | bits () const |
returns the number of bits in the vector. More... | |
bool | operator[] (int position) const |
returns the value of the bit at the position specified. More... | |
bool | on (int position) const |
returns true if the bit at "position" is set. More... | |
bool | off (int position) const |
returns true if the bit at "position" is clear. More... | |
void | set_bit (int position, bool value) |
sets the bit at "position" to a particular "value". More... | |
bool | whole () const |
returns true if entire vector is set. More... | |
bool | empty () const |
returns true if entire vector is unset. More... | |
int | find_first (bool to_find) const |
Seeks the first occurrence of "to_find". More... | |
void | light (int position) |
sets the value of the bit at "position". More... | |
void | clear (int position) |
clears the value of the bit at "position". More... | |
void | resize (int size) |
Changes the size of the bit_vector to "size" bits. More... | |
void | reset (int size) |
resizes the bit_vector and clears all bits in it. More... | |
bool | compare (const bit_vector &that, int start, int stop) const |
true if "this" is the same as "that" between "start" and "stop". More... | |
bool | operator== (const bit_vector &that) const |
returns true if "this" is equal to "that". More... | |
basis::astring | text_form () const |
prints a nicely formatted list of bits to a string. More... | |
bit_vector | subvector (int start, int end) const |
Extracts a chunk of the vector between "start" and "end". More... | |
bool | overwrite (int start, const bit_vector &to_write) |
Stores bits from "to_write" into "this" at "start". More... | |
basis::un_int | get (int start, int size) const |
gets a portion of the vector as an unsigned integer. More... | |
bool | set (int start, int size, basis::un_int source) |
puts the "source" value into the vector at "start". More... | |
operator const basis::byte_array & () const | |
returns a copy of the low-level implementation of the bit vector. More... | |
An array of bits with operations for manipulating and querying individual bits.
Definition at line 25 of file bit_vector.h.
structures::bit_vector::bit_vector | ( | ) |
creates a zero length bit_vector.
Definition at line 36 of file bit_vector.cpp.
Referenced by subvector().
structures::bit_vector::bit_vector | ( | int | size, |
const basis::abyte * | initial = NULL_POINTER |
||
) |
creates a bit_vector able to store "size" bits.
if initial is NULL_POINTER, 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 40 of file bit_vector.cpp.
References BITS_PER_BYTE, basis::number_of_packets(), basis::array< contents >::reset(), and reset().
structures::bit_vector::bit_vector | ( | const bit_vector & | to_copy | ) |
Definition at line 49 of file bit_vector.cpp.
structures::bit_vector::~bit_vector | ( | ) |
Definition at line 54 of file bit_vector.cpp.
References basis::WHACK().
int structures::bit_vector::bits | ( | ) | const |
returns the number of bits in the vector.
Definition at line 66 of file bit_vector.cpp.
Referenced by textual::byte_formatter::bytes_to_shifted_string(), get(), sockets::span_manager::make_missing_list(), sockets::span_manager::make_received_list(), overwrite(), sockets::span_manager::received_sequence(), resize(), set(), set_bit(), textual::byte_formatter::shifted_string_to_bytes(), subvector(), and sockets::span_manager::update().
void structures::bit_vector::clear | ( | int | position | ) |
clears the value of the bit at "position".
Definition at line 152 of file bit_vector.cpp.
References bounds_return, and set_bit().
Referenced by resize().
bool structures::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 176 of file bit_vector.cpp.
References on().
Referenced by operator==().
bool structures::bit_vector::empty | ( | ) | const |
returns true if entire vector is unset.
Definition at line 70 of file bit_vector.cpp.
References find_first(), and basis::negative().
int structures::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 158 of file bit_vector.cpp.
References BITS_PER_BYTE, basis::array< contents >::get(), basis::array< contents >::length(), basis::minimum(), and on().
Referenced by empty(), sockets::span_manager::make_missing_list(), sockets::span_manager::make_received_list(), sockets::span_manager::missing_sequence(), sockets::span_manager::received_sequence(), and whole().
basis::un_int structures::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 252 of file bit_vector.cpp.
References bits(), BITS_PER_BYTE, basis::array< contents >::get(), structures::host_bit_order, structures::host_byte_order, structures::LEFT_ENDIAN, LOG, basis::minimum(), basis::number_of_packets(), resize(), structures::RIGHT_ENDIAN, basis::astring::s(), structures::SET(), set_bit(), subvector(), and text_form().
void structures::bit_vector::light | ( | int | position | ) |
sets the value of the bit at "position".
Definition at line 146 of file bit_vector.cpp.
References bounds_return, and set_bit().
Referenced by sockets::span_manager::update().
bool structures::bit_vector::off | ( | int | position | ) | const |
returns true if the bit at "position" is clear.
Definition at line 78 of file bit_vector.cpp.
References on().
bool structures::bit_vector::on | ( | int | position | ) | const |
returns true if the bit at "position" is set.
Definition at line 75 of file bit_vector.cpp.
Referenced by textual::byte_formatter::bytes_to_shifted_string(), compare(), find_first(), sockets::span_manager::make_missing_list(), sockets::span_manager::make_received_list(), off(), subvector(), and text_form().
structures::bit_vector::operator const basis::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.
bit_vector & structures::bit_vector::operator= | ( | const bit_vector & | to_copy | ) |
Definition at line 56 of file bit_vector.cpp.
bool structures::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 72 of file bit_vector.cpp.
References compare().
bool structures::bit_vector::operator[] | ( | int | position | ) | const |
returns the value of the bit at the position specified.
Definition at line 140 of file bit_vector.cpp.
References bounds_return.
bool structures::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 220 of file bit_vector.cpp.
References bits(), bounds_return, and set_bit().
Referenced by set().
void structures::bit_vector::reset | ( | int | size | ) |
resizes the bit_vector and clears all bits in it.
Definition at line 105 of file bit_vector.cpp.
References basis::array< contents >::access(), basis::array< contents >::length(), and resize().
Referenced by bit_vector().
void structures::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 80 of file bit_vector.cpp.
References bits(), BITS_PER_BYTE, clear(), basis::negative(), basis::number_of_packets(), basis::array< contents >::resize(), and basis::array< contents >::use().
Referenced by get(), sockets::span_manager::reset(), reset(), set(), and textual::byte_formatter::shifted_string_to_bytes().
bool structures::bit_vector::set | ( | int | start, |
int | size, | ||
basis::un_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 236 of file bit_vector.cpp.
References bits(), bounds_return, structures::host_bit_order, overwrite(), basis::array< contents >::resize(), resize(), and structures::RIGHT_ENDIAN.
void structures::bit_vector::set_bit | ( | int | position, |
bool | value | ||
) |
sets the bit at "position" to a particular "value".
Definition at line 127 of file bit_vector.cpp.
References bits(), and bounds_return.
Referenced by clear(), get(), light(), overwrite(), textual::byte_formatter::shifted_string_to_bytes(), and subvector().
bit_vector structures::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 210 of file bit_vector.cpp.
References bit_vector(), bits(), bounds_return, on(), and set_bit().
Referenced by get().
astring structures::bit_vector::text_form | ( | ) | const |
prints a nicely formatted list of bits to a string.
Definition at line 184 of file bit_vector.cpp.
References BITS_PER_BYTE, and on().
Referenced by get().
bool structures::bit_vector::whole | ( | ) | const |
returns true if entire vector is set.
Definition at line 68 of file bit_vector.cpp.
References find_first(), and basis::negative().