|
CIRCT 23.0.0git
|
A max-heap of ids into caller-owned storage. More...
#include <SATSolver.h>

Public Member Functions | |
| IndexedMaxHeap (llvm::SmallVectorImpl< T > &storage) | |
| void | resize (unsigned size) |
| bool | empty () const |
| bool | contains (unsigned id) const |
| void | clear () |
| Remove all heap entries while keeping the underlying storage untouched. | |
| void | insert (unsigned id) |
Insert id if it is not already present. | |
| void | increase (unsigned id) |
Restore heap order after the score for an existing id increased. | |
| unsigned | pop () |
| Remove and return the highest-scoring id. | |
Private Member Functions | |
| double | score (unsigned id) const |
| Compute the ordering score for one heap entry. | |
| void | swapHeapEntries (unsigned lhs, unsigned rhs) |
| Swap two heap slots and keep the reverse index in sync. | |
| void | siftUp (unsigned index) |
| Bubble one entry toward the root until the heap property is restored. | |
| void | siftDown (unsigned index) |
| Push one entry toward the leaves until the heap property is restored. | |
Private Attributes | |
| llvm::SmallVectorImpl< T > & | storage |
| The caller-owned objects indexed by heap ids. | |
| llvm::SmallVector< unsigned, 0 > | heap |
| Binary heap of ids ordered by descending score. | |
| llvm::SmallVector< unsigned, 0 > | positions |
Reverse map from id to heap slot, or InvalidIndex if absent. | |
Static Private Attributes | |
| static constexpr unsigned | kInvalidIndex = ~0u |
A max-heap of ids into caller-owned storage.
The heap stores only integer ids and keeps a reverse map from each id to its heap slot. That lets callers update an existing entry without creating duplicates. Scores come from a stateless policy type. If a caller changes an element in storage in a way that raises its score, it must call increase(id) to restore heap order.
This data structure design is inspired by MiniSat's minisat/mtl/Heap.h.
Definition at line 33 of file SATSolver.h.
|
inlineexplicit |
Definition at line 37 of file SATSolver.h.
|
inline |
Remove all heap entries while keeping the underlying storage untouched.
Definition at line 52 of file SATSolver.h.
References circt::IndexedMaxHeap< T, ScoreFn >::heap, circt::IndexedMaxHeap< T, ScoreFn >::kInvalidIndex, and circt::IndexedMaxHeap< T, ScoreFn >::positions.
|
inline |
Definition at line 47 of file SATSolver.h.
References circt::IndexedMaxHeap< T, ScoreFn >::kInvalidIndex, and circt::IndexedMaxHeap< T, ScoreFn >::positions.
Referenced by circt::IndexedMaxHeap< T, ScoreFn >::increase(), and circt::IndexedMaxHeap< T, ScoreFn >::insert().
|
inline |
Definition at line 45 of file SATSolver.h.
References circt::IndexedMaxHeap< T, ScoreFn >::heap.
Referenced by circt::IndexedMaxHeap< T, ScoreFn >::pop().
|
inline |
Restore heap order after the score for an existing id increased.
This only moves the entry upward. Callers should use this when the score policy is monotonic in the "better" direction, such as SAT variable activity bumps. Mutating a stored element without calling increase(id) leaves the heap order stale.
Definition at line 76 of file SATSolver.h.
References circt::IndexedMaxHeap< T, ScoreFn >::contains(), circt::IndexedMaxHeap< T, ScoreFn >::positions, and circt::IndexedMaxHeap< T, ScoreFn >::siftUp().
|
inline |
Insert id if it is not already present.
This heap treats ids as stable identities; duplicates are ignored instead of creating multiple entries for the same object.
Definition at line 61 of file SATSolver.h.
References circt::IndexedMaxHeap< T, ScoreFn >::contains(), circt::IndexedMaxHeap< T, ScoreFn >::heap, circt::IndexedMaxHeap< T, ScoreFn >::positions, circt::IndexedMaxHeap< T, ScoreFn >::resize(), and circt::IndexedMaxHeap< T, ScoreFn >::siftUp().
|
inline |
Remove and return the highest-scoring id.
Definition at line 82 of file SATSolver.h.
References assert(), circt::IndexedMaxHeap< T, ScoreFn >::empty(), circt::IndexedMaxHeap< T, ScoreFn >::heap, circt::IndexedMaxHeap< T, ScoreFn >::kInvalidIndex, circt::IndexedMaxHeap< T, ScoreFn >::positions, and circt::IndexedMaxHeap< T, ScoreFn >::siftDown().
|
inline |
Definition at line 40 of file SATSolver.h.
References circt::IndexedMaxHeap< T, ScoreFn >::kInvalidIndex, and circt::IndexedMaxHeap< T, ScoreFn >::positions.
Referenced by circt::IndexedMaxHeap< T, ScoreFn >::insert().
|
inlineprivate |
Compute the ordering score for one heap entry.
Definition at line 103 of file SATSolver.h.
References circt::IndexedMaxHeap< T, ScoreFn >::storage.
Referenced by circt::IndexedMaxHeap< T, ScoreFn >::siftDown(), and circt::IndexedMaxHeap< T, ScoreFn >::siftUp().
|
inlineprivate |
Push one entry toward the leaves until the heap property is restored.
Definition at line 127 of file SATSolver.h.
References assert(), circt::IndexedMaxHeap< T, ScoreFn >::heap, circt::IndexedMaxHeap< T, ScoreFn >::score(), and circt::IndexedMaxHeap< T, ScoreFn >::swapHeapEntries().
Referenced by circt::IndexedMaxHeap< T, ScoreFn >::pop().
|
inlineprivate |
Bubble one entry toward the root until the heap property is restored.
Definition at line 113 of file SATSolver.h.
References assert(), circt::IndexedMaxHeap< T, ScoreFn >::heap, circt::IndexedMaxHeap< T, ScoreFn >::score(), and circt::IndexedMaxHeap< T, ScoreFn >::swapHeapEntries().
Referenced by circt::IndexedMaxHeap< T, ScoreFn >::increase(), and circt::IndexedMaxHeap< T, ScoreFn >::insert().
|
inlineprivate |
Swap two heap slots and keep the reverse index in sync.
Definition at line 106 of file SATSolver.h.
References circt::IndexedMaxHeap< T, ScoreFn >::heap, and circt::IndexedMaxHeap< T, ScoreFn >::positions.
Referenced by circt::IndexedMaxHeap< T, ScoreFn >::siftDown(), and circt::IndexedMaxHeap< T, ScoreFn >::siftUp().
|
private |
Binary heap of ids ordered by descending score.
Definition at line 149 of file SATSolver.h.
Referenced by circt::IndexedMaxHeap< T, ScoreFn >::clear(), circt::IndexedMaxHeap< T, ScoreFn >::empty(), circt::IndexedMaxHeap< T, ScoreFn >::insert(), circt::IndexedMaxHeap< T, ScoreFn >::pop(), circt::IndexedMaxHeap< T, ScoreFn >::siftDown(), circt::IndexedMaxHeap< T, ScoreFn >::siftUp(), and circt::IndexedMaxHeap< T, ScoreFn >::swapHeapEntries().
|
staticconstexprprivate |
Definition at line 100 of file SATSolver.h.
Referenced by circt::IndexedMaxHeap< T, ScoreFn >::clear(), circt::IndexedMaxHeap< T, ScoreFn >::contains(), circt::IndexedMaxHeap< T, ScoreFn >::pop(), and circt::IndexedMaxHeap< T, ScoreFn >::resize().
|
private |
Reverse map from id to heap slot, or InvalidIndex if absent.
Definition at line 152 of file SATSolver.h.
Referenced by circt::IndexedMaxHeap< T, ScoreFn >::clear(), circt::IndexedMaxHeap< T, ScoreFn >::contains(), circt::IndexedMaxHeap< T, ScoreFn >::increase(), circt::IndexedMaxHeap< T, ScoreFn >::insert(), circt::IndexedMaxHeap< T, ScoreFn >::pop(), circt::IndexedMaxHeap< T, ScoreFn >::resize(), and circt::IndexedMaxHeap< T, ScoreFn >::swapHeapEntries().
|
private |
The caller-owned objects indexed by heap ids.
Definition at line 146 of file SATSolver.h.
Referenced by circt::IndexedMaxHeap< T, ScoreFn >::score().