36#define mutex_lock(m) (void)0
37#define mutex_unlock(m) (void)0
38#define mutex_trylock(m) (void)0
39#define mutex_init(m) ((m)=123456)
55#define Left(x) (2 * (x) + 1)
56#define Right(x) (2 * (x) + 2)
57#define Parent(x) ((int)((x)-1)/2)
59#define Threshold 10000
99 for (i = 0; i < hp->
last; i++) {
153 if (elm == lastNode) {
159 }
else if (hp->
last > 0) {
308 return (hp->
last <= 0) ? 1 : 0;
322 int left = 0, right = 0;
335 kid = hp->
nodes[left];
338 kid = hp->
nodes[right];
340 kid = hp->
nodes[left];
355 while (elm->
id > 0) {
357 if (parentNode->
key <= elm->
key)
370 int elm1Id = elm1->
id;
426 while (id < hp->
last) {
427 printf(
"%d\tKey = %.04f\n",
id, hp->
nodes[
id]->
key);
440 for (i = 0; i < hp->
last / 2; i++) {
449 printf(
"verifyHeap: violated at %d", i);
457#ifdef MEASURE_HEAP_SKEW
464compare_heap_keys(
const void *a,
const void *b)
468 float cmp = (*an)->
key - (*bn)->key;
486calc_heap_skew(
heap *
heap,
int replace)
489 long id, diff, skew = 0;
490#ifdef HEAP_DEBUG_SKEW
518 qsort(nodes,
max,
sizeof(
heap_node *), compare_heap_keys);
520 for (
id = 0;
id <
max;
id++) {
521 diff =
id - nodes[id]->
id;
524#ifdef HEAP_DEBUG_SKEW
525 skewsq += diff * diff;
527 printf(
"%d\tKey = %f, diff = %d\n",
id, nodes[
id]->key, diff);
540 for (
id = 0;
id <
max;
id++) {
556 norm = skew * 2.56 / (
max *
max);
A const & max(A const &lhs, A const &rhs)
heap_t heap_update(heap *hp, heap_node *elm, void *dat)
heap_t heap_delete(heap *hp, heap_node *elm)
heap_node * heap_insert(heap *hp, void *dat)
static void _heap_ify_down(heap *hp, heap_node *elm)
void * heap_peep(heap *hp, int n)
heap_key heap_peepminkey(heap *hp)
static void _heap_ify_up(heap *hp, heap_node *elm)
heap * new_heap(int initSize, heap_key_func gen_key)
heap_t heap_extractlast(heap *hp)
heap_key heap_peepkey(heap *hp, int n)
heap_key heap_gen_key(heap *hp, heap_t dat)
void * heap_peepmin(heap *hp)
static void heap_print_inorder(heap *hp, int id)
static void _heap_swap_element(heap *hp, heap_node *elm1, heap_node *elm2)
static int _heap_should_grow(heap *hp)
int verify_heap_property(heap *hp)
static void _heap_grow(heap *hp)
void delete_heap(heap *hp)
heap_t heap_extractmin(heap *hp)
static int _heap_node_exist(heap *hp, int id)
heap_key heap_key_func(heap_t, heap_key)
void * xrealloc(void *s, size_t sz)
void * xcalloc(size_t n, size_t sz)