3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-28 17:08:45 +00:00
z3/src/util/visit_helper.h
Nikolaj Bjorner 90490cb22f make visited_helper independent of literals
re-introduce shorthands in sat::solver for visited and have them convert literals to unsigned.
2022-11-03 03:54:39 -07:00

49 lines
No EOL
1.2 KiB
C++

/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
visit_helper.h
Abstract:
Routine for marking and counting visited occurrences
Author:
Clemens Eisenhofer 2022-11-03
--*/
#pragma once
class visit_helper {
unsigned_vector m_visited;
unsigned m_visited_begin = 0;
unsigned m_visited_end = 0;
public:
void init_visited(unsigned n, unsigned lim = 1) {
SASSERT(lim > 0);
if (m_visited_end >= m_visited_end + lim) { // overflow
m_visited_begin = 0;
m_visited_end = lim;
m_visited.reset();
}
else {
m_visited_begin = m_visited_end;
m_visited_end = m_visited_end + lim;
}
while (m_visited.size() < n)
m_visited.push_back(0);
}
void mark_visited(unsigned v) { m_visited[v] = m_visited_begin + 1; }
void inc_visited(unsigned v) {
m_visited[v] = std::min(m_visited_end, std::max(m_visited_begin, m_visited[v]) + 1);
}
bool is_visited(unsigned v) const { return m_visited[v] > m_visited_begin; }
unsigned num_visited(unsigned v) { return std::max(m_visited_begin, m_visited[v]) - m_visited_begin; }
};