OpenTTD Source  14.0-beta1
Hash Struct Reference

Public Member Functions

void Init (Hash_HashProc *hash, uint num_buckets)
 Builds a new hash in an existing struct. More...
 
void * Get (TileIndex tile, Trackdir dir) const
 Gets the value associated with the given key pair, or nullptr when it is not present.
 
void * Set (TileIndex tile, Trackdir dir, void *value)
 Sets the value associated with the given key pair to the given value. More...
 
void * DeleteValue (TileIndex tile, Trackdir dir)
 Deletes the value with the specified key pair from the hash and returns that value. More...
 
void Clear (bool free_values)
 Cleans the hash, but keeps the memory allocated.
 
void Delete (bool free_values)
 Deletes the hash and cleans up. More...
 
uint GetSize () const
 Gets the current size of the hash.
 

Data Fields

Hash_HashProchash
 
uint size
 
uint num_buckets
 
HashNodebuckets
 
bool * buckets_in_use
 

Protected Member Functions

HashNodeFindNode (TileIndex tile, Trackdir dir, HashNode **prev_out) const
 Finds the node that that saves this key pair. More...
 

Detailed Description

Definition at line 74 of file queue.h.

Member Function Documentation

◆ Delete()

void Hash::Delete ( bool  free_values)

Deletes the hash and cleans up.

Only cleans up memory allocated by new_Hash & friends. If free is true, it will call free() on all the values that are left in the hash.

Definition at line 253 of file queue.cpp.

References free().

Referenced by AyStar::Free().

◆ DeleteValue()

void * Hash::DeleteValue ( TileIndex  tile,
Trackdir  dir 
)

Deletes the value with the specified key pair from the hash and returns that value.

Returns nullptr when the value was not present. The value returned is not free()'d!

Definition at line 406 of file queue.cpp.

Referenced by AyStar::OpenListPop().

◆ FindNode()

HashNode * Hash::FindNode ( TileIndex  tile,
Trackdir  dir,
HashNode **  prev_out 
) const
protected

Finds the node that that saves this key pair.

If it is not found, returns nullptr. If it is found, *prev is set to the node before the one found, or if the node found was the first in the bucket to nullptr. If it is not found, *prev is set to the last HashNode in the bucket, or nullptr if it is empty. prev can also be nullptr, in which case it is not used for output.

Definition at line 369 of file queue.cpp.

Referenced by Get(), and Set().

◆ Init()

void Hash::Init ( Hash_HashProc hash,
uint  num_buckets 
)

Builds a new hash in an existing struct.

Make sure that hash() always returns a hash less than num_buckets! Call delete_hash after use

Definition at line 232 of file queue.cpp.

References CheckAllocationConstraints().

Referenced by AyStar::Init().

◆ Set()

void * Hash::Set ( TileIndex  tile,
Trackdir  dir,
void *  value 
)

Sets the value associated with the given key pair to the given value.

Returns the old value if the value was replaced, nullptr when it was not yet present.

Definition at line 449 of file queue.cpp.

References FindNode().

Referenced by AyStar::ClosedListAdd(), and AyStar::OpenListAdd().


The documentation for this struct was generated from the following files: