![]() |
KSquare Utilities
|
Allows you to manage very long bit strings. More...
#include <BitString.h>
Inheritance diagram for KKB::BitString:Public Member Functions | |
| BitString () | |
| Instantiates a empty bit-string of length 0; needed for ReadXML. More... | |
| BitString (kkuint32 _bitLen) | |
| Construct a bit string of length _binLen with all bits set to '0'. More... | |
| BitString (const BitString &b) | |
| Copy constructor. More... | |
| BitString (kkuint32 _bitLen, kkuint16 *_bitNums, kkuint32 _bitNumsLen) | |
| Construct a BitString of length _bitLen with bits indicated by '_bitNums' set to '1'. More... | |
| ~BitString () | |
| kkuint32 | BitLen () const |
| Returns the length of the bit-string. More... | |
| const char * | ClassName () const |
| kkuint32 | Count () const |
| Returns number of bits set to '1'. More... | |
| virtual BitString * | Duplicate () const |
| KKStr | HexStr () const |
| Returns a Hex-String representation. More... | |
| void | ListOfSetBits16 (VectorUint16 &setBits) const |
| void | ListOfSetBits32 (VectorUint32 &setBits) const |
| bool | operator!= (const BitString &right) const |
| BitString & | operator&= (const BitString &right) |
| Performs a bitwise AND against the left operand. More... | |
| BitString & | operator*= (const BitString &right) |
| Performs a bitwise AND against the left operand. More... | |
| BitString & | operator+= (const BitString &right) |
| Performs a bitwise OR against the left operand. More... | |
| bool | operator< (const BitString &right) const |
| bool | operator<= (const BitString &right) const |
| BitString & | operator= (const BitString &right) |
| bool | operator== (const BitString &right) const |
| bool | operator> (const BitString &right) const |
| bool | operator>= (const BitString &right) const |
| BitString | operator^ (const BitString &right) |
| Performs a bitwise XOR between two operands returning a new BitString. More... | |
| BitString & | operator^= (const BitString &right) |
| Performs a bitwise XOR against the left operand. More... | |
| BitString & | operator|= (const BitString &right) |
| Performs a bitwise OR against the left operand. More... | |
| void | PopulateVectorBool (VectorBool &boolVector) const |
| Populates a boolean vector where each element reflects whether the corresponding bit is set. More... | |
| virtual void | ReadXML (XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log) |
| void | ReSet () |
| Set all bits to '0'. More... | |
| void | ReSet (kkuint32 bitNum) |
| Set the bit indicated by 'bitNum' to '0'. More... | |
| void | Set () |
| Set all bits to '1'. More... | |
| void | Set (kkuint32 bitNum) |
| Set the bit indicated by 'bitNum' to '1'. More... | |
| bool | Test (kkuint32 bitNum) const |
| virtual void | WriteXML (const KKStr &varName, std::ostream &o) const |
Public Member Functions inherited from KKB::Atom | |
| Atom () | |
| virtual | ~Atom () |
Static Public Member Functions | |
| static BitString | FromHexStr (const KKStr &hexStr, bool &validHexStr) |
| Create a bit-string from a Hex String. More... | |
Additional Inherited Members | |
Public Types inherited from KKB::Atom | |
| typedef AtomPtr(* | AtomCreator) (XmlStream &i) |
| typedef Atom * | AtomPtr |
Allows you to manage very long bit strings.
Useful when you need to deal with very large yes/no decisions. For example performing Feature Selection on a DNA dataset where you can have 50,000+ features. You need to keep a list of which feature combinations have been tried. You can use a BitString to do this where a particular bit indicates a particular feature. In the feature selection case you may want to track several thousand feature combinations. If you did this using arrays you would require very large amount of memory to accomplish this. With BitString's the memory requirement is reduced to 1/8'the allowing for more efficient use of memory.
This class will manage Bit-Strings up to UINT_MAX in length. Logical operations such as bitwise AND, OR, and NOT are supported plus others. An example of where this class is used is in KKMLL::FeatureNumList.
Definition at line 31 of file BitString.h.
| BitString::BitString | ( | ) |
Instantiates a empty bit-string of length 0; needed for ReadXML.
Definition at line 58 of file BitString.cpp.
| BitString::BitString | ( | kkuint32 | _bitLen | ) |
Construct a bit string of length _binLen with all bits set to '0'.
| [in] | _bitLen | Length of bit string to allocate. |
Definition at line 68 of file BitString.cpp.
Referenced by FromHexStr(), and KKMLL::FeatureNumList::ToHexString().
| BitString::BitString | ( | const BitString & | b | ) |
Construct a BitString of length _bitLen with bits indicated by '_bitNums' set to '1'.
| [in] | _binLen | Length of bit string. |
| [in] | _bitNums | List if bit positions to set to '1'. |
| [in] | _bitNumsLen | Size of '_bitNums' array. |
Definition at line 89 of file BitString.cpp.
References KKB::KKStr::Concat(), KKB::KKException::KKException(), KKB::KKStr::KKStr(), and Set().
| BitString::~BitString | ( | ) |
Definition at line 116 of file BitString.cpp.
|
inline |
Returns the length of the bit-string.
Definition at line 64 of file BitString.h.
Referenced by KKMLL::FeatureNumList::FeatureNumList().
|
inlinevirtual |
| kkuint32 BitString::Count | ( | ) | const |
Returns number of bits set to '1'.
summary> Returns true if bit indicated by bitNum is set to 1.
Definition at line 142 of file BitString.cpp.
|
virtual |
Implements KKB::Atom.
Definition at line 124 of file BitString.cpp.
References BitString().
Create a bit-string from a Hex String.
Will convert the Hex String stored in the parameter 'hexStr' and create a bit string from it.
ex: "A189" will be converted into "1010000110001001"
| [in] | hexStr | String containing hex characters '0' - '9', 'A' - 'F' |
| [out] | validHexStr | returns 'TRUE' if no invalid characters. |
Definition at line 399 of file BitString.cpp.
References BitString(), KKB::KKStr::Len(), and KKB::KKStr::operator[]().
| KKStr BitString::HexStr | ( | ) | const |
Returns a Hex-String representation.
ex: "1110 0000 0101 1011" would return "E09B".
Definition at line 361 of file BitString.cpp.
References KKB::KKStr::Append(), KKB::KKStr::Concat(), and KKB::KKStr::KKStr().
Referenced by KKMLL::FeatureNumList::ToHexString(), and WriteXML().
| void BitString::ListOfSetBits16 | ( | VectorUint16 & | setBits | ) | const |
summary> Get Bit positions that are set to "1". The parameter setBits will be populated with the list of bits that are set to "1" for bit strings that are up to 2^32-1 bits long. /summary> example> ex: Bit String "001200110011" will produce a vector <2, 3, 6, 7, 10, 11> /example> param in="setBits"> Will be populated with all bits that are set to "1", will be cleared first.
Definition at line 266 of file BitString.cpp.
References KKB::KKStr::Concat(), KKB::KKException::KKException(), and KKB::KKStr::KKStr().
Referenced by KKMLL::FeatureNumList::FeatureNumList().
| void BitString::ListOfSetBits32 | ( | VectorUint32 & | setBits | ) | const |
Definition at line 317 of file BitString.cpp.
| bool BitString::operator!= | ( | const BitString & | right | ) | const |
Definition at line 552 of file BitString.cpp.
Performs a bitwise AND against the left operand.
Definition at line 484 of file BitString.cpp.
Referenced by operator*=().
Performs a bitwise AND against the left operand.
Definition at line 504 of file BitString.cpp.
References operator&=().
Performs a bitwise OR against the left operand.
Definition at line 475 of file BitString.cpp.
References operator|=().
| bool BitString::operator< | ( | const BitString & | right | ) | const |
Definition at line 573 of file BitString.cpp.
| bool KKB::BitString::operator<= | ( | const BitString & | right | ) | const |
Definition at line 441 of file BitString.cpp.
| bool BitString::operator== | ( | const BitString & | right | ) | const |
Definition at line 545 of file BitString.cpp.
| bool BitString::operator> | ( | const BitString & | right | ) | const |
Definition at line 559 of file BitString.cpp.
| bool BitString::operator>= | ( | const BitString & | right | ) | const |
Definition at line 566 of file BitString.cpp.
Performs a bitwise XOR between two operands returning a new BitString.
Definition at line 598 of file BitString.cpp.
Performs a bitwise XOR against the left operand.
Definition at line 580 of file BitString.cpp.
Performs a bitwise OR against the left operand.
Definition at line 459 of file BitString.cpp.
Referenced by operator+=().
| void BitString::PopulateVectorBool | ( | VectorBool & | boolVector | ) | const |
Populates a boolean vector where each element reflects whether the corresponding bit is set.
| [out] | boolVector | Vector to be populated reflecting which bits are set to '1'. |
Definition at line 239 of file BitString.cpp.
|
virtual |
TODO decode text block into list of bits.
Implements KKB::Atom.
Definition at line 618 of file BitString.cpp.
References KKB::XmlContent::Content(), and KKB::XmlStream::GetNextToken().
| void BitString::ReSet | ( | ) |
Set all bits to '0'.
Definition at line 207 of file BitString.cpp.
Referenced by KKMLL::FeatureNumList::ToBitString().
| void BitString::ReSet | ( | kkuint32 | bitNum | ) |
Set the bit indicated by 'bitNum' to '0'.
Definition at line 215 of file BitString.cpp.
| void BitString::Set | ( | ) |
Set all bits to '1'.
Definition at line 173 of file BitString.cpp.
| void BitString::Set | ( | kkuint32 | bitNum | ) |
Set the bit indicated by 'bitNum' to '1'.
Definition at line 182 of file BitString.cpp.
Referenced by BitString(), and KKMLL::FeatureNumList::ToBitString().
| bool BitString::Test | ( | kkuint32 | bitNum | ) | const |
summary> Get Bit positions that are set to 1; The parameter setBits will be populated with the list of bits that are set to 1 for bit strings that are up to 2^16-1 bits long. /summary> code> ex: Bit String "001200110011" will produce a vector <2, 3, 6, 7, 10, 11> /code> param name='setBits'> Will be populated with all bits that are set to '1', will be cleared first.
Definition at line 158 of file BitString.cpp.
|
virtual |
Implements KKB::Atom.
Definition at line 650 of file BitString.cpp.
References KKB::XmlTag::AddAtribute(), KKB::KKStr::Empty(), HexStr(), KKB::XmlTag::tagEnd, KKB::XmlTag::tagStart, KKB::XmlTag::WriteXML(), KKB::XmlContent::WriteXml(), and KKB::XmlTag::XmlTag().