7 #include <unordered_set> 11 #include "dreal/util/exception.h" 17 template <
class Key,
class Hash = std::hash<Key>,
18 class KeyEqual = std::equal_to<Key>,
19 class Allocator = std::allocator<Key>>
24 using key_type =
typename UnorderedSetType::key_type;
25 using value_type =
typename UnorderedSetType::value_type;
26 using size_type =
typename UnorderedSetType::size_type;
27 using const_iterator =
typename UnorderedSetType::const_iterator;
34 using Action = std::tuple<ActionKind, Key>;
48 const_iterator
begin()
const {
return set_.begin(); }
49 const_iterator cbegin()
const {
return set_.cbegin(); }
50 const_iterator end()
const {
return set_.end(); }
51 const_iterator cend()
const {
return set_.cend(); }
54 bool empty()
const {
return set_.empty(); }
55 size_type size()
const {
return set_.size(); }
63 void insert(
const Key& k) {
64 auto it = set_.find(k);
65 if (it == set_.end()) {
72 size_type count(
const Key& key)
const {
return set_.count(key); }
74 const_iterator
find(
const Key& key)
const {
return set_.find(key); }
77 void push() { stack_.push_back(actions_.size()); }
80 throw DREAL_RUNTIME_ERROR(
81 "ScopedUnorderedSet cannot be popped because it's scope is empty.");
83 size_type idx = stack_.back();
84 while (idx < actions_.size()) {
85 const Action& item{actions_.back()};
87 const Key& k{std::get<1>(item)};
88 auto it = set_.find(k);
101 std::vector<Action> actions_;
102 std::vector<size_type> stack_;
Sum type of symbolic::Expression and symbolic::Formula.
Definition: api.cc:9
Backtrackable set.
Definition: scoped_unordered_set.h:20
std::unordered_set< Variable::Id, std::hash< Variable::Id >, std::equal_to< Variable::Id >, std::allocator< Variable::Id > > UnorderedSetType
Aliases.
Definition: scoped_unordered_set.h:23
void push()
Push/Pop.
Definition: scoped_unordered_set.h:77
const_iterator find(const Key &key) const
Definition: scoped_unordered_set.h:74
Insert(k) means that k is inserted.
void clear()
Modifiers.
Definition: scoped_unordered_set.h:58
bool empty() const
Capacity.
Definition: scoped_unordered_set.h:54
const_iterator begin() const
Iterators.
Definition: scoped_unordered_set.h:48
ActionKind
To backtrack, we need to record the actions applied to this container.
Definition: scoped_unordered_set.h:31