1#ifndef _inlineheap_h_INCLUDED
2#define _inlineheap_h_INCLUDED
11#define HEAP_CHILD(POS) (KISSAT_assert ((POS) < (1u << 31)), (2 * (POS) + 1))
13#define HEAP_PARENT(POS) (KISSAT_assert ((POS) > 0), (((POS) - 1) / 2))
19 unsigned idx_pos =
pos[idx];
21 const double idx_score = score[idx];
24 const unsigned parent = stack[parent_pos];
25 if (score[parent] >= idx_score)
27 LOG (
"heap bubble up: %u@%u = %g swapped with %u@%u = %g", parent,
28 parent_pos, score[parent], idx, idx_pos, idx_score);
29 stack[idx_pos] = parent;
30 pos[parent] = idx_pos;
45 unsigned idx_pos =
pos[idx];
47 const double idx_score = score[idx];
52 unsigned child = stack[child_pos];
53 double child_score = score[child];
54 const unsigned sibling_pos = child_pos + 1;
55 if (sibling_pos < end) {
56 const unsigned sibling = stack[sibling_pos];
57 const double sibling_score = score[sibling];
58 if (sibling_score > child_score) {
60 child_pos = sibling_pos;
61 child_score = sibling_score;
64 if (child_score <= idx_score)
66 LOG (
"heap bubble down: %u@%u = %g swapped with %u@%u = %g", child,
67 child_pos, score[child], idx, idx_pos, idx_score);
68 stack[idx_pos] = child;
79#define HEAP_IMPORT(IDX) \
81 KISSAT_assert ((IDX) < UINT_MAX - 1); \
82 if (heap->vars <= (IDX)) \
83 kissat_enlarge_heap (solver, heap, (IDX) + 1); \
86#define CHECK_HEAP_IMPORTED(IDX)
90 LOG (
"push heap %u", idx);
100 LOG (
"pop heap %u", idx);
106 const unsigned idx_pos =
heap->
pos[idx];
121 const unsigned idx = *begin;
123 LOG (
"pop max heap %u", idx);
124 const unsigned last =
POP_STACK (*stack);
141 const unsigned new_vars = idx + 1;
142 const unsigned old_vars =
heap->
vars;
143 if (new_vars <= old_vars)
145 const unsigned old_size =
heap->
size;
146 if (idx >= old_size) {
147 size_t new_size = old_size ? 2 * old_size : 1;
148 while (idx >= new_size)
157 unsigned idx,
double new_score) {
158 const double old_score = kissat_get_heap_score (
heap, idx);
159 if (old_score == new_score)
162 LOG (
"update heap %u score from %g to %g", idx, old_score, new_score);
166 LOG (
"tainted heap");
168 if (!kissat_heap_contains (
heap, idx))
170 if (new_score > old_score)
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
#define POKE_STACK(S, N, E)
void kissat_enlarge_heap(kissat *solver, heap *heap, unsigned new_vars)
void kissat_resize_heap(kissat *solver, heap *heap, unsigned new_size)
#define KISSAT_assert(ignore)
#define kissat_check_heap(...)