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;
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);
#define HASHTABLE_DEFAULT_SIZE
Default size of the HashTable internal table.
Associatives are containers that provide a mapping of keys to values.
Describes a bucket in the HashTable, for collision avoidance.
Bucket(const Bucket &b)
Copy constructor.
V value
Value of the item.
Bucket(K k, V v)
Constructor.
Bucket()
Default constructor.
bool operator!=(const Bucket &b) const
Inequality operator.
bool operator==(const Bucket &b) const
Comparision operator.
Efficient key -> value lookups.
virtual const V value(const K &key, const V defaultValue=V()) const
Return the first value for the given key.
virtual int remove(const K &key)
Remove value(s) for the given key.
virtual List< K > keys(const V &value) const
Retrieve list of Keys for the given value.
HashTable(Size size=HASHTABLE_DEFAULT_SIZE)
Class constructor.
Vector< List< Bucket > > & table()
Get the internal Vector with Buckets.
virtual const V & at(const K &key) const
Returns a reference to the first value for the given key.
Size m_count
Number of values in the buckets.
virtual List< V > values(const K &key) const
Retrieve values for the given key inside the Association.
const V & operator[](const K &key) const
Constant index operator.
virtual const V * get(const K &key) const
Returns the first value for the given key.
virtual List< K > keys() const
Retrieve all keys inside the Association.
virtual Size size() const
Get the size of the HashTable.
virtual Size count() const
Get the number of values stored in the HashTable.
virtual bool insert(const K &key, const V &value)
Inserts the given item to the HashTable.
V & operator[](const K &key)
Modifiable index operator.
virtual List< V > values() const
Retrieve all values inside the Association.
virtual bool append(const K &key, const V &value)
Append a new item.
Vector< List< Bucket > > m_table
Internal table.
virtual bool hasCurrent() const
Check if there is a current item on the List.
Simple linked list template class.
Node * head()
Get the first Node on the list.
virtual bool contains(const T t) const
Check whether an element is on the List.
Vectors are dynamically resizeable Arrays.
#define assert(exp)
Insert program diagnostics.
Size hash(const String &key, Size mod)
Compute a hash using the FNV algorithm.
unsigned int Size
Any sane size indicator cannot go negative.