Header:
plang/factor/hash_.hpp
Class:
hash_ : factor

    hash is built-in data type represents hash table. In C++ code boost::shared_ptr<hash_> is class corresponding to hash.
hash has hash table data type member named h which holds keys and values of that object.

Members
h
hash table

Methods

constructors

hash()

hash(hash& x)
operators


hash& operator =(hash& x)
methods


bool empty()

unsigned int size()

nil clear()

T1& at(T2& key)

bool exist(T& key)

bool erase(T& key)

nil swap(hash& x)

bool insert(T1& key, T2& value)

hash()
default constructor, set empty hash table

effects
h=hash_table()


hash(hash& x)
copy constructor, deepcopy hash table x.h

parameters
hash& x - copy this

effects
deepcopy(x)


hash& operator =(hash& x)
deepcopy hash table x.h

parameters
hash& x - copy this

effects
deepcopy(x)


bool empty()
test if hash table is empty, i.e. whether size() is 0

returns
h.empty()


unsigned int size()
get number of elements in hash table h

returns
h.size()


nil clear()
destroy all elements in hash table h

effects
h=hash_table()


template<class T1, class T2> T1& at(T2 key)
get value associated with key

parameters
T2 key
identifying value

returns
h.at(key)

exceptions
range_error - if !exist(key)


template<class T> bool exist(T key)
test if hash key key exists in hash table h

parameters
T key - identifying value

returns
h.exist(key)


template<class T> bool erase(T key)
erase value associated with key

parameters
T key - identifying value

effects
remove h[key] from h

returns
return true if h[key] is successfully removed, false otherwise


nil swap(hash& x)
swap h with x.h

parameters
hash& x - object to be swapped

effects
h.swap(x.h)


template<class T1, class T2> bool insert(T1 key, T2 value)
insert new elements (copyof(key), copyof(value)) into h

parameters
T1 key - new hash key
T2 value - new hash value

effects
insert (key.clone(), value.clone()) into h if !exist(key)

returns
return true if (key.clone(), value.clone()) is successfully inserted, false otherwise