Connect++ 0.6.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
ClauseCopyCache.cpp
1/*
2
3Copyright © 2023-24 Sean Holden. All rights reserved.
4
5*/
6/*
7
8This file is part of Connect++.
9
10Connect++ is free software: you can redistribute it and/or modify it
11under the terms of the GNU General Public License as published by the
12Free Software Foundation, either version 3 of the License, or (at your
13option) any later version.
14
15Connect++ is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18more details.
19
20You should have received a copy of the GNU General Public License along
21with Connect++. If not, see <https://www.gnu.org/licenses/>.
22
23*/
24
25#include "ClauseCopyCache.hpp"
26
27//---------------------------------------------------------------------------
28void ClauseCopyCache::set_size(size_t _size) {
29 size = _size;
30 clear();
31}
32//---------------------------------------------------------------------------
34 size_t _index, Clause& _clause, VariableIndex& _vi, TermIndex& _ti) {
35 size_t n = current_copy_number[_index];
36 if (n < number_of_copies_available[_index]) {
37 _clause = (cache[_index])[n];
38 }
39 else {
40 // _clause = Make an actual copy
41 cache[_index].push_back(_clause);
43 }
44 current_copy_number[_index]++;
45 stack.push_back(_index);
46}
47//---------------------------------------------------------------------------
49 size_t i = stack.back();
50 stack.pop_back();
52}
53//---------------------------------------------------------------------------
55 cache = vector<vector<Clause>>(size, vector<Clause>());
56 number_of_copies_available = vector<size_t>(size, 0);
57 current_copy_number = vector<size_t>(size, 0);
58 stack.clear();
59}
void set_size(size_t)
You probably don't know the size at the point when this needs to be constructed.
vector< vector< Clause > > cache
Cache containing some number of copies (with unique variables, not used anywhere else) of clauses fro...
vector< size_t > stack
Each time you supply a copy, remember the action so that you can backtrack.
void clear()
We will sometimes need to clear the cache and start again because of reordering operations on the mat...
void make_copy_with_new_variables(size_t, Clause &, VariableIndex &, TermIndex &)
If there is a copy cached, replace the parameter with it. Otherwise, use the parameter to actually ma...
void backtrack()
Backtracking is just looking at the last copy supplied and undoing that action.
vector< size_t > current_copy_number
When 0, there are no copies available. When 1, the last copy we used is the one at index 0,...
vector< size_t > number_of_copies_available
How many copies of each clause, in total, are currently available? At any given time some may be avai...
size_t size
Keep track of how many clauses there are in the matrix.
Representation of clauses.
Definition Clause.hpp:52
Look after terms, using hash consing to avoid storing copies of terms.
Definition TermIndex.hpp:54
Storage of named variables, and management of new, anonymous and unique variables.