25#include "TermIndex.hpp"
31 auto i = index.find(t);
32 if (i != index.end()) {
51TermIndex::~TermIndex() {
58 cerr <<
"Don't add substituted variables to the Term Index!" << endl;
67 index.insert(pair<Term, Term*>(t, p));
74 const vector<Term*>& args) {
75 for (
size_t i = 0; i < args.size(); i++) {
76 if (args[i]->is_subbed()) {
77 cerr <<
"Don't add substituted functions to the Term Index!" << endl;
85 p =
new Term(fp, args);
87 index.insert(pair<Term, Term*>(t, p));
97 if (old_v == t->
get_v()) {
105 vector<Term*> new_args;
106 for (
size_t i = 0; i < t->
arity(); i++)
118 if (old_v == t->
get_v()) {
126 vector<Term*> new_args;
127 for (
size_t i = 0; i < t->
arity(); i++)
133ostream& operator<<(ostream& out,
const TermIndex& t) {
134 out <<
"Contents of term index:" << endl;
135 out <<
"-----------------------" << endl;
136 for (
Term* p : t.term_pointers)
137 out << p <<
" : " << *p << endl;
150 unordered_map<Variable*,Term*>& v_map)
const {
151 Term* result =
nullptr;
155 cerr <<
"If you're doing Connection Calculus then something's wrong!" << endl;
158 auto i = v_map.find(v);
159 if (i == v_map.end()) {
162 v_map.insert(VarMapType(v, result));
170 vector<Term*> new_args;
171 for (
size_t i = 0; i < args.size(); i++) {
182 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, (ideally) 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
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
Self-explanatory.
Term * get_subbed_term() const
Self-explanatory.
Storage of named variables, and management of new, anonymous variables.
Variable * add_anon_var()
Add an anonymous variable.