10#ifndef KLEE_MAPOFSETS_H
11#define KLEE_MAPOFSETS_H
29 template<
class K,
class V>
39 void insert(
const std::set<K> &set,
const V &value);
47 std::vector< std::pair<std::set<K>, V> > &resultOut);
49 std::vector< std::pair<std::set<K>, V> > &resultOut);
51 template<
class Predicate>
53 template<
class Predicate>
54 V *
findSubset(
const std::set<K> &set,
const Predicate &p);
61 template<
class Iterator,
class Vector>
63 const std::set<K> &accum,
67 template<
class Iterator,
class Vector>
69 const std::set<K> &accum,
73 template<
class Predicate>
75 typename std::set<K>::iterator
begin,
76 typename std::set<K>::iterator
end,
78 template<
class Predicate>
80 typename std::set<K>::iterator
begin,
81 typename std::set<K>::iterator
end,
87 template<
class K,
class V>
99 std::map<K, Node> children;
102 Node() : value(), isEndOfSet(false) {}
105 template<
class K,
class V>
107 typedef std::vector< typename std::map<K, Node>::iterator >
stack_ty;
117 Node *n = stack.empty() ?
root : &stack.back()->second;
119 stack.push_back(n->
children.begin());
120 n = &stack.back()->second;
128 while (!stack.empty()) {
129 unsigned size = stack.size();
130 Node *at = size==1 ?
root : &stack[size-2]->second;
131 typename std::map<K,Node>::iterator &cur = stack.back();
136 Node *n = &cur->second;
140 stack.push_back(n->
children.begin());
141 n = &stack.back()->second;
159 const std::pair<const std::set<K>,
const V>
operator*() {
160 assert(onEntry || !stack.empty());
162 for (
typename stack_ty::iterator it = stack.begin(), ie = stack.end();
164 s.insert((*it)->first);
165 Node *n = stack.empty() ?
root : &stack.back()->second;
166 return std::make_pair(s, n->
value);
184 template<
class K,
class V>
187 template<
class K,
class V>
190 for (
auto const& element : set) {
191 n = &n->
children.insert(std::make_pair(element,
Node())).first->second;
197 template<
class K,
class V>
200 for (
typename std::set<K>::const_iterator it = set.begin(), ie = set.end();
202 typename Node::children_ty::iterator kit = n->
children.find(*it);
216 template<
class K,
class V>
220 template<
class K,
class V>
224 template<
class K,
class V>
225 template<
class Iterator,
class Vector>
227 const std::set<K> &accum,
230 Vector &resultsOut) {
232 resultsOut.push_back(std::make_pair(accum, n->
value));
235 for (Iterator it=begin; it!=end;) {
237 typename Node::children_ty::iterator kit = n->
children.find(elt);
240 std::set<K> nacc = accum;
242 findSubsets(&kit->second, nacc, it, end, resultsOut);
247 template<
class K,
class V>
249 std::vector< std::pair<std::set<K>,
251 findSubsets(&root, std::set<K>(), set.begin(), set.end(), resultOut);
254 template<
class K,
class V>
255 template<
class Iterator,
class Vector>
257 const std::set<K> &accum,
260 Vector &resultsOut) {
263 resultsOut.push_back(std::make_pair(accum, n->
value));
264 for (
typename Node::children_ty::iterator it = n->
children.begin(),
265 ie = n->
children.end(); it != ie; ++it) {
266 std::set<K> nacc = accum;
267 nacc.insert(it->first);
268 findSupersets(&it->second, nacc, begin, end, resultsOut);
272 Iterator next = begin;
274 for (
typename Node::children_ty::iterator it = n->
children.begin(),
275 ie = n->
children.end(); it != ie; ++it) {
276 std::set<K> nacc = accum;
277 nacc.insert(it->first);
278 if (elt==it->first) {
279 findSupersets(&it->second, nacc, next, end, resultsOut);
280 }
else if (it->first<elt) {
281 findSupersets(&it->second, nacc, begin, end, resultsOut);
289 template<
class K,
class V>
291 std::vector< std::pair<std::set<K>, V> > &resultOut) {
292 findSupersets(&root, std::set<K>(), set.begin(), set.end(), resultOut);
295 template<
class K,
class V>
296 template<
class Predicate>
298 typename std::set<K>::iterator begin,
299 typename std::set<K>::iterator end,
300 const Predicate &p) {
303 }
else if (begin==end) {
306 typename Node::children_ty::iterator kend = n->
children.end();
307 typename Node::children_ty::iterator
308 kbegin = n->
children.lower_bound(*begin);
309 typename std::set<K>::iterator it = begin;
313 while (*it < kbegin->first) {
318 if (*it == kbegin->first) {
320 V *res = findSubset(&kbegin->second, it, end, p);
324 while (kbegin->first < *it) {
333 template<
class K,
class V>
334 template<
class Predicate>
336 typename std::set<K>::iterator begin,
337 typename std::set<K>::iterator end,
338 const Predicate &p) {
342 for (
typename Node::children_ty::iterator it = n->
children.begin(),
343 ie = n->
children.end(); it != ie; ++it) {
344 V *res = findSuperset(&it->second, begin, end, p);
348 typename Node::children_ty::iterator kmid =
350 for (
typename Node::children_ty::iterator it = n->
children.begin(),
351 ie = n->
children.end(); it != ie; ++it) {
352 V *res = findSuperset(&it->second, begin, end, p);
355 if (kmid!=n->
children.end() && *begin==kmid->first) {
356 V *res = findSuperset(&kmid->second, ++begin, end, p);
363 template<
class K,
class V>
364 template<
class Predicate>
366 return findSuperset(&root, set.begin(), set.end(), p);
369 template<
class K,
class V>
370 template<
class Predicate>
372 return findSubset(&root, set.begin(), set.end(), p);
375 template<
class K,
class V>
377 root.isEndOfSet =
false;
379 root.children.clear();
std::map< K, Node > children
std::map< K, Node > children_ty
const std::pair< const std::set< K >, const V > operator*()
std::vector< typename std::map< K, Node >::iterator > stack_ty
bool operator==(const iterator &b)
bool operator!=(const iterator &b)
V * lookup(const std::set< K > &set)
V * findSuperset(const std::set< K > &set, const Predicate &p)
V * findSuperset(Node *n, typename std::set< K >::iterator begin, typename std::set< K >::iterator end, const Predicate &p)
void findSubsets(Node *n, const std::set< K > &accum, Iterator begin, Iterator end, Vector &resultsOut)
void insert(const std::set< K > &set, const V &value)
V * findSubset(Node *n, typename std::set< K >::iterator begin, typename std::set< K >::iterator end, const Predicate &p)
V * findSubset(const std::set< K > &set, const Predicate &p)
void supersets(const std::set< K > &set, std::vector< std::pair< std::set< K >, V > > &resultOut)
void subsets(const std::set< K > &set, std::vector< std::pair< std::set< K >, V > > &resultOut)
void findSupersets(Node *n, const std::set< K > &accum, Iterator begin, Iterator end, Vector &resultsOut)