OpenTTD Source: CHashTableT< Titem_, Thash_bits_ > Class Template Reference

OpenTTD Source 14.0-beta3

Public Types | Public Member Functions | Static Public Attributes | Protected Types | Static Protected Member Functions | Protected Attributes
CHashTableT< Titem_, Thash_bits_ > Class Template Reference

class CHashTableT<Titem, Thash_bits> - simple hash table of pointers allocated elsewhere. More...

`#include <hashtable.hpp>`

## Public Types
typedef Titem_ | Titem
typedef Titem_::Key | Tkey

## Public Member Functions
int | Count () const
| item count
void | Clear ()
| simple clear - forget all items - used by CSegmentCostCacheT.Flush()
const Titem_ * | Find (const Tkey &key) const
| const item search
Titem_ * | Find (const Tkey &key)
| non-const item search
Titem_ * | TryPop (const Tkey &key)
| non-const item search & optional removal (if found)
Titem_ & | Pop (const Tkey &key)
| non-const item search & removal
bool | TryPop (Titem_ &item)
| non-const item search & optional removal (if found)
void | Pop (Titem_ &item)
| non-const item search & removal
void | Push (Titem_ &new_item)
| add one item - copy it from the given item

## Static Public Attributes
static const int | Thash_bits = Thash_bits_
static const int | Tcapacity = 1 << Thash_bits

## Protected Types
typedef CHashTableSlotT< Titem_ > | Slot
| each slot contains pointer to the first item in the list, Titem contains pointer to the next item - GetHashNext(), SetHashNext()

## Static Protected Member Functions
static int | CalcHash (const Tkey &key)
| static helper - return hash for the given key modulo number of slots
static int | CalcHash (const Titem_ &item)
| static helper - return hash for the given item modulo number of slots

## Protected Attributes
Slot | m_slots [Tcapacity]
int | m_num_items

## Detailed Description

### template<class Titem_, int Thash_bits_>
class CHashTableT< Titem_, Thash_bits_ >

class CHashTableT<Titem, Thash_bits> - simple hash table of pointers allocated elsewhere.

Supports: Add/Find/Remove of Titems.

Your Titem must meet some extra requirements to be CHashTableT compliant:

- its constructor/destructor (if any) must be public
- if the copying of item requires an extra resource management, you must define also copy constructor
- must support nested type (struct, class or typedef) Titem::Key that defines the type of key class for that item
- must support public method: const Key& GetKey() const; // return the item's key object

In addition, the Titem::Key class must support:

- public method that calculates key's hash: int CalcHash() const;
- public 'equality' operator to compare the key with another one bool operator==(const Key &other) const;

Definition at line 135 of file hashtable.hpp.

The documentation for this class was generated from the following file:

- src/misc/hashtable.hpp