OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
opencog::AtomTable Class Reference

#include <AtomTable.h>

+ Collaboration diagram for opencog::AtomTable:

Public Member Functions

 AtomTable (AtomTable *parent=NULL, AtomSpace *holder=NULL)
 
 ~AtomTable ()
 
UUID get_uuid (void)
 
AtomSpacegetAtomSpace (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
 
AtomSignaladdAtomSignal ()
 
AtomPtrSignalremoveAtomSignal ()
 
AVCHSiglAVChangedSignal ()
 
TVCHSiglTVChangedSignal ()
 

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)
 
AtomTableoperator= (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
 

Detailed Description

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.

Constructor & Destructor Documentation

AtomTable::AtomTable ( const AtomTable other)
private

Definition at line 123 of file AtomTable.cc.

AtomTable::AtomTable ( AtomTable parent = NULL,
AtomSpace holder = NULL 
)

Member Function Documentation

Handle AtomTable::add ( AtomPtr  atom,
bool  async 
)

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.

Parameters
Thenew atom to be added.
Returns
The handle of the newly added atom.

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().

+ Here is the caller graph for this function:

AtomSignal& opencog::AtomTable::addAtomSignal ( )
inline

Definition at line 343 of file AtomTable.h.

References _addAtomSignal.

+ Here is the caller graph for this function:

AVCHSigl& opencog::AtomTable::AVChangedSignal ( )
inline

Provide ability for others to find out about AV changes

Definition at line 347 of file AtomTable.h.

References _AVChangedSignal.

+ Here is the caller graph for this function:

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.

+ Here is the caller graph for this function:

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.

Parameters
handleThe atom to be extracted.
recursiveRecursive-removal flag; if set, the links in the incoming set will also be extracted.
Returns
A set of the extracted atoms.

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().

+ Here is the caller graph for this function:

template<typename Function >
void opencog::AtomTable::foreachHandleByType ( Function  func,
Type  type,
bool  subclass = false,
bool  parent = true 
) const
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.

+ Here is the caller graph for this function:

UUID opencog::AtomTable::get_uuid ( void  )
inline

Definition at line 165 of file AtomTable.h.

References _uuid.

AtomSpace* opencog::AtomTable::getAtomSpace ( void  )
inline

Definition at line 166 of file AtomTable.h.

References _as.

+ Here is the caller graph for this function:

Handle AtomTable::getHandle ( Type  t,
std::string  name 
) const

Returns the exact atom for the given name and type. Note: Type must inherit from NODE. Otherwise, it returns Handle::UNDEFINED.

Parameters
Thename of the desired atom.
Thetype of the desired atom.
Returns
The handle of the desired atom if found.

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().

+ Here is the caller graph for this function:

Handle AtomTable::getHandle ( const NodePtr n) const

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().

Handle AtomTable::getHandle ( Type  t,
const HandleSeq seq 
) const
Handle AtomTable::getHandle ( const LinkPtr l) const

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().

Handle AtomTable::getHandle ( const AtomPtr a) const

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.

Handle AtomTable::getHandle ( Handle h) const
UnorderedHandleSet opencog::AtomTable::getHandlesByAV ( AttentionValue::sti_t  lowerBound,
AttentionValue::sti_t  upperBound = AttentionValue::MAXSTI 
) const
inline

Returns the set of atoms within the given importance range.

Parameters
Importancerange lower bound (inclusive).
Importancerange upper bound (inclusive).
Returns
The set of atoms within the given importance range.

Definition at line 241 of file AtomTable.h.

References _mtx, opencog::ImportanceIndex::getHandleSet(), and importanceIndex.

+ Here is the caller graph for this function:

template<typename OutputIterator >
OutputIterator opencog::AtomTable::getHandlesByType ( OutputIterator  result,
Type  type,
bool  subclass = false,
bool  parent = true 
) const
inline

Returns the set of atoms of a given type (subclasses optionally).

Parameters
Thedesired type.
Whethertype subclasses should be considered.
Returns
The set of atoms of a given type (subclasses optionally).

Definition at line 204 of file AtomTable.h.

References _environ, _mtx, opencog::TypeIndex::begin(), opencog::TypeIndex::end(), getHandlesByType(), python.bindlink::result, and typeIndex.

+ Here is the caller graph for this function:

LinkPtr opencog::AtomTable::getLink ( Handle h) const
inline

Get Link object already in the AtomTable.

Parameters
hHandle of the link to retrieve.
Returns
pointer to Link object, NULL if no atom within this AtomTable is associated with handle or if the atom is a node.

Definition at line 316 of file AtomTable.h.

References getHandle(), and opencog::LinkCast().

NodePtr opencog::AtomTable::getNode ( Handle h) const
inline

Get Node object already in the AtomTable.

Parameters
hHandle of the node to retrieve.
Returns
pointer to Node object, NULL if no atom within this AtomTable is associated with handle or if the atom is a link.

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.

+ Here is the caller graph for this function:

size_t AtomTable::getNumLinks ( ) const

Definition at line 631 of file AtomTable.cc.

References _mtx, linkIndex, and opencog::LinkIndex::size().

+ Here is the caller graph for this function:

size_t AtomTable::getNumNodes ( ) const

Definition at line 625 of file AtomTable.cc.

References _mtx, nodeIndex, and opencog::NodeIndex::size().

+ Here is the caller graph for this function:

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.

+ Here is the caller graph for this function:

bool opencog::AtomTable::holds ( Handle h) const
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().

+ Here is the caller graph for this function:

bool AtomTable::inEnviron ( AtomPtr  atom)
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.

+ Here is the caller graph for this function:

bool AtomTable::isCleared ( void  ) const
private

Definition at line 99 of file AtomTable.cc.

References _mtx, DPRINTF, importanceIndex, opencog::FixedIntegerIndex::size(), size, and typeIndex.

AtomTable & AtomTable::operator= ( const AtomTable other)
private

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.

AtomPtrSignal& opencog::AtomTable::removeAtomSignal ( )
inline

Definition at line 344 of file AtomTable.h.

References _removeAtomSignal.

+ Here is the caller graph for this function:

TVCHSigl& opencog::AtomTable::TVChangedSignal ( )
inline

Provide ability for others to find out about TV changes

Definition at line 350 of file AtomTable.h.

References _TVChangedSignal.

+ Here is the caller graph for this function:

void AtomTable::typeAdded ( Type  t)
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.

+ Here is the caller graph for this function:

void opencog::AtomTable::updateImportanceIndex ( AtomPtr  a,
int  bin 
)
inline

Updates the importance index for the given atom. According to the new importance of the atom, it may change importance bins.

Parameters
Theatom whose importance index will be updated.
Theold importance bin where the atom originally was.

Definition at line 255 of file AtomTable.h.

References _mtx, importanceIndex, and opencog::ImportanceIndex::updateImportance().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class ::AtomTableUTest
friend

Definition at line 82 of file AtomTable.h.

friend class SavingLoading
friend

Definition at line 81 of file AtomTable.h.

Member Data Documentation

AtomSignal opencog::AtomTable::_addAtomSignal
private

Provided signals

Definition at line 127 of file AtomTable.h.

AtomSpace* opencog::AtomTable::_as
private

Definition at line 150 of file AtomTable.h.

std::unordered_set<Handle, handle_hash> opencog::AtomTable::_atom_set
private

Definition at line 104 of file AtomTable.h.

AVCHSigl opencog::AtomTable::_AVChangedSignal
private

Signal emitted when the AV changes.

Definition at line 134 of file AtomTable.h.

AtomTable* opencog::AtomTable::_environ
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.

std::recursive_mutex AtomTable::_mtx
staticprivate

Definition at line 90 of file AtomTable.h.

AtomPtrSignal opencog::AtomTable::_removeAtomSignal
private

Definition at line 128 of file AtomTable.h.

TVCHSigl opencog::AtomTable::_TVChangedSignal
private

Signal emitted when the TV changes.

Definition at line 131 of file AtomTable.h.

UUID opencog::AtomTable::_uuid
private

Definition at line 147 of file AtomTable.h.

boost::signals2::connection opencog::AtomTable::addedTypeConnection
private

signal connection used to find out about atom type additions in the ClassServer

Definition at line 121 of file AtomTable.h.

size_t opencog::AtomTable::size
private

Definition at line 92 of file AtomTable.h.


The documentation for this class was generated from the following files: