3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

reorganizing the code

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2012-10-24 14:47:40 -07:00
parent 61bd5a69ec
commit 12a255e36b
195 changed files with 11 additions and 526 deletions

View file

@ -1,158 +0,0 @@
/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
fvi.cpp
Abstract:
Feature Vector Indexing.
Author:
Leonardo de Moura (leonardo) 2008-02-01.
Revision History:
--*/
#ifdef _WINDOWS
#include"fvi_def.h"
#include"trace.h"
typedef vector<int> data;
static int to_feature(int val) {
return val % 4;
}
static std::ostream & operator<<(std::ostream & out, data const & d) {
out << "[";
data::const_iterator it = d.begin();
data::const_iterator end = d.end();
for (bool first = true; it != end; ++it, first = false)
out << (first ? "" : " ") << *it << ":" << to_feature(*it);
out << "]";
return out;
}
#define NUM_FEATURES 5
struct to_feature_vector {
unsigned m_num_features;
to_feature_vector(unsigned n):m_num_features(n) {}
void operator()(data * d, unsigned * f) {
for (unsigned i = 0; i < m_num_features; i++) {
f[i] = to_feature((*d)[i]);
}
}
};
struct data_hash {
unsigned operator()(data * d) const {
unsigned r = 0;
data::iterator it = d->begin();
data::iterator end = d->end();
for (; it != end; ++it)
r += *it;
return r;
}
};
ptr_vector<data> g_datas;
static void collect() {
std::for_each(g_datas.begin(), g_datas.end(), delete_proc<data>());
}
static data * mk_random_data() {
data * d = alloc(data);
for (unsigned i = 0; i < NUM_FEATURES; i++)
d->push_back(rand() % 1000);
g_datas.push_back(d);
return d;
}
struct le_visitor {
data * m_data;
le_visitor(data * d):m_data(d) {}
bool operator()(data * other) {
// TRACE("fvi", tout << *other << " <= " << *m_data << "\n";);
for (unsigned i = 0; i < NUM_FEATURES; i++) {
SASSERT(to_feature((*other)[i]) <= to_feature((*m_data)[i]));
}
return true;
}
};
static void tst1(unsigned n1) {
typedef fvi<data, to_feature_vector, data_hash> data_set;
data_set index1(NUM_FEATURES, to_feature_vector(NUM_FEATURES));
ptr_vector<data> index2;
for (unsigned i = 0; i < n1; i++) {
int op = rand()%6;
if (op < 3) {
data * d = mk_random_data();
if (!index1.contains(d)) {
// TRACE("fvi", tout << "inserting: " << *d << "\n";);
index1.insert(d);
index2.push_back(d);
SASSERT(std::find(index2.begin(), index2.end(), d) != index2.end());
SASSERT(index1.contains(d));
}
}
else if (op < 4) {
if (!index2.empty()) {
unsigned idx = rand() % index2.size();
if (index2[idx]) {
SASSERT(index1.contains(index2[idx]));
}
}
}
else if (op < 5) {
if (!index2.empty()) {
unsigned idx = rand() % index2.size();
if (index2[idx]) {
// TRACE("fvi", tout << "erasing: " << *(index2[idx]) << "\n";);
index1.erase(index2[idx]);
SASSERT(!index1.contains(index2[idx]));
index2[idx] = 0;
}
}
}
else {
if (!index2.empty()) {
unsigned idx = rand() % index2.size();
data * d = index2[idx];
if (d)
index1.visit(d, le_visitor(d));
}
}
}
TRACE("fvi",
data_set::statistics s;
index1.stats(s);
tout << "size: " << s.m_size << "\n";
tout << "num. nodes: " << s.m_num_nodes << "\n";
tout << "num. leaves: " << s.m_num_leaves << "\n";
tout << "min. leaf size: " << s.m_min_leaf_size << "\n";
tout << "max. leaf size: " << s.m_max_leaf_size << "\n";
);
}
void tst_fvi() {
for (unsigned i = 0; i < 1000; i++)
tst1(100);
tst1(10000);
collect();
}
#else
void tst_fvi() {
}
#endif

View file

