void test_a(void) { bhp a; int i; void* v; a = mbh_new((void*)NULL, &mbh_compare_int); test_cycle(a); for (i = 0; i < 3; ++i) { mbh_insert(a, I2P(i)); } test_b(); i = mbh_size(a); if (i != 3) { ++g_fail; printf("Error: expected suspended heap to have size 3, got %d\n", i); } for (i = 0; i < 3; ++i) { v = mbh_shift(a); if (P2I(v) != i) { ++g_fail; printf("Error: heap a corrupted by heap b: expected %d, got %d\n", i, P2I(v)); } ++g_test; } }
void test_cycle(bhp h) { int i, j; void* v; i = mbh_size(h); if (i != 0) { ++g_fail; printf("Error: expected empty heap to have size 0, got %d\n", i); } ++g_test; for (i = 0; i < 100; ++i) { j = (i * 3) % 100; mbh_insert(h, I2P(j)); } i = mbh_size(h); if (i != 100) { ++g_fail; printf("Error: expected filled heap to have size 100, got %d\n", i); } ++g_test; for (i = 0; i < 100; ++i) { v = mbh_shift(h); if (P2I(v) != i) { ++g_fail; printf("Error: from mod 3 heap expected %d got %d\n", i, P2I(v)); } ++g_test; } i = mbh_size(h); if (i != 0) { ++g_fail; printf("Error: expected emptied heap to have size 0, got %d\n", i); } ++g_test; }
int mbh_compare_wr(void* context, void* left, void* right) { whp wh = P2I(context); walker* w = DWP(wh); wrhp wlh = P2I(left); wrhp wrh = P2I(right); walk_result* wl = DWRP(wh, wlh); walk_result* wr = DWRP(wh, wrh); return w->cmper(wr_next_discard(w, wl), wr_next_discard(w, wr)); }
int mbh_compare_int(void* context, void* left, void* right) { int il = P2I(left); int ir = P2I(right); return (il < ir) ? -1 : (il == ir) ? 0 : +1; }
int map_comp_int(const void *a, const void *b) { return P2I(a) - P2I(b); }
static inline walk_result* pop_heap(walker* w) { void* v = mbh_shift(w->heap); return DWRP(WHP(w), P2I(v)); }