ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
heap.h
Go to the documentation of this file.
1#ifndef _heap_h_INCLUDED
2#define _heap_h_INCLUDED
3
4#include "stack.h"
5#include "utilities.h"
6
7#include <assert.h>
8#include <limits.h>
9#include <stdbool.h>
10
11#include "global.h"
13
14#define DISCONTAIN UINT_MAX
15#define DISCONTAINED(IDX) ((int) (IDX) < 0)
16
17typedef struct heap heap;
18
19struct heap {
20 bool tainted;
21 unsigned vars;
22 unsigned size;
23 unsigneds stack;
24 double *score;
25 unsigned *pos;
26};
27
28struct kissat;
29
30void kissat_resize_heap (struct kissat *, heap *, unsigned size);
31void kissat_release_heap (struct kissat *, heap *);
32
33static inline bool kissat_heap_contains (heap *heap, unsigned idx) {
34 return idx < heap->vars && !DISCONTAINED (heap->pos[idx]);
35}
36
37static inline unsigned kissat_get_heap_pos (const heap *heap,
38 unsigned idx) {
39 return idx < heap->vars ? heap->pos[idx] : DISCONTAIN;
40}
41
42static inline double kissat_get_heap_score (const heap *heap,
43 unsigned idx) {
44 return idx < heap->vars ? heap->score[idx] : 0.0;
45}
46
47static inline bool kissat_empty_heap (heap *heap) {
48 return EMPTY_STACK (heap->stack);
49}
50
51static inline size_t kissat_size_heap (heap *heap) {
52 return SIZE_STACK (heap->stack);
53}
54
55static inline unsigned kissat_max_heap (heap *heap) {
56 KISSAT_assert (!kissat_empty_heap (heap));
57 return PEEK_STACK (heap->stack, 0);
58}
59
60void kissat_rescale_heap (struct kissat *, heap *heap, double factor);
61
62void kissat_enlarge_heap (struct kissat *, heap *, unsigned new_vars);
63
64static inline double kissat_max_score_on_heap (heap *heap) {
65 if (!heap->tainted)
66 return 0;
68 const double *const score = heap->score;
69 const double *const end = score + heap->vars;
70 double res = score[0];
71 for (const double *p = score + 1; p != end; p++)
72 res = MAX (res, *p);
73 return res;
74}
75
76#ifndef KISSAT_NDEBUG
77void kissat_dump_heap (heap *);
78#endif
79
80#ifndef KISSAT_NDEBUG
81void kissat_check_heap (heap *);
82#else
83#define kissat_check_heap(...) \
84 do { \
85 } while (0)
86#endif
87
89
90#endif
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
#define MAX(a, b)
Definition avl.h:23
#define SIZE_STACK(S)
Definition stack.h:19
#define EMPTY_STACK(S)
Definition stack.h:18
#define PEEK_STACK(S, N)
Definition stack.h:29
Cube * p
Definition exorList.c:222
#define KISSAT_assert(ignore)
Definition global.h:13
void kissat_resize_heap(struct kissat *, heap *, unsigned size)
Definition heap.c:46
void kissat_enlarge_heap(struct kissat *, heap *, unsigned new_vars)
Definition heap.c:82
#define DISCONTAINED(IDX)
Definition heap.h:15
#define DISCONTAIN
Definition heap.h:14
void kissat_rescale_heap(struct kissat *, heap *heap, double factor)
Definition heap.c:69
#define kissat_check_heap(...)
Definition heap.h:83
void kissat_release_heap(struct kissat *, heap *)
Definition heap.c:10
Definition heap.h:19
unsigneds stack
Definition heap.h:23
unsigned * pos
Definition heap.h:25
double * score
Definition heap.h:24
unsigned vars
Definition heap.h:21
unsigned size
Definition heap.h:22
bool tainted
Definition heap.h:20
unsigned size
Definition internal.h:107