@ -151,8 +151,6 @@ int main(int argc, char ** argv) {
TST(list);
TST(small_object_allocator);
TST(timeout);
TST(splay_tree);
TST(fvi);
TST(proof_checker);
TST(simplifier);
TST(bv_simplifier_plugin);

View file

@ -1,175 +0,0 @@
/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
splay_tree.cpp
Abstract:
Splay trees
Author:
Leonardo de Moura (leonardo) 2008-01-31.
Revision History:
--*/
#include"splay_tree_map.h"
#include"splay_tree_def.h"
#include"trace.h"
#include"vector.h"
#include"map.h"
#include"timeit.h"
struct icomp {
int operator()(int k1, int k2) const {
return k1 - k2;
}
};
struct visitor {
bool m_out;
int m_prev;
unsigned m_num;
visitor(bool f = true):m_out(f), m_prev(-1), m_num(0) {}
void operator()(int k, int d) {
SASSERT(m_prev < k);
SASSERT(d == 2 * k);
m_num++;
m_prev = k;
if (m_out) {
TRACE_CODE(tout << k << " ";);
}
}
};
static void tst1(unsigned n) {
splay_tree_map<int, int, icomp> s1;
svector<bool> s2(n, false);
unsigned size = 0;
unsigned num_op = rand()%1000;
for (unsigned i = 0; i < num_op; i++) {
unsigned op = rand()%5;
if (op < 3) {
unsigned idx = rand() % n;
TRACE("splay_tree_detail", tout << "inserting: " << idx << "\n";);
if (!s2[idx]) {
size++;
}
s2[idx] = true;
s1.insert(idx, idx*2);
}
else if (op < 4) {
unsigned idx = rand() % n;
TRACE("splay_tree_detail", tout << "erasing: " << idx << "\n";);
if (s2[idx]) {
size--;
}
s2[idx] = false;
s1.erase(idx);
}
else {
SASSERT((size == 0) == s1.empty());
for (unsigned idx = 0; idx < n; idx++) {
unsigned idx2 = rand() % n;
DEBUG_CODE(
int v;
SASSERT(s2[idx2] == s1.find(idx2, v));
SASSERT(!s2[idx2] || v == 2*idx2);
);
}
}
TRACE("splay_tree",
visitor v;
s1.visit(v);
tout << "\n";
int idx = rand()%n;
tout << "smaller than: " << idx << "\n";
visitor v2;
s1.visit_le(v2, idx);
tout << "\n";
tout << "greater than: " << idx << "\n";
visitor v3;
s1.visit_ge(v3, idx);
tout << "\n";);
visitor v(false);
s1.visit(v);
CTRACE("splay_tree", v.m_num != size, s1.display(tout); tout << "\n";);
SASSERT(v.m_num == size);
}
s1.reset();
SASSERT(s1.empty());
TRACE("splay_tree",
visitor v;;
s1.visit(v);
SASSERT(v.m_num == 0);
tout << "\n";);
}
static void tst_perf(int n1, int n2, int n3, int n4, int n5) {
u_map<int> values1;
svector<int> idxs;
splay_tree_map<int, int, icomp> values2;
{
timeit t(true, "building: ");
for (int i = 0; i < n2; i++) {
int idx = rand() % n1;
idxs.push_back(idx);
values1.insert(idxs[i], i);
}
for (int i = 0; i < n2; i++) {
values2.insert(idxs[i], i);
}
}
int s1, s2;
{
timeit t(true, "u_map: ");
s1 = 0;
for (int j = 0; j < n4; j++) {
for (int i = 0; i < n5; i++) {
int v;
values1.find(idxs[i], v);
s1 += v;
}
}
}
std::cout << s1 << "\n";
{
timeit t(true, "splay_tree: ");
s2 = 0;
for (int j = 0; j < n4; j++) {
for (int i = 0; i < n5; i++) {
int v;
values2.find(idxs[i], v);
s2 += v;
}
}
// for (int i = 0; i < n5; i++) {
// std::cout << idxs[i] << " ";
// }
std::cout << "\n";
// values2.display(std::cout);
}
std::cout << s2 << "\n";
}
void tst_splay_tree() {
for (unsigned i = 0; i < 100; i++) {
tst1(1 + rand()%31);
tst1(1 + rand()%100);
}
// tst_perf(10000000, 1000000, 10000, 1000000, 100);
}