Connect++ 0.6.1
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
Stack.hpp
1/*
2
3Copyright © 2023-25 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#pragma once
26
27#include "StackItem.hpp"
28
40class Stack {
41private:
55 size_t capacity;
59 void extend(size_t _n) {
60 size_t old_capacity = capacity;
61 // _n == 0 is interpreted as "double the capacity".
62 _n == 0 ? capacity *= 2 : capacity += _n;
63 StackItem* old_stack = stack;
64 stack = new StackItem [capacity];
65 for (size_t i = 0; i < old_capacity; i++) {
66 stack[i] = old_stack[i];
67 }
68 delete [] old_stack;
69 }
70public:
75 Stack() : stack(), next_item_index(0), capacity(params::stack_start_size) {
76 stack = new StackItem [params::stack_start_size];
77 };
78 ~Stack() { delete [] stack; }
82 inline void clear() {
84 }
88 inline bool empty() const {
89 return next_item_index == 0;
90 }
94 inline size_t size() const {
95 return next_item_index;
96 }
100 inline void push_back(const StackItem& _item) {
101 if (next_item_index == capacity) {
102 extend(params::stack_increment);
103 }
104 stack[next_item_index++] = _item;
105 }
109 inline StackItem& back() {
110 return stack[next_item_index - 1];
111 }
116 inline void pop_back() {
118 }
122 inline StackItem& operator[](size_t _i) {
123 return stack[_i];
124 }
132 inline void emplace_back(StackItemType sit,
133 const Clause& _c,
134 const SimplePath& _p,
135 const Lemmata& _l,
136 uint32_t _d) {
137 if (next_item_index == capacity) {
138 extend(params::stack_increment);
139 }
141 si->item_type = sit;
142 si->c = _c;
143 si->p = _p;
144 si->l = _l;
145 si->sub.clear();
146 si->depth = _d;
147 si->bt_restriction_index = 0;
148 si->stack_item_setup();
150 }
158 inline void emplace_back(StackItemType sit,
159 const Clause& _c,
160 const SimplePath& _p,
161 const Lemmata& _l,
162 const Substitution& _sub,
163 uint32_t _d) {
164 if (next_item_index == capacity) {
165 extend(params::stack_increment);
166 }
168 si->item_type = sit;
169 si->c = _c;
170 si->p = _p;
171 si->l = _l;
172 si->sub = _sub;
173 si->depth = _d;
174 si->bt_restriction_index = 0;
175 si->stack_item_setup();
177 }
178 friend ostream& operator<<(ostream&, Stack&);
179};
180
Representation of clauses.
Definition Clause.hpp:52
Representation of the lemma list.
Definition Lemmata.hpp:49
Simple representation of the path within a proof tree.
If you implement the stacks used by the prover as a vector<StackItem> then every time you move down t...
Definition Stack.hpp:40
void emplace_back(StackItemType sit, const Clause &_c, const SimplePath &_p, const Lemmata &_l, const Substitution &_sub, uint32_t _d)
(Almost!) exact analogue of the same function for vector<>.
Definition Stack.hpp:158
Stack()
The constructor is straightforward - just make some initial space in the vector.
Definition Stack.hpp:75
size_t next_item_index
Keep track of where the next empty space is.
Definition Stack.hpp:50
void emplace_back(StackItemType sit, const Clause &_c, const SimplePath &_p, const Lemmata &_l, uint32_t _d)
(Almost!) exact analogue of the same function for vector<>.
Definition Stack.hpp:132
size_t size() const
Exact analogue of the same function for vector<>.
Definition Stack.hpp:94
StackItem & operator[](size_t _i)
Exact analogue of the same function for vector<>.
Definition Stack.hpp:122
StackItem * stack
The idea is to store the stack here, but to never actually remove anything from it,...
Definition Stack.hpp:46
bool empty() const
Exact analogue of the same function for vector<>.
Definition Stack.hpp:88
void push_back(const StackItem &_item)
Exact analogue of the same function for vector<>.
Definition Stack.hpp:100
void extend(size_t _n)
Make extra space later if needed.
Definition Stack.hpp:59
void clear()
Exact analogue of the same function for vector<>.
Definition Stack.hpp:82
void pop_back()
Exact analogue of the same function for vector<>. BUT - importantly - avoid calling the StackItem des...
Definition Stack.hpp:116
StackItem & back()
Exact analogue of the same function for vector<>.
Definition Stack.hpp:109
size_t capacity
Keep track of how much space we have. If we need more then extend as needed.
Definition Stack.hpp:55
General representation of a substitution.
void clear()
Clear a substitution.
Stack items: each contains its own material for generating possible next inferences.
Definition StackItem.hpp:54
SimplePath p
Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the path.
Definition StackItem.hpp:76
Substitution sub
Some nodes in the proof tree have an associated substitution.
Definition StackItem.hpp:94
uint32_t depth
How deep in the proof tree are we?
Definition StackItem.hpp:98
size_t bt_restriction_index
Pointer that allows a right branch to know where to delete alternatives for restricted backtracking.
Lemmata l
Each node in the proof tree is a tuple of clause, matrix, path, lemmas: this is the lemmas.
Definition StackItem.hpp:85
Clause c
Each node in the proof tree is a tuple of clause, matrix, path, lemmata: this is the clause.
Definition StackItem.hpp:63
StackItemType item_type
What type of StackItem is this?
Definition StackItem.hpp:58
void stack_item_setup()
Basic setup collected in a method to avoid repeating it in the various constructors.
Definition StackItem.cpp:51
Structure containing all the command line and other options.