/*--------------------------------------------------*/ Darray Darray_insert(Darray dar, int index, VOIDP data) { int l = Darray_len(dar); int source; if (index <= 0) Darray_addl(dar, data); else if (index >= l) Darray_addh(dar, data); else { Darray_addh(dar, NULL); for (source = l - 1; source >= index; source--) Darray_set(dar, source + 1, Darray_get(dar, source)); Darray_set(dar, index, data); } return dar; }
#include "tagger.h" void SetTagVal(Darray tagVal, Darray freeptrs, int count, char *val, int *first) { // Benjamin Han: add val for later destruction if (*first) {
void *Heap_pop_replace(Heap *heap, void *value) { void *root; assert(heap); root = Darray_get(heap->contents, 0); Darray_set(heap->contents, 0, value); Heap_sift_down(heap); return root; }
void *Heap_pop(Heap *heap) { void *oldRoot; void *last; assert(heap); oldRoot = Darray_get(heap->contents, 0); last = Darray_pop(heap->contents); Darray_set(heap->contents, 0, last); Heap_sift_down(heap); return oldRoot; }
Darray Darray_remove(Darray dar, int index) { int s, d, l; l = Darray_len(dar); if (index == (l - 1)) { Darray_remh(dar); return dar; } if (index == 0) { Darray_reml(dar); return dar; } s = index + 1; d = index; while (s < l) { Darray_set(dar, d, (VOIDP)Darray_get(dar, s)); s++; d++; } Darray_remh(dar); return dar; }
static inline void Heap_set(Heap *heap, int index, void *value) { Darray_set(heap->contents, index, value); }