Go to the documentation of this file.
18 #ifndef __LIB_LIBSTD_HASHTABLE_H
19 #define __LIB_LIBSTD_HASHTABLE_H
31 #define HASHTABLE_DEFAULT_SIZE 64
141 if (i.current().key == key)
143 i.current().value =
value;
184 if (i.current().key == key)
228 lst << j.current().key;
242 if (j.current().value ==
value && !lst.
contains(j.current().key))
243 lst << j.current().key;
259 lst << j.current().value;
274 if (i.current().key == key)
275 lst << i.current().value;
287 virtual const V *
get(
const K & key)
const
292 if (i.current().key == key)
293 return &i.current().value;
307 virtual const V &
at(
const K & key)
const
312 if (i.current().key == key)
313 return i.current().value;
315 return m_table[0].head()->data.value;
325 virtual const V
value(
const K & key,
const V defaultValue = V())
const
330 if (i.current().key == key)
331 return i.current().value;
351 return (V &)
at(key);
359 return (
const V &)
at(key);
bool operator==(const Bucket &b) const
Comparision operator.
virtual List< V > values(const K &key) const
Retrieve values for the given key inside the Association.
Efficient key -> value lookups.
V value
Value of the item.
const V & operator[](const K &key) const
Constant index operator.
virtual List< K > keys(const V &value) const
Retrieve list of Keys for the given value.
Size hash(const String &key, Size mod)
Compute a hash using the FNV algorithm.
Bucket(K k, V v)
Constructor.
virtual bool append(const K &key, const V &value)
Append a new item.
virtual List< K > keys() const
Retrieve all keys inside the Association.
virtual const V & at(const K &key) const
Returns a reference to the first value for the given key.
#define HASHTABLE_DEFAULT_SIZE
Default size of the HashTable internal table.
Describes a bucket in the HashTable, for collision avoidance.
V & operator[](const K &key)
Modifiable index operator.
virtual int remove(const K &key)
Remove value(s) for the given key.
virtual bool hasCurrent() const
Check if there is a current item on the List.
virtual const V * get(const K &key) const
Returns the first value for the given key.
virtual Size count() const
Get the number of values stored in the HashTable.
Bucket(const Bucket &b)
Copy constructor.
unsigned int Size
Any sane size indicator cannot go negative.
virtual List< V > values() const
Retrieve all values inside the Association.
bool operator!=(const Bucket &b) const
Inequality operator.
Bucket()
Default constructor.
HashTable(Size size=HASHTABLE_DEFAULT_SIZE)
Class constructor.
Vector< List< Bucket > > m_table
Internal table.
#define assert(exp)
Insert program diagnostics.
Vector< List< Bucket > > & table()
Get the internal Vector with Buckets.
Associatives are containers that provide a mapping of keys to values.
Size m_count
Number of values in the buckets.
virtual bool contains(const T t) const
Check whether an element is on the List.
Simple linked list template class.
virtual Size size() const
Get the size of the HashTable.
Vectors are dynamically resizeable Arrays.
virtual bool insert(const K &key, const V &value)
Inserts the given item to the HashTable.
virtual const V value(const K &key, const V defaultValue=V()) const
Return the first value for the given key.