aboutsummaryrefslogtreecommitdiff
path: root/src/core/term_bank.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-04-03 02:46:12 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-04-03 02:46:12 +0800
commit9ab592ce3765d07b6dbdb9c1d9b62dc8045e784e (patch)
tree5b2bf93147980c5dabef80eff4c6209caa95f034 /src/core/term_bank.cc
parent1e35f078fe5ace02b22e6f4ba89f57ba4a58b8c9 (diff)
downloadratp-9ab592ce3765d07b6dbdb9c1d9b62dc8045e784e.tar.gz
ratp-9ab592ce3765d07b6dbdb9c1d9b62dc8045e784e.tar.xz
feat: implement core term, symbol, and clause storage logic with canonicalization support
Diffstat (limited to 'src/core/term_bank.cc')
-rw-r--r--src/core/term_bank.cc37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/core/term_bank.cc b/src/core/term_bank.cc
index b62ffd0..53b4f0c 100644
--- a/src/core/term_bank.cc
+++ b/src/core/term_bank.cc
@@ -16,4 +16,41 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+#include "atp/core/term_bank.h"
+#include "atp/core/types.h"
+#include <cassert>
+namespace atp {
+
+TermId TermBank::makeTerm(SymbolId symbol, std::span<const TermId> args) {
+ TermKey key{.symbol = symbol, .args = {args.begin(), args.end()}};
+ auto it = term_to_id_.find(key);
+ if (it != term_to_id_.end()) {
+ return it->second;
+ }
+ auto new_id = static_cast<TermId>(terms_.size());
+ Term new_term{.symbol_id = symbol, .args = {args.begin(), args.end()}};
+ terms_.push_back(std::move(new_term));
+ term_to_id_.emplace(std::move(key), new_id);
+ return new_id;
+}
+
+TermId TermBank::makeVar(SymbolId var_symbol) {
+ return makeTerm(var_symbol, {});
+}
+
+const Term& TermBank::getTerm(TermId id) const {
+ assert(id < terms_.size() && "TermId out of bounds!");
+ return terms_[id];
+}
+
+bool TermBank::isVariable(TermId id) const {
+ assert(id < terms_.size() && "TermId out of bounds!");
+ return symbols_.isVariable(terms_[id].symbol_id);
+}
+
+size_t TermBank::size() const {
+ return terms_.size();
+}
+
+} // namespace atp