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

red-black tree maps Handle keys to type T elements More...

#include <HandleMap.h>

+ Inheritance diagram for opencog::HandleMap< T >:
+ Collaboration diagram for opencog::HandleMap< T >:

Public Types

typedef std::shared_ptr
< HandleMap< T > > 
MapPtr
 

Public Member Functions

 HandleMap ()
 
void add (Handle key, T element) throw (RuntimeException)
 
get (Handle key)
 
bool contains (Handle key)
 
remove (Handle key)
 
void resize (int newSize)
 
int get_count ()
 
int get_size ()
 
HandleMapIterator< T > * keys ()
 

Private Types

typedef std::map< Handle, T,
std::less< Handle > > 
InternalMap
 
typedef InternalMap::iterator InternalIterator
 

Private Attributes

InternalMap _handle_map
 
std::mutex _mtx
 

Friends

class HandleMapIterator< T >
 

Detailed Description

template<class T>
class opencog::HandleMap< T >

red-black tree maps Handle keys to type T elements

This is an Adapter to stl's HashMap.

Definition at line 53 of file HandleMap.h.

Member Typedef Documentation

template<class T >
typedef InternalMap::iterator opencog::HandleMap< T >::InternalIterator
private

Definition at line 64 of file HandleMap.h.

template<class T >
typedef std::map< Handle, T, std::less<Handle> > opencog::HandleMap< T >::InternalMap
private

Defines an iterator to the map.

Definition at line 63 of file HandleMap.h.

template<class T >
typedef std::shared_ptr<HandleMap<T> > opencog::HandleMap< T >::MapPtr

Definition at line 78 of file HandleMap.h.

Constructor & Destructor Documentation

template<class T >
opencog::HandleMap< T >::HandleMap ( )
inline

Definition at line 79 of file HandleMap.h.

Member Function Documentation

template<class T >
void opencog::HandleMap< T >::add ( Handle  key,
element 
)
throw (RuntimeException
)
inline

Adds a new entry to the hash table.

Parameters
Key.
Element.

Definition at line 87 of file HandleMap.h.

References opencog::HandleMap< T >::_handle_map, and opencog::HandleMap< T >::_mtx.

template<class T >
bool opencog::HandleMap< T >::contains ( Handle  key)
inline

Checks if there exists an element for the given key.

Parameters
Key.
Returns
Whether there exists an element for the given key.

Definition at line 131 of file HandleMap.h.

References opencog::HandleMap< T >::_handle_map, and opencog::HandleMap< T >::_mtx.

template<class T >
T opencog::HandleMap< T >::get ( Handle  key)
inline

Returns the element for a given key.

Parameters
Key.
Returns
Element for a given key.

Definition at line 109 of file HandleMap.h.

References opencog::HandleMap< T >::_handle_map, and opencog::HandleMap< T >::_mtx.

template<class T >
int opencog::HandleMap< T >::get_count ( )
inline

Returns the total number of elements in the hash table.

Returns
Total number of elements in the hash table.

Definition at line 175 of file HandleMap.h.

References opencog::HandleMap< T >::_handle_map, and opencog::HandleMap< T >::_mtx.

template<class T >
int opencog::HandleMap< T >::get_size ( )
inline

Returns the size of the hash table (number of possible collision lists). XXX No not any more XXX.

Returns
Size of the hash table (number of possible collision lists).

Definition at line 187 of file HandleMap.h.

References opencog::HandleMap< T >::_handle_map, and opencog::HandleMap< T >::_mtx.

template<class T >
HandleMapIterator<T>* opencog::HandleMap< T >::keys ( )
inline

Returns an iterator through all keys stored in the hash table.

Returns
An iterator through all keys stored in the hash table.

Definition at line 200 of file HandleMap.h.

template<class T >
T opencog::HandleMap< T >::remove ( Handle  key)
inline

Removes an element referred by a given key from the table and returns it.

Parameters
Key.
Returns
Removed element.

Definition at line 144 of file HandleMap.h.

References opencog::HandleMap< T >::_handle_map, and opencog::HandleMap< T >::_mtx.

template<class T >
void opencog::HandleMap< T >::resize ( int  newSize)
inline

Changes the size of the hash table to at least a new size.

Parameters
Newsize for the hash table.

Definition at line 164 of file HandleMap.h.

References opencog::HandleMap< T >::_handle_map, and opencog::HandleMap< T >::_mtx.

Friends And Related Function Documentation

template<class T >
friend class HandleMapIterator< T >
friend

Definition at line 56 of file HandleMap.h.

Member Data Documentation

template<class T >
InternalMap opencog::HandleMap< T >::_handle_map
private

The Map where the elements will be stored.

Definition at line 69 of file HandleMap.h.

template<class T >
std::mutex opencog::HandleMap< T >::_mtx
private

The mutex used to control access to the HashMap.

Definition at line 74 of file HandleMap.h.


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