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

Mechanism for looking after functions. More...

#include <FunctionIndex.hpp>

Collaboration diagram for FunctionIndex:

Public Member Functions

 FunctionIndex (const FunctionIndex &)=delete
 As usual, trying to copy one of these is a really bad idea.
 
 FunctionIndex (const FunctionIndex &&)=delete
 
FunctionIndexoperator= (const FunctionIndex &)=delete
 
FunctionIndexoperator= (const FunctionIndex &&)=delete
 
size_t get_size () const
 Self-explanatory.
 
Functionadd_function (const string &, Arity)
 Add a new function to the index.
 
Functionmake_skolem_function (Arity)
 Add a new Skolem function. Naming is automatic.
 
Functionfind_function (const string &, Arity)
 Look up a stored Function by name and arity.
 
Arity find_maximum_arity () const
 Find the largest arity appearing for any Function in the index.
 
Arity find_minimum_arity () const
 Find the smallest arity appearing for any Function in the index.
 
Functionoperator[] (size_t i)
 Access to pointers to Functions, but don't mess with them!
 

Private Attributes

vector< Function * > funs
 Pointers to all the Functions used.
 
unordered_map< pair< string, Arity >, Function *, fun_hashname_index
 Fast lookup from name/arity to pointer to the Function.
 
ID next_index
 Keep track of ids for adding new Functions.
 
uint32_t skolem_function_number
 Automate the naming of Skolem functions.
 

Friends

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

Detailed Description

Mechanism for looking after functions.

Function names are only stored once, but functions can have the same name and a different arity.

Somewhat more straightforward than looking after variables as there is no need for anonymous functions other than Skolem functions, and those do not get recycled. For the same reason, there is no need to take account of backtracking.

You should only use this to make new Functions. As long as you do, it will take care of allocation and deallocation for you.

Definition at line 64 of file FunctionIndex.hpp.

Constructor & Destructor Documentation

◆ FunctionIndex()

FunctionIndex::FunctionIndex ( )

Definition at line 27 of file FunctionIndex.cpp.

28: funs()
29, name_index()
30, next_index(0)
32{}
unordered_map< pair< string, Arity >, Function *, fun_hash > name_index
Fast lookup from name/arity to pointer to the Function.
ID next_index
Keep track of ids for adding new Functions.
uint32_t skolem_function_number
Automate the naming of Skolem functions.
vector< Function * > funs
Pointers to all the Functions used.

◆ ~FunctionIndex()

FunctionIndex::~FunctionIndex ( )

Definition at line 34 of file FunctionIndex.cpp.

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

Member Function Documentation

◆ add_function()

Function * FunctionIndex::add_function ( const string & name,
Arity arity )

Add a new function to the index.

If you add twice, the original will get re-used.

Parameters
nameThe name of the Function.
arityThe arity of the Function.

Definition at line 39 of file FunctionIndex.cpp.

39 {
40 Function* new_fun = nullptr;
41 auto i = name_index.find(FunIndexType(name, arity));
42 if (i == name_index.end()) {
43 new_fun = new Function(next_index++, name, arity);
44 funs.push_back(new_fun);
45 name_index.insert(FunMapType(FunIndexType(name, arity),
46 new_fun));
47 }
48 else {
49 new_fun = i->second;
50 }
51 return new_fun;
52}
Basic representation of functions.
Definition Function.hpp:54

◆ find_function()

Function * FunctionIndex::find_function ( const string & fun_name,
Arity arity )

Look up a stored Function by name and arity.

Parameters
fun_nameName of Function to find.
arityArity of Function to find.

Definition at line 60 of file FunctionIndex.cpp.

61 {
62 Function* fun = nullptr;
63 auto i = name_index.find(FunIndexType(fun_name, arity));
64 if (i != name_index.end())
65 fun = i->second;
66 else
67 cerr << "That function name doesn't exist" << endl;
68 return fun;
69}

◆ find_maximum_arity()

Arity FunctionIndex::find_maximum_arity ( ) const

Find the largest arity appearing for any Function in the index.

Definition at line 71 of file FunctionIndex.cpp.

71 {
72 Arity result = 0;
73 for (size_t i = 0; i < funs.size(); i++) {
74 Arity current = funs[i]->get_arity();
75 if (current > result)
76 result = current;
77 }
78 return result;
79}

◆ find_minimum_arity()

Arity FunctionIndex::find_minimum_arity ( ) const

Find the smallest arity appearing for any Function in the index.

Definition at line 81 of file FunctionIndex.cpp.

81 {
82 Arity result = UINT32_MAX;
83 for (size_t i = 0; i < funs.size(); i++) {
84 Arity current = funs[i]->get_arity();
85 if (current < result)
86 result = current;
87 }
88 return result;
89}

◆ get_size()

size_t FunctionIndex::get_size ( ) const
inline

Self-explanatory.

Definition at line 96 of file FunctionIndex.hpp.

96{ return funs.size(); }

◆ make_skolem_function()

Function * FunctionIndex::make_skolem_function ( Arity arity)

Add a new Skolem function. Naming is automatic.

Parameters
arityThe arity of the new Skolem function.

Definition at line 54 of file FunctionIndex.cpp.

54 {
55 string name(params::unique_skolem_prefix);
56 name += std::to_string(skolem_function_number++);
57 return add_function(name, arity);
58}
Function * add_function(const string &, Arity)
Add a new function to the index.

◆ operator[]()

Function * FunctionIndex::operator[] ( size_t i)
inline

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

Definition at line 133 of file FunctionIndex.hpp.

133{ return funs[i]; }

Friends And Related Symbol Documentation

◆ operator<<

ostream & operator<< ( ostream & out,
const FunctionIndex & fi )
friend

Definition at line 91 of file FunctionIndex.cpp.

91 {
92 out << "Function Index" << endl;
93 out << "--------------" << endl;
94 for (Function* f : fi.funs) {
95 out << *f << endl;
96 }
97 return out;
98}

Member Data Documentation

◆ funs

vector<Function*> FunctionIndex::funs
private

Pointers to all the Functions used.

Definition at line 69 of file FunctionIndex.hpp.

◆ name_index

unordered_map<pair<string, Arity>, Function*, fun_hash> FunctionIndex::name_index
private

Fast lookup from name/arity to pointer to the Function.

Definition at line 73 of file FunctionIndex.hpp.

◆ next_index

ID FunctionIndex::next_index
private

Keep track of ids for adding new Functions.

Definition at line 77 of file FunctionIndex.hpp.

◆ skolem_function_number

uint32_t FunctionIndex::skolem_function_number
private

Automate the naming of Skolem functions.

Definition at line 81 of file FunctionIndex.hpp.


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