quick start:g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_system.a #include <SysHeap.h> boolean insert(void* ptr); boolean extractMax(void*& ptr); boolean extract(void* ptr); boolean build();
description:// declare a heap object // SysHeap heap; // set the length of heap // heap.setLength(10); // give values to heap // heap.data_d[0] = (void*)8; heap.data_d[1] = (void*)14; heap.data_d[2] = (void*)7; heap.data_d[3] = (void*)11; heap.data_d[4] = (void*)10; heap.data_d[5] = (void*)1; heap.data_d[6] = (void*)4; heap.data_d[7] = (void*)2; heap.data_d[8] = (void*)3; heap.data_d[9] = (void*)9; // declare a pointer // void* ptr_ins; // insert this pointer into heap // ptr_ins = (void*)12; heap.insert(ptr_ins);
Parent (i) = i / 2A good tutorial on heaps can be found at :
Left Child (i) = 2 * i + 1
Right Child (i) = 2 * i + 2
static const unichar CLASS_NAME[] = L"SysHeap";
static const long DEF_NUM_ELEMENTS = 0;
static const long DEF_CAPACITY = 0;
static const long DEF_GROW_FACTOR = 2;
static const long ERR = 1700;
static const long ERR_HEMPTY = 1701;
static const long ERR_INVPTR = 1702;
void** data_d;
long capacity_d;
long num_elements_d;
long grow_factor_d;
Integral::DEBUG debug_level_d;
static const SysString& name();
static boolean diagnose(Integral::DEBUG debug_level);
static boolean setDebug(Integral::DEBUG debug_level);
boolean debug(const unichar* message);
~SysHeap();
SysHeap();
these methods are omitted because SysHeap cannot be duplicated
these methods are omitted because SysHeap cannot be duplicated
these methods are omitted because SysHeap can not write itself to an sof file
boolean eq(const SysHeap& arg);
new and delete are omitted because memory for SysHeap objects is not managed by the MemoryManager class
boolean clear(Integral::CMODE ctype_a = Integral::DEF_CMODE);
boolean build();
boolean isEmpty() const;
long length() const;
boolean insert(void* ptr);
long find(void* ptr, long start_index = 0) const;
boolean extractMax(void*& ptr);
boolean extract(void* ptr);
boolean extract(void* ptr, long pos);
boolean setLength(long len);
boolean setCapacity(long cap);
boolean setGrow(long grow_factor);
SysHeap(const SysHeap& arg);
boolean heapify(long index);
boolean bubbleUp(long index);
boolean parent(long index) const;
boolean left(long index) const;
boolean right(long index) const;
// declare heap object // SysHeap heap; // set the length of the heap // heap.setLength(5); // give values to heap // heap.data_d[0] = (void*)8; heap.data_d[1] = (void*)14; heap.data_d[2] = (void*)7; heap.data_d[3] = (void*)11; heap.data_d[4] = (void*)10; // build the heap // heap.build();
// insertion of a pointer in the heap // void* ptr0; ptr0 = (void*)15; heap.insert(ptr0); // extract the maximum pointer from the heap // void* ptr_ext_max; heap.extractMax(ptr_ext_max); // extract a pointer from the heap // void* ptr1; ptr1 = (void*)11; heap.extract(ptr1);