ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cdb.h
Go to the documentation of this file.
1//===--- cdb.h --------------------------------------------------------------===
2//
3// satoko: Satisfiability solver
4//
5// This file is distributed under the BSD 2-Clause License.
6// See LICENSE for details.
7//
8//===------------------------------------------------------------------------===
9#ifndef satoko__cdb_h
10#define satoko__cdb_h
11
12#include "clause.h"
13
16
17/* Clauses DB data structure */
18struct cdb {
19 unsigned size;
20 unsigned cap;
21 unsigned wasted;
22 unsigned *data;
23};
24
25//===------------------------------------------------------------------------===
26// Clause DB API
27//===------------------------------------------------------------------------===
28static inline struct clause *cdb_handler(struct cdb *p, unsigned cref)
29{
30 return cref != 0xFFFFFFFF ? (struct clause *)(p->data + cref) : NULL;
31}
32
33static inline unsigned cdb_cref(struct cdb *p, unsigned *clause)
34{
35 return (unsigned)(clause - &(p->data[0]));
36}
37
38static inline void cdb_grow(struct cdb *p, unsigned cap)
39{
40 unsigned prev_cap = p->cap;
41
42 if (p->cap >= cap)
43 return;
44 while (p->cap < cap) {
45 unsigned delta = ((p->cap >> 1) + (p->cap >> 3) + 2) & (unsigned)(~1);
46 p->cap += delta;
47 assert(p->cap >= prev_cap);
48 }
49 assert(p->cap > 0);
50 p->data = satoko_realloc(unsigned, p->data, p->cap);
51}
52
53static inline struct cdb *cdb_alloc(unsigned cap)
54{
55 struct cdb *p = satoko_calloc(struct cdb, 1);
56 if (cap <= 0)
57 cap = 1024 * 1024;
58 cdb_grow(p, cap);
59 return p;
60}
61
62static inline void cdb_free(struct cdb *p)
63{
64 satoko_free(p->data);
66}
67
68static inline unsigned cdb_append(struct cdb *p, unsigned size)
69{
70 unsigned prev_size;
71 assert(size > 0);
72 cdb_grow(p, p->size + size);
73 prev_size = p->size;
74 p->size += size;
75 assert(p->size > prev_size);
76 return prev_size;
77}
78
79static inline void cdb_remove(struct cdb *p, struct clause *clause)
80{
81 p->wasted += clause->size;
82}
83
84static inline void cdb_clear(struct cdb *p)
85{
86 p->wasted = 0;
87 p->size = 0;
88}
89
90static inline unsigned cdb_capacity(struct cdb *p)
91{
92 return p->cap;
93}
94
95static inline unsigned cdb_size(struct cdb *p)
96{
97 return p->size;
98}
99
100static inline unsigned cdb_wasted(struct cdb *p)
101{
102 return p->wasted;
103}
104
106#endif /* satoko__cdb_h */
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Cube * p
Definition exorList.c:222
#define satoko_free(p)
Definition mem.h:20
#define satoko_calloc(type, n_elements)
Definition mem.h:18
#define satoko_realloc(type, ptr, n_elements)
Definition mem.h:19
Definition cdb.h:18
unsigned wasted
Definition cdb.h:21
unsigned cap
Definition cdb.h:20
unsigned * data
Definition cdb.h:22
unsigned size
Definition cdb.h:19
unsigned size
Definition clause.h:37
#define assert(ex)
Definition util_old.h:213