25#include "TermIndex.hpp"
29 auto i =
index.find(t);
30 if (i !=
index.end()) {
36TermIndex::~TermIndex() {
43 cerr <<
"Don't add substituted variables to the Term Index!" << endl;
51 index.insert(pair<Term, Term*>(t, p));
57 const vector<Term*>& args) {
58 for (
size_t i = 0; i < args.size(); i++) {
59 if (args[i]->is_subbed()) {
60 cerr <<
"Don't add substituted functions to the Term Index!" << endl;
68 p =
new Term(fp, args);
69 index.insert(pair<Term, Term*>(t, p));
78 if (old_v == t->
get_v()) {
86 vector<Term*> new_args;
87 for (
size_t i = 0; i < t->
arity(); i++)
99 if (old_v == t->
get_v()) {
107 vector<Term*> new_args;
108 for (
size_t i = 0; i < t->
arity(); i++)
114ostream& operator<<(ostream& out,
const TermIndex& t) {
115 out <<
"Contents of term index:" << endl;
116 out <<
"-----------------------" << endl;
117 for (
Term* p : t.term_pointers)
118 out << p <<
" : " << *p << endl;
131 unordered_map<Variable*,Term*>& v_map)
const {
132 Term* result =
nullptr;
136 cerr <<
"If you're doing Connection Calculus then something's wrong!" << endl;
139 auto i = v_map.find(v);
140 if (i == v_map.end()) {
143 v_map.insert(VarMapType(v, result));
151 vector<Term*> new_args;
152 for (
size_t i = 0; i < args.size(); i++) {
163 unordered_map<Variable*,Term*> v_map;
Basic representation of functions.
General representation of terms.
Term * make_copy_with_new_vars(VariableIndex &, TermIndex &) const
Does as the name suggests.
Variable * get_v() const
Self-explanatory access function.
Term * make_copy_with_new_vars_helper(VariableIndex &, TermIndex &, unordered_map< Variable *, Term * > &) const
Main implementation of make_copy_with_new_vars.
Function * get_f() const
Self-explanatory access function.
bool is_variable() const
Self-explanatory.
Arity arity() const
Self-explanatory access function.
Look after terms, using hash consing to avoid storing copies of terms.
Term * find(const Term &)
Find a term in the index.
Term * add_function_term(Function *, const vector< Term * > &)
Self-explanatory: add a Term containing a function to the index.
vector< Term * > term_pointers
Used to make destruction easy.
unordered_map< Term, Term *, term_hash > index
Hash table for storing pointers to where Terms are actually stored.
Term * add_variable_term(Variable *)
Self-explanatory: add a Term containing a variable to the index.
Term * replace_variable_in_term_with_term(Term *, Variable *, Term *)
Minor variation on replace_variable_in_term.
Term * replace_variable_in_term(Variable *, Variable *, Term *)
Replace a variable in a term with an alternative, maintaining the structure of the TermIndex.
Basic representation of variables.
bool is_subbed() const
Is this variable currently substituted?
Term * get_subbed_term() const
Get the current substitution, or nullptr.
Storage of named variables, and management of new, anonymous and unique variables.
Variable * add_anon_var()
Add an anonymous variable.