# queue.h File Reference

Simple Queue/Hash implementations. More...

Go to the source code of this file.

## Data Structures

struct | InsSortNode
struct | BinaryHeapNode
struct | Queue
struct | HashNode
struct | Hash

## Defines

#define | BINARY_HEAP_BLOCKSIZE_BITS 10

## Typedefs

typedef bool | Queue_PushProc (Queue *q, void *item, int priority)
typedef void * | Queue_PopProc (Queue *q)
typedef bool | Queue_DeleteProc (Queue *q, void *item, int priority)
typedef void | Queue_ClearProc (Queue *q, bool free_values)
typedef void | Queue_FreeProc (Queue *q, bool free_values)
typedef uint | Hash_HashProc (uint key1, uint key2)
| Generates a hash code from the given key pair.

## Functions

void | init_InsSort (Queue *q)
| Insertion Sorter.
void | init_BinaryHeap (Queue *q, uint max_size)
| Initializes a binary heap and allocates internal memory for maximum of max_size elements.
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.
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.
uint | Hash_Size (const Hash *h)
| Gets the current size of the Hash.

## Detailed Description

Simple Queue/Hash implementations.

Definition in file queue.h.

## Typedef Documentation

typedef uint Hash_HashProc(uint key1, uint key2)

Generates a hash code from the given key pair.

You should make sure that the resulting range is clearly defined.

Definition at line 112 of file queue.h.

## 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 320 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 482 of file queue.cpp.

References Hash_FindNode().

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 557 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 526 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 299 of file queue.cpp.