OpenCog Framework
Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
|
#include <AtomTable.h>
Public Member Functions | |
AtomTable (AtomTable *parent=NULL, AtomSpace *holder=NULL) | |
~AtomTable () | |
UUID | get_uuid (void) |
AtomSpace * | getAtomSpace (void) |
size_t | getSize () const |
size_t | getNumNodes () const |
size_t | getNumLinks () const |
size_t | getNumAtomsOfType (Type type, bool subclass=true) const |
Handle | getHandle (Type, std::string) const |
Handle | getHandle (const NodePtr &) const |
Handle | getHandle (Type, const HandleSeq &) const |
Handle | getHandle (const LinkPtr &) const |
Handle | getHandle (const AtomPtr &) const |
Handle | getHandle (Handle &) const |
template<typename OutputIterator > | |
OutputIterator | getHandlesByType (OutputIterator result, Type type, bool subclass=false, bool parent=true) const |
template<typename Function > | |
void | foreachHandleByType (Function func, Type type, bool subclass=false, bool parent=true) const |
UnorderedHandleSet | getHandlesByAV (AttentionValue::sti_t lowerBound, AttentionValue::sti_t upperBound=AttentionValue::MAXSTI) const |
void | updateImportanceIndex (AtomPtr a, int bin) |
Handle | add (AtomPtr, bool async) |
void | barrier (void) |
bool | holds (Handle &h) const |
NodePtr | getNode (Handle &h) const |
LinkPtr | getLink (Handle &h) const |
AtomPtrSet | extract (Handle &handle, bool recursive=true) |
Handle | getRandom (RandGen *rng) const |
AtomSignal & | addAtomSignal () |
AtomPtrSignal & | removeAtomSignal () |
AVCHSigl & | AVChangedSignal () |
TVCHSigl & | TVChangedSignal () |
Static Public Member Functions | |
static AtomPtr | factory (Type atom_type, AtomPtr atom) |
Private Member Functions | |
void | put_atom_into_index (AtomPtr &) |
void | typeAdded (Type) |
bool | isCleared () const |
bool | inEnviron (AtomPtr) |
AtomTable & | operator= (const AtomTable &) |
AtomTable (const AtomTable &) | |
Private Attributes | |
size_t | size |
std::unordered_set< Handle, handle_hash > | _atom_set |
TypeIndex | typeIndex |
NodeIndex | nodeIndex |
LinkIndex | linkIndex |
ImportanceIndex | importanceIndex |
async_caller< AtomTable, AtomPtr > | _index_queue |
boost::signals2::connection | addedTypeConnection |
AtomSignal | _addAtomSignal |
AtomPtrSignal | _removeAtomSignal |
TVCHSigl | _TVChangedSignal |
AVCHSigl | _AVChangedSignal |
AtomTable * | _environ |
UUID | _uuid |
AtomSpace * | _as |
Static Private Attributes | |
static std::recursive_mutex | _mtx |
Friends | |
class | SavingLoading |
class | ::AtomTableUTest |
This class provides mechanisms to store atoms and keep indices for efficient lookups. It implements the local storage data structure of OpenCog. It contains methods to add and remove atoms, as well as to retrieve specific sets according to different criteria.
Definition at line 79 of file AtomTable.h.
|
private |
Definition at line 123 of file AtomTable.cc.
Constructor and destructor for this class.
Definition at line 64 of file AtomTable.cc.
References _as, _environ, _uuid, addedTypeConnection, opencog::ClassServer::addTypeSignal(), opencog::classserver(), opencog::TLB::reserve_extent(), opencog::Handle::set_resolver(), size, and typeAdded().
AtomTable::~AtomTable | ( | ) |
Definition at line 83 of file AtomTable.cc.
References _atom_set, _mtx, addedTypeConnection, opencog::Handle::clear_resolver(), opencog::Handle::UNDEFINED, and opencog::Handle::value().
Adds an atom to the table. If the atom already is in the atomtable, then the truth values and attention values of the two are merged (how, exactly? Is this doe corrrectly!?)
If the async flag is set, then the atom addition is performed asynchronously; the atom might not be fully added by the time this method returns, although it will get added eventually. Async addition can improve the multi-threaded performance of lots of parallel adds. The barrier() method can be used to force synchronization.
XXX The async code path doesn't really do anything yet, since it also uses the big global lock, at the moment. This needs fixing, mostly be creating a second mutex for the atom insertion, and also giving each index its own uique mutex, to avoid collsions. So teh API is here, but more work is stil needed.
The | new atom to be added. |
Definition at line 394 of file AtomTable.cc.
References _addAtomSignal, _atom_set, _index_queue, _mtx, opencog::Handle::_ptr, opencog::TLB::addAtom(), opencog::classserver(), clone_factory(), createLink, DPRINTF, factory(), getHandle(), opencog::Atom::getHandle(), inEnviron(), opencog::Atom::insert_atom(), opencog::LinkCast(), prt_diag(), put_atom_into_index(), opencog::Atom::remove_atom(), opencog::TLB::reserve_upto(), size, opencog::Handle::UNDEFINED, and opencog::Handle::value().
|
inline |
Definition at line 343 of file AtomTable.h.
References _addAtomSignal.
|
inline |
Provide ability for others to find out about AV changes
Definition at line 347 of file AtomTable.h.
References _AVChangedSignal.
void AtomTable::barrier | ( | void | ) |
Read-write synchronization barrier fence. When called, this will not return until all the atoms previously added to the atomspace have been fully inserted.
Definition at line 615 of file AtomTable.cc.
References _index_queue.
AtomPtrSet AtomTable::extract | ( | Handle & | handle, |
bool | recursive = true |
||
) |
Extracts atoms from the table. Table will not contain the extracted atoms anymore.
Note that if the recursive flag is set to false, and the atom appears in the incoming set of some other atom, then extraction will fail. Thus, it is generally recommended that extraction be recursive, unless you can guarentee that the atom is not in someone else's outgoing set.
handle | The atom to be extracted. |
recursive | Recursive-removal flag; if set, the links in the incoming set will also be extracted. |
Definition at line 667 of file AtomTable.cc.
References _atom_set, _mtx, _removeAtomSignal, python.create_atoms_by_type::a, python.atom_type_names::atom, DPRINTF, opencog::Atom::getAtomTable(), getHandle(), opencog::Atom::getIncomingSet(), opencog::Atom::getIncomingSetSize(), importanceIndex, inEnviron(), opencog::Atom::isMarkedForRemoval(), opencog::LinkCast(), linkIndex, nodeIndex, opencog::ImportanceIndex::removeAtom(), opencog::LinkIndex::removeAtom(), opencog::NodeIndex::removeAtom(), opencog::TypeIndex::removeAtom(), python.bindlink::result, size, opencog::Atom::toString(), typeIndex, and opencog::Atom::unsetRemovalFlag().
Definition at line 269 of file AtomTable.cc.
References python.atom_type_names::atom, opencog::BindLinkCast(), opencog::classserver(), createBindLink, createDefineLink, createLambdaLink, createNumberNode, createPatternLink, createPutLink, createTypeNode, createVariableList, opencog::DefineLinkCast(), opencog::LambdaLinkCast(), opencog::LinkCast(), opencog::NodeCast(), opencog::NumberNodeCast(), opencog::PatternLinkCast(), opencog::PutLinkCast(), opencog::TypeNodeCast(), and opencog::VariableListCast().
|
inline |
Calls function 'func' on all atoms
Definition at line 219 of file AtomTable.h.
References _environ, _mtx, opencog::TypeIndex::begin(), opencog::TypeIndex::end(), foreachHandleByType(), and typeIndex.
|
inline |
Definition at line 165 of file AtomTable.h.
References _uuid.
|
inline |
Definition at line 166 of file AtomTable.h.
References _as.
Returns the exact atom for the given name and type. Note: Type must inherit from NODE. Otherwise, it returns Handle::UNDEFINED.
The | name of the desired atom. |
The | type of the desired atom. |
Definition at line 130 of file AtomTable.cc.
References _environ, _mtx, python.atom_type_names::atom, opencog::NodeIndex::getAtom(), getHandle(), opencog::Atom::getHandle(), nodeIndex, opencog::Handle::UNDEFINED, opencog::NumberNode::validate(), and opencog::TypeNode::validate().
Find an equivalent atom that has exactly the same name and type. That is, if there is an atom with this name and type already in the table, then return that; else return undefined.
Definition at line 153 of file AtomTable.cc.
References _environ, and getHandle().
Definition at line 164 of file AtomTable.cc.
References _environ, _mtx, opencog::classserver(), opencog::Handle::compare(), opencog::LinkIndex::getHandle(), getHandle(), linkIndex, and opencog::Handle::UNDEFINED.
Find an equivalent atom that has exactly the same type and outgoing set. That is, if there is an atom with this ype and outset already in the table, then return that; else return undefined.
Definition at line 193 of file AtomTable.cc.
References _environ, and getHandle().
Find an equivalent atom that is exactly the same as the arg. If such an atom is in the table, it is returned, else the return is the bad handle.
Definition at line 207 of file AtomTable.cc.
References getHandle(), opencog::LinkCast(), opencog::NodeCast(), and opencog::Handle::UNDEFINED.
Definition at line 220 of file AtomTable.cc.
References _atom_set, _environ, _mtx, opencog::Handle::_ptr, getHandle(), opencog::Handle::UNDEFINED, and opencog::Handle::value().
|
inline |
Returns the set of atoms within the given importance range.
Importance | range lower bound (inclusive). |
Importance | range upper bound (inclusive). |
Definition at line 241 of file AtomTable.h.
References _mtx, opencog::ImportanceIndex::getHandleSet(), and importanceIndex.
|
inline |
Returns the set of atoms of a given type (subclasses optionally).
The | desired type. |
Whether | type subclasses should be considered. |
Definition at line 204 of file AtomTable.h.
References _environ, _mtx, opencog::TypeIndex::begin(), opencog::TypeIndex::end(), getHandlesByType(), python.bindlink::result, and typeIndex.
Get Link object already in the AtomTable.
h | Handle of the link to retrieve. |
Definition at line 316 of file AtomTable.h.
References getHandle(), and opencog::LinkCast().
Get Node object already in the AtomTable.
h | Handle of the node to retrieve. |
Definition at line 305 of file AtomTable.h.
References getHandle(), and opencog::NodeCast().
size_t AtomTable::getNumAtomsOfType | ( | Type | type, |
bool | subclass = true |
||
) | const |
Definition at line 637 of file AtomTable.cc.
References _environ, _mtx, opencog::TypeIndex::getNumAtomsOfType(), getNumAtomsOfType(), python.bindlink::result, and typeIndex.
size_t AtomTable::getNumLinks | ( | ) | const |
Definition at line 631 of file AtomTable.cc.
References _mtx, linkIndex, and opencog::LinkIndex::size().
size_t AtomTable::getNumNodes | ( | ) | const |
Definition at line 625 of file AtomTable.cc.
References _mtx, nodeIndex, and opencog::NodeIndex::size().
Handle AtomTable::getRandom | ( | RandGen * | rng | ) | const |
Return a random atom in the AtomTable.
Definition at line 648 of file AtomTable.cc.
References foreachHandleByType(), getSize(), and opencog::Handle::UNDEFINED.
size_t AtomTable::getSize | ( | ) | const |
Return the number of atoms contained in a table.
Definition at line 620 of file AtomTable.cc.
References size.
|
inline |
Return true if the atom table holds this handle, else return false.
Definition at line 295 of file AtomTable.h.
References opencog::Atom::getAtomTable().
|
private |
Return true if the atom is in this atomtable, or in the environment for this atomtable.
Definition at line 256 of file AtomTable.cc.
References _environ.
|
private |
Definition at line 99 of file AtomTable.cc.
References _mtx, DPRINTF, importanceIndex, opencog::FixedIntegerIndex::size(), size, and typeIndex.
Override and declare copy constructor and equals operator as private. This is to prevent large object copying by mistake.
Definition at line 117 of file AtomTable.cc.
|
inline |
Definition at line 344 of file AtomTable.h.
References _removeAtomSignal.
|
inline |
Provide ability for others to find out about TV changes
Definition at line 350 of file AtomTable.h.
References _TVChangedSignal.
|
private |
Handler of the 'type added' signal from ClassServer
Definition at line 829 of file AtomTable.cc.
References _mtx, linkIndex, nodeIndex, opencog::LinkIndex::resize(), opencog::TypeIndex::resize(), opencog::NodeIndex::resize(), and typeIndex.
|
inline |
Updates the importance index for the given atom. According to the new importance of the atom, it may change importance bins.
The | atom whose importance index will be updated. |
The | old importance bin where the atom originally was. |
Definition at line 255 of file AtomTable.h.
References _mtx, importanceIndex, and opencog::ImportanceIndex::updateImportance().
|
friend |
Definition at line 82 of file AtomTable.h.
|
friend |
Definition at line 81 of file AtomTable.h.
|
private |
Provided signals
Definition at line 127 of file AtomTable.h.
|
private |
Definition at line 150 of file AtomTable.h.
|
private |
Definition at line 104 of file AtomTable.h.
|
private |
Signal emitted when the AV changes.
Definition at line 134 of file AtomTable.h.
|
private |
Parent environment for this table. Null if top-level. This allows atomspaces to be nested; atoms in this atomspace can reference those in the parent environment. The UUID is used to uniquely identify it, for distributed operation. Viz, other computers on the network may have a copy of this atomtable, and so need to have its UUID to sync up.
Definition at line 145 of file AtomTable.h.
|
staticprivate |
Definition at line 90 of file AtomTable.h.
|
private |
Definition at line 128 of file AtomTable.h.
|
private |
Signal emitted when the TV changes.
Definition at line 131 of file AtomTable.h.
|
private |
Definition at line 147 of file AtomTable.h.
|
private |
signal connection used to find out about atom type additions in the ClassServer
Definition at line 121 of file AtomTable.h.
|
private |
Definition at line 92 of file AtomTable.h.