# queue.cpp File Reference

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "queue.h"`
`#include "core/alloc_func.hpp"`

Go to the source code of this file.

## Defines
#define | BINARY_HEAP_BLOCKSIZE (1 << BINARY_HEAP_BLOCKSIZE_BITS)
#define | BINARY_HEAP_BLOCKSIZE_MASK (BINARY_HEAP_BLOCKSIZE - 1)
#define | BIN_HEAP_ARR(i) q->data.binaryheap.elements[((i) - 1) >> BINARY_HEAP_BLOCKSIZE_BITS][((i) - 1) & BINARY_HEAP_BLOCKSIZE_MASK]
## Functions
static void | InsSort_Clear (Queue *q, bool free_values)
static void | InsSort_Free (Queue *q, bool free_values)
static bool | InsSort_Push (Queue *q, void *item, int priority)
static void * | InsSort_Pop (Queue *q)
static bool | InsSort_Delete (Queue *q, void *item, int priority)
void | init_InsSort (Queue *q)
| Insertion Sorter.
static void | BinaryHeap_Clear (Queue *q, bool free_values)
static void | BinaryHeap_Free (Queue *q, bool free_values)
static bool | BinaryHeap_Push (Queue *q, void *item, int priority)
static bool | BinaryHeap_Delete (Queue *q, void *item, int priority)
static void * | BinaryHeap_Pop (Queue *q)
void | init_BinaryHeap (Queue *q, uint max_size)
| Initializes a binary heap and allocates internal memory for maximum of max_size elements.
void | init_Hash (Hash *h, Hash_HashProc *hash, uint num_buckets)
| Builds a new hash in an existing struct.
void | delete_Hash (Hash *h, bool free_values)
| Deletes the hash and cleans up.
void | clear_Hash (Hash *h, bool free_values)
| Cleans the hash, but keeps the memory allocated.
static HashNode * | Hash_FindNode (const Hash *h, uint key1, uint key2, HashNode **prev_out)
| Finds the node that that saves this key pair.
void * | Hash_Delete (Hash *h, uint key1, uint key2)
| Deletes the value with the specified key pair from the hash and returns that value.
void * | Hash_Set (Hash *h, uint key1, uint key2, void *value)
| Sets the value associated with the given key pair to the given value.
void * | Hash_Get (const Hash *h, uint key1, uint key2)
| Gets the value associated with the given key pair, or NULL when it is not present.
uint | Hash_Size (const Hash *h)
| Gets the current size of the Hash.

## Detailed Description

Definition in file queue.cpp.

## Function Documentation

void delete_Hash | ( | Hash * | h,
|  | 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 322 of file queue.cpp.

void* Hash_Delete | ( | Hash * | h,
|  | 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 484 of file queue.cpp.

References Hash_FindNode().

static HashNode* Hash_FindNode | ( | const Hash * | h,
|  | uint | key1,
|  | uint | key2,
|  | HashNode ** | prev_out |
| ) |  |  | `[static]`

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 440 of file queue.cpp.

Referenced by Hash_Delete(), Hash_Get(), and Hash_Set().

void* Hash_Get | ( | const Hash * | h,
|  | uint | key1,
|  | uint | key2 |
| ) |  |  |

Gets the value associated with the given key pair, or NULL when it is not present.

Definition at line 559 of file queue.cpp.

References Hash_FindNode().

void* Hash_Set | ( | Hash * | h,
|  | 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 528 of file queue.cpp.

References Hash_FindNode().

void init_Hash | ( | Hash * | h,
|  | 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 301 of file queue.cpp.