3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-03-15 09:39:59 +00:00

restructure base class struct_factory so that enumeration of values for a sort comes together with hash-table access. This allows to use the enumeration view during value creations for finite sets

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2025-10-16 13:15:23 +02:00
parent b53e87dcba
commit 1b918ce4ec
5 changed files with 44 additions and 49 deletions

View file

@ -19,41 +19,39 @@ Revision History:
#include "model/struct_factory.h"
#include "model/model_core.h"
struct_factory::value_set * struct_factory::get_value_set(sort * s) {
struct_factory::value_set& struct_factory::get_value_set(sort * s) {
value_set * set = nullptr;
if (!m_sort2value_set.find(s, set)) {
set = alloc(value_set);
set = alloc(value_set, m_model.get_manager());
m_sort2value_set.insert(s, set);
m_sorts.push_back(s);
m_sets.push_back(set);
}
SASSERT(set != 0);
return set;
return *set;
}
struct_factory::struct_factory(ast_manager & m, family_id fid, model_core & md):
value_factory(m, fid),
m_model(md),
m_values(m),
m_sorts(m) {
}
struct_factory::~struct_factory() {
std::for_each(m_sets.begin(), m_sets.end(), delete_proc<value_set>());
}
void struct_factory::register_value(expr * new_value) {
sort * s = new_value->get_sort();
value_set * set = get_value_set(s);
if (!set->contains(new_value)) {
m_values.push_back(new_value);
set->insert(new_value);
auto& [set, values] = get_value_set(s);
if (!set.contains(new_value)) {
values.push_back(new_value);
set.insert(new_value);
}
}
bool struct_factory::get_some_values(sort * s, expr_ref & v1, expr_ref & v2) {
value_set * set = get_value_set(s);
switch (set->size()) {
auto& [set, values] = get_value_set(s);
switch (set.size()) {
case 0:
v1 = get_fresh_value(s);
v2 = get_fresh_value(s);
@ -63,7 +61,7 @@ bool struct_factory::get_some_values(sort * s, expr_ref & v1, expr_ref & v2) {
v2 = get_fresh_value(s);
return v2 != 0;
default:
obj_hashtable<expr>::iterator it = set->begin();
obj_hashtable<expr>::iterator it = set.begin();
v1 = *it;
++it;
v2 = *it;