dlvhex
2.5.0
|
Stores a set of atoms efficiently as a bitset. More...
#include <include/dlvhex2/Interpretation.h>
Public Types | |
typedef boost::shared_ptr < Interpretation > | Ptr |
typedef boost::shared_ptr < const Interpretation > | ConstPtr |
typedef bm::bvector | Storage |
typedef boost::function< bool(IDAddress)> | FilterCallback |
typedef Storage::enumerator | TrueBitIterator |
Public Member Functions | |
Interpretation () | |
Constructor. | |
Interpretation (RegistryPtr registry) | |
Constructor. | |
virtual | ~Interpretation () |
Destructor. | |
virtual unsigned | filter (FilterCallback callback) |
Go through 1-bits and set to zero if callback returns false. | |
virtual std::ostream & | print (std::ostream &o, const char *first, const char *sep, const char *last) const |
Prints the interpretation. | |
virtual std::ostream & | printWithoutPrefix (std::ostream &o, const char *first, const char *sep, const char *last) const |
Prints the interpretation where atom names are printed without module prefixes (cf. | |
virtual std::ostream & | printAsNumber (std::ostream &o, const char *first, const char *sep, const char *last) const |
Prints the interpretation where atom ID addresses are printed rather than atom names. | |
virtual std::ostream & | print (std::ostream &o) const |
Prints the interpretation in curly braces with comma as atom delimiter. | |
virtual std::ostream & | printWithoutPrefix (std::ostream &o) const |
Prints the interpretation in curly braces with comma as atom delimiter and with atom names printed without module prefixes (cf. | |
virtual std::ostream & | printAsNumber (std::ostream &o) const |
Prints the interpretation where atom ID addresses are printed rather than atom names. | |
virtual std::ostream & | printAsFacts (std::ostream &o) const |
Prints the interpretation as set of facts (each atom follows by a dot). | |
void | add (const Interpretation &other) |
Adds another interpretation to this one. | |
void | bit_and (const Interpretation &other) |
Bit-ands this interpretation with another interpretation one. | |
Ptr | getInterpretationWithoutExternalAtomAuxiliaries () const |
Removed external atom auxiliaries from the interpretation and returns it as a new interpretation. | |
void | setFact (IDAddress id) |
Adds an atom to the interpretation. | |
void | clearFact (IDAddress id) |
Removes an atom from the interpretation. | |
bool | getFact (IDAddress id) const |
Checks if a ground atom is true in the interpretation. | |
const Storage & | getStorage () const |
Returns the internal storage of the interpretation. | |
Storage & | getStorage () |
std::pair< TrueBitIterator, TrueBitIterator > | trueBits () const |
Returns a pair of a begin and an end operator to iterate through true atoms in the interpretation. | |
const OrdinaryAtom & | getAtomToBit (IDAddress addr) const |
Helper function gives ordinary ground atom to true bit. | |
const OrdinaryAtom & | getAtomToBit (TrueBitIterator it) const |
Helper function gives ordinary ground atom to true bit. | |
RegistryPtr | getRegistry () const |
void | setRegistry (RegistryPtr registry1) |
bool | isClear () const |
Checks if the interpretation is empty. | |
void | clear () |
Resets the interpretation to the empty one. | |
bool | operator== (const Interpretation &other) const |
Compares this interpretation atomwise to another one. | |
bool | operator!= (const Interpretation &other) const |
Compares this interpretation atomwise to another one. | |
bool | operator< (const Interpretation &other) const |
Compares this interpretation atomwise to another one and checks if it is a subset of other . | |
std::size_t | getHash () const |
Returns the hash value of this interpretation. | |
Protected Attributes | |
RegistryPtr | registry |
Regirstry used to interpret IDs when printing. | |
Storage | bits |
Internal bitset storage. | |
bool | hashUpdated |
std::size_t | myHash |
Stores a set of atoms efficiently as a bitset.
Definition at line 51 of file Interpretation.h.
typedef boost::shared_ptr<const Interpretation> Interpretation::ConstPtr |
Definition at line 58 of file Interpretation.h.
typedef boost::function<bool (IDAddress)> Interpretation::FilterCallback |
Definition at line 60 of file Interpretation.h.
typedef boost::shared_ptr<Interpretation> Interpretation::Ptr |
Definition at line 57 of file Interpretation.h.
typedef bm::bvector Interpretation::Storage |
Definition at line 59 of file Interpretation.h.
Definition at line 61 of file Interpretation.h.
Interpretation::Interpretation | ( | ) | [inline] |
Constructor.
Definition at line 78 of file Interpretation.h.
Referenced by getInterpretationWithoutExternalAtomAuxiliaries().
Interpretation::Interpretation | ( | RegistryPtr | registry | ) |
Constructor.
registry | Registry to use for interpreting IDs. |
Definition at line 59 of file Interpretation.cpp.
Interpretation::~Interpretation | ( | ) | [virtual] |
Destructor.
Definition at line 66 of file Interpretation.cpp.
void Interpretation::add | ( | const Interpretation & | other | ) |
Adds another interpretation to this one.
other | Interpretation to add. |
Definition at line 181 of file Interpretation.cpp.
References bits, and hashUpdated.
void Interpretation::bit_and | ( | const Interpretation & | other | ) |
Bit-ands this interpretation with another interpretation one.
other | Interpretation to bit-add. |
Definition at line 188 of file Interpretation.cpp.
References bits, and hashUpdated.
void Interpretation::clear | ( | ) | [inline] |
Resets the interpretation to the empty one.
Definition at line 238 of file Interpretation.h.
void Interpretation::clearFact | ( | IDAddress | id | ) | [inline] |
Removes an atom from the interpretation.
id | Address of a ground atom ID. |
Definition at line 183 of file Interpretation.h.
Referenced by filter().
unsigned Interpretation::filter | ( | FilterCallback | callback | ) | [virtual] |
Go through 1-bits and set to zero if callback returns false.
callback | Callback to use. |
Definition at line 71 of file Interpretation.cpp.
References bits, clearFact(), bm::bvector< Alloc >::count(), bm::bvector< Alloc >::end(), bm::bvector< Alloc >::first(), and bm::bvector< Alloc >::set().
const OrdinaryAtom& Interpretation::getAtomToBit | ( | IDAddress | addr | ) | const [inline] |
Helper function gives ordinary ground atom to true bit.
addr | Address of an ID of an ordinary ground atom. |
Definition at line 212 of file Interpretation.h.
const OrdinaryAtom& Interpretation::getAtomToBit | ( | TrueBitIterator | it | ) | const [inline] |
Helper function gives ordinary ground atom to true bit.
it | Iterator through addresses of IDs of ordinary ground atoms. |
Definition at line 220 of file Interpretation.h.
bool Interpretation::getFact | ( | IDAddress | id | ) | const [inline] |
Checks if a ground atom is true in the interpretation.
id | Address of a ground atom ID. |
Definition at line 190 of file Interpretation.h.
std::size_t Interpretation::getHash | ( | ) | const |
Returns the hash value of this interpretation.
Definition at line 232 of file Interpretation.cpp.
References DLVHEX_BENCHMARK_REGISTER_AND_SCOPE, hash_value(), hashUpdated, and myHash.
Referenced by operator!=(), and operator==().
Removed external atom auxiliaries from the interpretation and returns it as a new interpretation.
The original (this) interpretation remains unchanged.
New | interpretation with external auxiliaries removed. |
Definition at line 195 of file Interpretation.cpp.
References bm::bvector< Alloc >::end(), bm::bvector< Alloc >::first(), getStorage(), Interpretation(), and registry.
RegistryPtr Interpretation::getRegistry | ( | ) | const [inline] |
Definition at line 223 of file Interpretation.h.
const Storage& Interpretation::getStorage | ( | ) | const [inline] |
Returns the internal storage of the interpretation.
Definition at line 197 of file Interpretation.h.
Referenced by getInterpretationWithoutExternalAtomAuxiliaries(), and hash_value().
Storage& Interpretation::getStorage | ( | ) | [inline] |
Definition at line 198 of file Interpretation.h.
bool Interpretation::isClear | ( | ) | const [inline] |
Checks if the interpretation is empty.
Definition at line 232 of file Interpretation.h.
bool Interpretation::operator!= | ( | const Interpretation & | other | ) | const |
Compares this interpretation atomwise to another one.
other | Interpretation to compare to. |
Definition at line 220 of file Interpretation.cpp.
bool Interpretation::operator< | ( | const Interpretation & | other | ) | const |
Compares this interpretation atomwise to another one and checks if it is a subset of other
.
other | Interpretation to compare to. |
Definition at line 227 of file Interpretation.cpp.
References bits.
bool Interpretation::operator== | ( | const Interpretation & | other | ) | const |
Compares this interpretation atomwise to another one.
other | Interpretation to compare to. |
Definition at line 213 of file Interpretation.cpp.
std::ostream & Interpretation::print | ( | std::ostream & | o, |
const char * | first, | ||
const char * | sep, | ||
const char * | last | ||
) | const [virtual] |
Prints the interpretation.
o | Stream to print. |
first | String to print at the begining of the output. |
sep | Atom delimiter. |
last | String to print at the end of the output. |
o
. Definition at line 125 of file Interpretation.cpp.
References bits, bm::bvector< Alloc >::end(), bm::bvector< Alloc >::first(), ID::MAINKIND_ATOM, RawPrinter::print(), registry, and ID::SUBKIND_ATOM_ORDINARYG.
Referenced by print(), and printAsFacts().
std::ostream & Interpretation::print | ( | std::ostream & | o | ) | const [virtual] |
Prints the interpretation in curly braces with comma as atom delimiter.
o | Stream to print. |
o
. Reimplemented from InterpretationBase.
Definition at line 97 of file Interpretation.cpp.
References print().
std::ostream & Interpretation::printAsFacts | ( | std::ostream & | o | ) | const [virtual] |
Prints the interpretation as set of facts (each atom follows by a dot).
o | Stream to print. |
o
. Definition at line 115 of file Interpretation.cpp.
References bits, bm::bvector< Alloc >::end(), bm::bvector< Alloc >::first(), and print().
std::ostream & Interpretation::printAsNumber | ( | std::ostream & | o, |
const char * | first, | ||
const char * | sep, | ||
const char * | last | ||
) | const [virtual] |
Prints the interpretation where atom ID addresses are printed rather than atom names.
o | Stream to print. |
first | String to print at the begining of the output. |
sep | Atom delimiter. |
last | String to print at the end of the output. |
o
. Definition at line 163 of file Interpretation.cpp.
References bits, bm::bvector< Alloc >::end(), and bm::bvector< Alloc >::first().
Referenced by printAsNumber().
std::ostream & Interpretation::printAsNumber | ( | std::ostream & | o | ) | const [virtual] |
Prints the interpretation where atom ID addresses are printed rather than atom names.
o | Stream to print. |
o
. Definition at line 109 of file Interpretation.cpp.
References printAsNumber().
std::ostream & Interpretation::printWithoutPrefix | ( | std::ostream & | o, |
const char * | first, | ||
const char * | sep, | ||
const char * | last | ||
) | const [virtual] |
Prints the interpretation where atom names are printed without module prefixes (cf.
modular HEX).
o | Stream to print. |
first | String to print at the begining of the output. |
sep | Atom delimiter. |
last | String to print at the end of the output. |
o
. Definition at line 144 of file Interpretation.cpp.
References bits, bm::bvector< Alloc >::end(), bm::bvector< Alloc >::first(), ID::MAINKIND_ATOM, RawPrinter::printWithoutPrefix(), registry, and ID::SUBKIND_ATOM_ORDINARYG.
Referenced by printWithoutPrefix().
std::ostream & Interpretation::printWithoutPrefix | ( | std::ostream & | o | ) | const [virtual] |
Prints the interpretation in curly braces with comma as atom delimiter and with atom names printed without module prefixes (cf.
modular HEX).
o | Stream to print. |
o
. Definition at line 103 of file Interpretation.cpp.
References printWithoutPrefix().
void Interpretation::setFact | ( | IDAddress | id | ) | [inline] |
Adds an atom to the interpretation.
id | Address of a ground atom ID. |
Definition at line 176 of file Interpretation.h.
void Interpretation::setRegistry | ( | RegistryPtr | registry1 | ) | [inline] |
Definition at line 226 of file Interpretation.h.
std::pair<TrueBitIterator, TrueBitIterator> Interpretation::trueBits | ( | ) | const [inline] |
Returns a pair of a begin and an end operator to iterate through true atoms in the interpretation.
Definition at line 204 of file Interpretation.h.
Storage Interpretation::bits [protected] |
Internal bitset storage.
Definition at line 68 of file Interpretation.h.
Referenced by add(), bit_and(), filter(), operator!=(), operator<(), operator==(), print(), printAsFacts(), printAsNumber(), and printWithoutPrefix().
bool Interpretation::hashUpdated [mutable, protected] |
Definition at line 71 of file Interpretation.h.
std::size_t Interpretation::myHash [mutable, protected] |
Definition at line 74 of file Interpretation.h.
Referenced by getHash().
RegistryPtr Interpretation::registry [protected] |
Regirstry used to interpret IDs when printing.
Definition at line 66 of file Interpretation.h.
Referenced by getInterpretationWithoutExternalAtomAuxiliaries(), print(), and printWithoutPrefix().