OpenTTD
|
Public Member Functions | |
void | Init (Hash_HashProc *hash, uint num_buckets) |
Builds a new hash in an existing struct. | |
void * | Get (uint key1, uint key2) const |
Gets the value associated with the given key pair, or NULL when it is not present. | |
void * | Set (uint key1, uint key2, void *value) |
Sets the value associated with the given key pair to the given value. | |
void * | DeleteValue (uint key1, uint key2) |
Deletes the value with the specified key pair from the hash and returns that value. | |
void | Clear (bool free_values) |
Cleans the hash, but keeps the memory allocated. | |
void | Delete (bool free_values) |
Deletes the hash and cleans up. | |
uint | GetSize () const |
Gets the current size of the hash. |
Data Fields | |
Hash_HashProc * | hash |
uint | size |
uint | num_buckets |
HashNode * | buckets |
bool * | buckets_in_use |
Protected Member Functions | |
HashNode * | FindNode (uint key1, uint key2, HashNode **prev_out) const |
Finds the node that that saves this key pair. |
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 255 of file queue.cpp.
References free().
Referenced by AyStar::Free().
void * Hash::DeleteValue | ( | uint | key1, |
uint | key2 | ||
) |
Deletes the value with the specified key pair from the hash and returns that value.
Returns NULL when the value was not present. The value returned is not free()'d!
Definition at line 411 of file queue.cpp.
References FindNode(), and free().
Referenced by AyStar::OpenListPop().
Finds the node that that saves this key pair.
If it is not found, returns NULL. 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 NULL. If it is not found, *prev is set to the last HashNode in the bucket, or NULL if it is empty. prev can also be NULL, in which case it is not used for output.
Definition at line 374 of file queue.cpp.
Referenced by DeleteValue(), Get(), and Set().
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 234 of file queue.cpp.
References CheckAllocationConstraints().
Referenced by AyStar::Init().
void * Hash::Set | ( | uint | key1, |
uint | key2, | ||
void * | value | ||
) |
Sets the value associated with the given key pair to the given value.
Returns the old value if the value was replaced, NULL when it was not yet present.
Definition at line 454 of file queue.cpp.
References FindNode().
Referenced by AyStar::ClosedListAdd(), and AyStar::OpenListAdd().