FreeNOS
Data Structures | Public Member Functions | Private Attributes
HashTable< K, V > Class Template Reference

Efficient key -> value lookups. More...

#include <HashTable.h>

Inheritance diagram for HashTable< K, V >:
Associative< K, V > Container Comparable< Associative< K, V > >

Data Structures

class  Bucket
 Describes a bucket in the HashTable, for collision avoidance. More...
 

Public Member Functions

 HashTable (Size size=HASHTABLE_DEFAULT_SIZE)
 Class constructor. More...
 
virtual bool insert (const K &key, const V &value)
 Inserts the given item to the HashTable. More...
 
virtual bool append (const K &key, const V &value)
 Append a new item. More...
 
virtual int remove (const K &key)
 Remove value(s) for the given key. More...
 
virtual Size size () const
 Get the size of the HashTable. More...
 
virtual Size count () const
 Get the number of values stored in the HashTable. More...
 
virtual List< K > keys () const
 Retrieve all keys inside the Association. More...
 
virtual List< K > keys (const V &value) const
 Retrieve list of Keys for the given value. More...
 
virtual List< V > values () const
 Retrieve all values inside the Association. More...
 
virtual List< V > values (const K &key) const
 Retrieve values for the given key inside the Association. More...
 
virtual const V * get (const K &key) const
 Returns the first value for the given key. More...
 
virtual const V & at (const K &key) const
 Returns a reference to the first value for the given key. More...
 
virtual const V value (const K &key, const V defaultValue=V()) const
 Return the first value for the given key. More...
 
Vector< List< Bucket > > & table ()
 Get the internal Vector with Buckets. More...
 
V & operator[] (const K &key)
 Modifiable index operator. More...
 
const V & operator[] (const K &key) const
 Constant index operator. More...
 
- Public Member Functions inherited from Associative< K, V >
virtual void clear ()
 Removes all items from the Association. More...
 
virtual bool contains (const K &key) const
 Check if the given key exists. More...
 
virtual int compareTo (const Associative< K, V > &a) const
 Compare this instance to another instance. More...
 
virtual bool equals (const Associative< K, V > &a) const
 Test if an Associative is equal to an other Associative. More...
 
const V & operator[] (K key) const
 Returns the first value for the given key. More...
 
- Public Member Functions inherited from Container
 Container ()
 Constructor. More...
 
virtual ~Container ()
 Destructor. More...
 
virtual bool isEmpty () const
 Check if the Container is empty. More...
 
virtual bool reserve (Size size)
 Ensure that at least the given size is available. More...
 
virtual bool shrink (Size size)
 Shrink the container size by the given amount of items. More...
 
virtual Size squeeze ()
 Try to minimize the memory required in the Container. More...
 
virtual bool resize (Size size)
 Change the size of the Container. More...
 
- Public Member Functions inherited from Comparable< Associative< K, V > >
virtual ~Comparable ()
 Class destructor. More...
 

Private Attributes

Vector< List< Bucket > > m_table
 Internal table. More...
 
Size m_count
 Number of values in the buckets. More...
 

Detailed Description

template<class K, class V>
class HashTable< K, V >

Efficient key -> value lookups.

Definition at line 44 of file HashTable.h.

Constructor & Destructor Documentation

◆ HashTable()

template<class K , class V >
HashTable< K, V >::HashTable ( Size  size = HASHTABLE_DEFAULT_SIZE)
inline

Class constructor.

Parameters
sizeInitial size of the internal table.

Definition at line 111 of file HashTable.h.

Member Function Documentation

◆ append()

template<class K , class V >
virtual bool HashTable< K, V >::append ( const K &  key,
const V &  value 
)
inlinevirtual

Append a new item.

Parameters
keyAssociated key.
valueNew item to append.
Returns
True if append successfull, false otherwise.

Reimplemented from Associative< K, V >.

Definition at line 162 of file HashTable.h.

◆ at()

template<class K , class V >
virtual const V& HashTable< K, V >::at ( const K &  key) const
inlinevirtual

Returns a reference to the first value for the given key.

Parameters
keyKey to find.
Returns
Reference to the first value for the key.
Note
This function assumes the key exists.

Implements Associative< K, V >.

Definition at line 307 of file HashTable.h.

Referenced by HashTable< String, FileCache * >::operator[]().

◆ count()

template<class K , class V >
virtual Size HashTable< K, V >::count ( ) const
inlinevirtual

Get the number of values stored in the HashTable.

Returns
Number of items in the HashTable.

Implements Container.

Definition at line 211 of file HashTable.h.

Referenced by FileSystemServer::clearFileCache(), ArgumentParser::getUsage(), and FileSystemServer::unregisterFile().

◆ get()

template<class K , class V >
virtual const V* HashTable< K, V >::get ( const K &  key) const
inlinevirtual

Returns the first value for the given key.

Parameters
keyKey to find.
Returns
Pointer to the first value for the given key or ZERO if not found.

Implements Associative< K, V >.

Definition at line 287 of file HashTable.h.

Referenced by ArgumentContainer::get(), DatastoreServer::getBufferTable(), Shell::getCommand(), ChannelRegistry::getConsumer(), FileSystemServer::getNextInode(), ChannelRegistry::getProducer(), FileSystemServer::inodeHandler(), ArgumentParser::parse(), UDP::process(), DatastoreServer::registerBuffer(), and FileSystemServer::waitFileHandler().

◆ insert()

template<class K , class V >
virtual bool HashTable< K, V >::insert ( const K &  key,
const V &  value 
)
inlinevirtual

Inserts the given item to the HashTable.

If an item exists for the given key, its value will be replaced.

Parameters
keyThe associated key for the given item to use.
valueThe item to insert
Returns
bool Whether inserting the item at the given position succeeded.

Reimplemented from Associative< K, V >.

Definition at line 133 of file HashTable.h.

Referenced by ArgumentContainer::addFlag(), UDP::bind(), FileCache::FileCache(), DatastoreServer::getBufferTable(), LinnFileSystem::getInode(), FileSystemServer::insertFileCache(), FileSystemServer::lookupFile(), DatastoreServer::registerBuffer(), Shell::registerCommand(), ChannelRegistry::registerConsumer(), ArgumentParser::registerFlag(), and ChannelRegistry::registerProducer().

◆ keys() [1/2]

template<class K , class V >
virtual List<K> HashTable< K, V >::keys ( ) const
inlinevirtual

Retrieve all keys inside the Association.

Returns
A List of keys.

Implements Associative< K, V >.

Definition at line 221 of file HashTable.h.

◆ keys() [2/2]

template<class K , class V >
virtual List<K> HashTable< K, V >::keys ( const V &  value) const
inlinevirtual

Retrieve list of Keys for the given value.

Implements Associative< K, V >.

Definition at line 236 of file HashTable.h.

◆ operator[]() [1/2]

template<class K , class V >
V& HashTable< K, V >::operator[] ( const K &  key)
inline

Modifiable index operator.

Definition at line 349 of file HashTable.h.

◆ operator[]() [2/2]

template<class K , class V >
const V& HashTable< K, V >::operator[] ( const K &  key) const
inline

Constant index operator.

Definition at line 357 of file HashTable.h.

◆ remove()

template<class K , class V >
virtual int HashTable< K, V >::remove ( const K &  key)
inlinevirtual

Remove value(s) for the given key.

Parameters
keyAssociated key.
Returns
Number of values removed.

Reimplemented from Associative< K, V >.

Definition at line 178 of file HashTable.h.

Referenced by FileSystemServer::clearFileCache(), ChannelRegistry::unregisterConsumer(), and ChannelRegistry::unregisterProducer().

◆ size()

template<class K , class V >
virtual Size HashTable< K, V >::size ( ) const
inlinevirtual

Get the size of the HashTable.

Returns
Size of the internal array.

Implements Container.

Definition at line 201 of file HashTable.h.

Referenced by HashTable< String, FileCache * >::HashTable().

◆ table()

template<class K , class V >
Vector<List<Bucket> >& HashTable< K, V >::table ( )
inline

Get the internal Vector with Buckets.

Returns
Reference to the Vector with Buckets.

Definition at line 341 of file HashTable.h.

◆ value()

template<class K , class V >
virtual const V HashTable< K, V >::value ( const K &  key,
const V  defaultValue = V() 
) const
inlinevirtual

Return the first value for the given key.

If the key is not found, the default value is returned.

Returns
First value for the given key, or the defaultValue.

Implements Associative< K, V >.

Definition at line 325 of file HashTable.h.

Referenced by HashTable< String, FileCache * >::append(), FileSystemServer::findFileCache(), LinnFileSystem::getInode(), HashTable< String, FileCache * >::insert(), HashTable< String, FileCache * >::keys(), and FileSystemServer::lookupFile().

◆ values() [1/2]

template<class K , class V >
virtual List<V> HashTable< K, V >::values ( ) const
inlinevirtual

Retrieve all values inside the Association.

Returns
A List of values.

Implements Associative< K, V >.

Definition at line 253 of file HashTable.h.

◆ values() [2/2]

template<class K , class V >
virtual List<V> HashTable< K, V >::values ( const K &  key) const
inlinevirtual

Retrieve values for the given key inside the Association.

Returns
A List of values.

Implements Associative< K, V >.

Definition at line 269 of file HashTable.h.

Field Documentation

◆ m_count

template<class K , class V >
Size HashTable< K, V >::m_count
private

◆ m_table

template<class K , class V >
Vector<List<Bucket> > HashTable< K, V >::m_table
private

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