hub/heap.c File Reference

#include "heap.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>

Include dependency graph for heap.c:

Go to the source code of this file.

Defines

#define VOID_PTR_COMPARE(x, y)   ((int)(x) - (int)(y))

Functions

HeapHeap_create ()
size_t Heap_add (Heap *heap, void *elem)
void Heap_resize (Heap *heap, size_t size)
size_t Heap_find (Heap *heap, void *elem)
int Heap_delete (Heap *heap, void *elem)
void Heap_destroy (Heap *heap)


Define Documentation

#define VOID_PTR_COMPARE ( x,
 )     ((int)(x) - (int)(y))

Definition at line 36 of file heap.c.

Referenced by Heap_add(), and Heap_find().


Function Documentation

size_t Heap_add ( Heap heap,
void *  elem 
)

Adds an element to the heap, returning its location. It will dynamically resize the allocated internal array if it needs.

Definition at line 38 of file heap.c.

References Heap_is_full, Heap_resize(), Heap::last, Heap::members, Heap::size, and VOID_PTR_COMPARE.

Referenced by Route_add_member().

Here is the call graph for this function:

Heap* Heap_create (  ) 

Creates a heap with an initial size of HEAP_SIZE.

Definition at line 23 of file heap.c.

References HEAP_SIZE, Heap::members, and Heap::size.

Referenced by Member_create(), Route_add_child(), and Route_create_root().

int Heap_delete ( Heap heap,
void *  elem 
)

Deletes the element from the heap, returning 0 if it wasn't in there or 1 if it was. It will reduce the size of the heap if there's a bunch of wasted space.

Definition at line 112 of file heap.c.

References Heap_find(), Heap_resize(), HEAP_SIZE, Heap_valid, Heap::last, Heap::members, and Heap::size.

Referenced by Route_unregister(), and Route_unregister_all().

Here is the call graph for this function:

void Heap_destroy ( Heap heap  ) 

Destroys the whole heap.

Definition at line 139 of file heap.c.

References Heap::members.

Referenced by Member_destroy(), Route_destroy(), and Route_destroy_children().

size_t Heap_find ( Heap heap,
void *  elem 
)

Finds the element in the Heap returning the location. If it returns something that is !Heap_valid(heap, at) then it wasn't found. This is also where a new element can be inserted.

Definition at line 81 of file heap.c.

References Heap::last, Heap::members, and VOID_PTR_COMPARE.

Referenced by Heap_delete().

void Heap_resize ( Heap heap,
size_t  size 
)

Resize a heap either up or down in size, size cannot be 0.

Definition at line 65 of file heap.c.

References Heap::members, and Heap::size.

Referenced by Heap_add(), and Heap_delete().


Generated on Tue Apr 10 01:00:40 2007 for Utu by  doxygen 1.5.1