Connect++ 0.4.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
PredicateIndex Class Reference

Management of Predicate objects. More...

#include <PredicateIndex.hpp>

Collaboration diagram for PredicateIndex:

Public Member Functions

 PredicateIndex (const PredicateIndex &)=delete
 Copying these is a terrible idea.
 
 PredicateIndex (const PredicateIndex &&)=delete
 
PredicateIndexoperator= (const PredicateIndex &)=delete
 
PredicateIndexoperator= (const PredicateIndex &&)=delete
 
size_t get_num_preds () const
 Basic get method.
 
Predicateadd_predicate (const string &, Arity)
 Self-explanatory.
 
Predicatefind_predicate (const string &, Arity)
 Self-explanatory.
 
Arity find_maximum_arity () const
 Find the largest arity appearing in the index.
 
bool true_false_added () const
 Sometimes $true and $false appear in the TPTP collection. See if you included them during the parsing.
 
Predicateoperator[] (size_t i)
 Access to Predicate pointers, but
don't mess with them!
 
Predicatemake_definitional_predicate (Arity arity)
 Make a new, unique definitional predicate.
 

Private Attributes

vector< Predicate * > preds
 Pointers to all predicates.
 
unordered_map< PredIndexType, Predicate *, fun_hashname_index
 Fast lookup using name and arity.
 
ID next_index
 Automatically generate IDs.
 
ID next_definitional_id
 Automatically generate IDs for definitional predicates.
 

Friends

ostream & operator<< (ostream &, const PredicateIndex &)
 

Detailed Description

Management of Predicate objects.

Note that the unordered_map can use the hash function from FunctionHash.hpp.

As usual only use this to make Predicates. As long as you do so then it takes care of memory allocation and deallocation.

Definition at line 58 of file PredicateIndex.hpp.

Constructor & Destructor Documentation

◆ PredicateIndex() [1/2]

PredicateIndex::PredicateIndex ( )

Definition at line 27 of file PredicateIndex.cpp.

28: preds()
29, name_index()
30, next_index(0)
32{
33}
vector< Predicate * > preds
Pointers to all predicates.
ID next_definitional_id
Automatically generate IDs for definitional predicates.
ID next_index
Automatically generate IDs.
unordered_map< PredIndexType, Predicate *, fun_hash > name_index
Fast lookup using name and arity.

◆ ~PredicateIndex()

PredicateIndex::~PredicateIndex ( )

Definition at line 35 of file PredicateIndex.cpp.

35 {
36 for (size_t i = 0; i < preds.size(); i++)
37 delete preds[i];
38}

◆ PredicateIndex() [2/2]

PredicateIndex::PredicateIndex ( const PredicateIndex & )
delete

Copying these is a terrible idea.

As usual, let the compiler help you out.

Member Function Documentation

◆ add_predicate()

Predicate * PredicateIndex::add_predicate ( const string & name,
Arity arity )

Self-explanatory.

Parameters
nameName of new Predicate.
arityArity of new Predicate.

Definition at line 40 of file PredicateIndex.cpp.

41 {
42 Predicate* new_pred = nullptr;
43 auto i = name_index.find(PredIndexType(name, arity));
44 if (i == name_index.end()) {
45 new_pred = new Predicate(next_index++, name, arity);
46 preds.push_back(new_pred);
47 name_index.insert(PredMapType(PredIndexType(name, arity), new_pred));
48 }
49 else {
50 new_pred = i->second;
51 }
52 return new_pred;
53}
Basic representation of predicates: here just names, ids and arities.
Definition Predicate.hpp:51

◆ find_maximum_arity()

Arity PredicateIndex::find_maximum_arity ( ) const

Find the largest arity appearing in the index.

Definition at line 66 of file PredicateIndex.cpp.

66 {
67 Arity result = 0;
68 for (size_t i = 0; i < preds.size(); i++) {
69 Arity current = preds[i]->get_arity();
70 if (current > result)
71 result = current;
72 }
73 return result;
74}

◆ find_predicate()

Predicate * PredicateIndex::find_predicate ( const string & fun_name,
Arity arity )

Self-explanatory.

Parameters
fun_nameName of Predicate.
arityArity of Predicate.

Definition at line 55 of file PredicateIndex.cpp.

56 {
57 Predicate* pred = nullptr;
58 auto i = name_index.find(PredIndexType(fun_name, arity));
59 if (i != name_index.end())
60 pred = i->second;
61 else
62 cerr << "That predicate name doesn't exist" << endl;
63 return pred;
64}

◆ get_num_preds()

size_t PredicateIndex::get_num_preds ( ) const
inline

Basic get method.

Definition at line 92 of file PredicateIndex.hpp.

92{ return preds.size(); }

◆ make_definitional_predicate()

Predicate * PredicateIndex::make_definitional_predicate ( Arity arity)
inline

Make a new, unique definitional predicate.

Parameters
arityArity of predicate.

Definition at line 127 of file PredicateIndex.hpp.

127 {
128 return add_predicate(
129 params::definitional_predicate_prefix + std::to_string(next_definitional_id++),
130 arity);
131 }
Predicate * add_predicate(const string &, Arity)
Self-explanatory.

◆ operator[]()

Predicate * PredicateIndex::operator[] ( size_t i)
inline

Access to Predicate pointers, but
don't mess with them!

Definition at line 121 of file PredicateIndex.hpp.

121{ return preds[i]; }

◆ true_false_added()

bool PredicateIndex::true_false_added ( ) const

Sometimes $true and $false appear in the TPTP collection. See if you included them during the parsing.

Definition at line 76 of file PredicateIndex.cpp.

76 {
77 auto i = name_index.find(PredIndexType(string("$true"), 0));
78 if (i != name_index.end())
79 return true;
80 i = name_index.find(PredIndexType(string("$false"), 0));
81 if (i != name_index.end())
82 return true;
83 return false;
84}

Friends And Related Symbol Documentation

◆ operator<<

ostream & operator<< ( ostream & out,
const PredicateIndex & pi )
friend

Definition at line 86 of file PredicateIndex.cpp.

86 {
87 out << "Predicate Index" << endl;
88 out << "---------------" << endl;
89 for (Predicate* p : pi.preds) {
90 out << *p << endl;
91 }
92 return out;
93}

Member Data Documentation

◆ name_index

unordered_map<PredIndexType, Predicate*, fun_hash> PredicateIndex::name_index
private

Fast lookup using name and arity.

Definition at line 67 of file PredicateIndex.hpp.

◆ next_definitional_id

ID PredicateIndex::next_definitional_id
private

Automatically generate IDs for definitional predicates.

Definition at line 76 of file PredicateIndex.hpp.

◆ next_index

ID PredicateIndex::next_index
private

Automatically generate IDs.

Definition at line 71 of file PredicateIndex.hpp.

◆ preds

vector<Predicate*> PredicateIndex::preds
private

Pointers to all predicates.

Definition at line 63 of file PredicateIndex.hpp.


The documentation for this class was generated from the following files: