1 | /*
|
2 | * Souffle - A Datalog Compiler
|
3 | * Copyright (c) 2022, The Souffle Developers. All rights reserved
|
4 | * Licensed under the Universal Permissive License v 1.0 as shown at:
|
5 | * - https://opensource.org/licenses/UPL
|
6 | * - <souffle root>/licenses/SOUFFLE-UPL.txt
|
7 | */
|
8 |
|
9 | /************************************************************************
|
10 | *
|
11 | * @file Nullaries.h
|
12 | *
|
13 | * Datastructure for Nullary relations
|
14 | *
|
15 | ***********************************************************************/
|
16 |
|
17 | #pragma once
|
18 |
|
19 | #include "souffle/RamTypes.h"
|
20 | #include "souffle/SouffleInterface.h"
|
21 | #include <atomic>
|
22 |
|
23 | namespace souffle {
|
24 |
|
25 | /** Nullary relations */
|
26 | class t_nullaries {
|
27 | private:
|
28 | std::atomic<bool> data{false};
|
29 |
|
30 | public:
|
31 | static constexpr Relation::arity_type Arity = 0;
|
32 |
|
33 | t_nullaries() = default;
|
34 | using t_tuple = Tuple<RamDomain, 0>;
|
35 | struct context {};
|
36 | context createContext() {
|
37 | return context();
|
38 | }
|
39 | class iterator {
|
40 | bool value;
|
41 |
|
42 | public:
|
43 | using iterator_category = std::forward_iterator_tag;
|
44 | using value_type = RamDomain*;
|
45 | using difference_type = ptrdiff_t;
|
46 | using pointer = value_type*;
|
47 | using reference = value_type&;
|
48 |
|
49 | iterator(bool v = false) : value(v) {}
|
50 |
|
51 | const RamDomain* operator*() {
|
52 | return nullptr;
|
53 | }
|
54 |
|
55 | bool operator==(const iterator& other) const {
|
56 | return other.value == value;
|
57 | }
|
58 |
|
59 | bool operator!=(const iterator& other) const {
|
60 | return other.value != value;
|
61 | }
|
62 |
|
63 | iterator& operator++() {
|
64 | if (value) {
|
65 | value = false;
|
66 | }
|
67 | return *this;
|
68 | }
|
69 | };
|
70 | iterator begin() const {
|
71 | return iterator(data);
|
72 | }
|
73 | iterator end() const {
|
74 | return iterator();
|
75 | }
|
76 | void insert(const t_tuple& /* t */) {
|
77 | data = true;
|
78 | }
|
79 | void insert(const t_tuple& /* t */, context& /* ctxt */) {
|
80 | data = true;
|
81 | }
|
82 | void insert(const RamDomain* /* ramDomain */) {
|
83 | data = true;
|
84 | }
|
85 | bool insert() {
|
86 | bool result = data;
|
87 | data = true;
|
88 | return !result;
|
89 | }
|
90 | bool contains(const t_tuple& /* t */) const {
|
91 | return data;
|
92 | }
|
93 | bool contains(const t_tuple& /* t */, context& /* ctxt */) const {
|
94 | return data;
|
95 | }
|
96 | std::size_t size() const {
|
97 | return data ? 1 : 0;
|
98 | }
|
99 | bool empty() const {
|
100 | return !data;
|
101 | }
|
102 | void purge() {
|
103 | data = false;
|
104 | }
|
105 | void printStatistics(std::ostream& /* o */) const {}
|
106 | };
|
107 |
|
108 | } // namespace souffle
|