Class DictBase.

Inherits Garbage. Inherited by Dict.

The DictBase class is the foundation for Dict.

It has no own API, it merely provides the member functions used in Dict. Dict, as befits a template, has only small, inline members. Whenever something big is required, Dict calls a DictBase function.

DictBase::DictBase( uint size )

Constructs an empty dictionary optimsed for up to size items. The dictionary will be really fast up to around size items, then it grows slower.

void DictBase::clear()

Empties this Dict object. The referenced objects are not deleted, merely forgotten.

bool DictBase::contains( const String & s ) const

Returns true only if the Dict contains the key s.

void * DictBase::find( const String & s ) const

Returns a pointer to the object whose key is s, or a null pointer if there is no such object.

static uint DictBase::hash( const String & key )

Returns a 32-bit has of the string key. key is viewed as a series of numbers, so the algorithm can easily be used on either UString or String.

This code uses the algorithm djb described on comp.lang.c in 1990, message-id <>. contains a good overview of simple hash functions.

void DictBase::insert( const String & s, void* r )

Inserts r to the dictionary based on key s, replacing any previous object with key s.

The previous object is not deleted, merely removed from the dictionary.

bool DictBase::isEmpty() const

Returns true if empty, false if not.

StringList DictBase::keys() const

Returns a list of all the keys in this dictionary.

void DictBase::resize( uint size )

Changes the number of buckets in the dictionary to size, resorting all the contained objects. This function is necessarily slow.

void * DictBase::take( const String & s )

Removes the object with key s from the dictionary. The object is not deleted, merely removed from the dictionary.

If there is no such object, insert() does nothing.

This web page based on source code belonging to Oryx Mail Systems GmbH. All rights reserved.