Poco

template < class Key, class Value, class KeyHashFunction = HashFunction < Key >>

class HashTable

Library: Foundation
Package: Hashing
Header: Poco/HashTable.h

Deprecated. This class is deprecated and should no longer be used.

Description

A HashTable stores a key value pair that can be looked up via a hashed key.

Collision handling is done via overflow maps(!). With small hash tables performance of this data struct will be closer to that a map than a hash table, i.e. slower. On the plus side, this class offers remove operations. Also HashTable full errors are not possible. If a fast HashTable implementation is needed and the remove operation is not required, use SimpleHashTable instead.

This class is NOT thread safe.

Member Summary

Member Functions: clear, currentState, exists, existsRaw, get, getKeyRaw, getRaw, hash, insert, insertRaw, maxCapacity, operator =, operator [], remove, removeRaw, resize, size, update, updateRaw

Types

ConstIterator

typedef typename HashEntryMap::const_iterator ConstIterator;

HashEntryMap

typedef std::map < Key, Value > HashEntryMap;

HashTableVector

typedef HashEntryMap * * HashTableVector;

Iterator

typedef typename HashEntryMap::iterator Iterator;

Constructors

HashTable inline

HashTable(
    UInt32 initialSize = 251
);

Creates the HashTable.

HashTable inline

HashTable(
    const HashTable & ht
);

Destructor

~HashTable inline

~HashTable();

Destroys the HashTable.

Member Functions

clear inline

void clear();

currentState inline

HashStatistic currentState(
    bool details = false
) const;

Returns the current internal state

exists inline

bool exists(
    const Key & key
);

existsRaw inline

bool existsRaw(
    const Key & key,
    UInt32 hsh
);

get inline

const Value & get(
    const Key & key
) const;

Throws an exception if the value does not exist

get inline

Value & get(
    const Key & key
);

Throws an exception if the value does not exist

get inline

bool get(
    const Key & key,
    Value & v
) const;

Sets v to the found value, returns false if no value was found

getKeyRaw inline

const Key & getKeyRaw(
    const Key & key,
    UInt32 hsh
);

Throws an exception if the key does not exist. returns a reference to the internally stored key. Useful when someone does an insert and wants for performance reason only to store a pointer to the key in another collection

getRaw inline

const Value & getRaw(
    const Key & key,
    UInt32 hsh
) const;

Throws an exception if the value does not exist

getRaw inline

bool getRaw(
    const Key & key,
    UInt32 hsh,
    Value & v
) const;

Sets v to the found value, returns false if no value was found

hash inline

UInt32 hash(
    const Key & key
) const;

insert inline

UInt32 insert(
    const Key & key,
    const Value & value
);

Returns the hash value of the inserted item. Throws an exception if the entry was already inserted

insertRaw inline

Value & insertRaw(
    const Key & key,
    UInt32 hsh,
    const Value & value
);

Returns the hash value of the inserted item. Throws an exception if the entry was already inserted

maxCapacity inline

UInt32 maxCapacity() const;

operator = inline

HashTable & operator = (
    const HashTable & ht
);

operator [] inline

const Value & operator[] (
    const Key & key
) const;

operator [] inline

Value & operator[] (
    const Key & key
);

remove inline

void remove(
    const Key & key
);

removeRaw inline

void removeRaw(
    const Key & key,
    UInt32 hsh
);

Performance version, allows to specify the hash value

resize inline

void resize(
    UInt32 newSize
);

Resizes the hashtable, rehashes all existing entries. Expensive!

size inline

std::size_t size() const;

Returns the number of elements already inserted into the HashTable

update inline

UInt32 update(
    const Key & key,
    const Value & value
);

Returns the hash value of the inserted item. Replaces an existing entry if it finds one

updateRaw inline

void updateRaw(
    const Key & key,
    UInt32 hsh,
    const Value & value
);

Returns the hash value of the inserted item. Replaces an existing entry if it finds one