klee
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ImmutableMap.h
Go to the documentation of this file.
1 //===-- ImmutableMap.h ------------------------------------------*- C++ -*-===//
2 //
3 // The KLEE Symbolic Virtual Machine
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef __UTIL_IMMUTABLEMAP_H__
11 #define __UTIL_IMMUTABLEMAP_H__
12 
13 #include <functional>
14 
15 #include "ImmutableTree.h"
16 
17 namespace klee {
18  template<class V, class D>
19  struct _Select1st {
20  D &operator()(V &a) const { return a.first; }
21  const D &operator()(const V &a) const { return a.first; }
22  };
23 
24  template<class K, class D, class CMP=std::less<K> >
25  class ImmutableMap {
26  public:
27  typedef K key_type;
28  typedef std::pair<K,D> value_type;
29 
31  typedef typename Tree::iterator iterator;
32 
33  private:
35 
36  ImmutableMap(const Tree &b): elts(b) {}
37 
38  public:
40  ImmutableMap(const ImmutableMap &b) : elts(b.elts) {}
42 
43  ImmutableMap &operator=(const ImmutableMap &b) { elts = b.elts; return *this; }
44 
45  bool empty() const {
46  return elts.empty();
47  }
48  size_t count(const key_type &key) const {
49  return elts.count(key);
50  }
51  const value_type *lookup(const key_type &key) const {
52  return elts.lookup(key);
53  }
54  const value_type *lookup_previous(const key_type &key) const {
55  return elts.lookup_previous(key);
56  }
57  const value_type &min() const {
58  return elts.min();
59  }
60  const value_type &max() const {
61  return elts.max();
62  }
63  size_t size() const {
64  return elts.size();
65  }
66 
67  ImmutableMap insert(const value_type &value) const {
68  return elts.insert(value);
69  }
70  ImmutableMap replace(const value_type &value) const {
71  return elts.replace(value);
72  }
73  ImmutableMap remove(const key_type &key) const {
74  return elts.remove(key);
75  }
76  ImmutableMap popMin(const value_type &valueOut) const {
77  return elts.popMin(valueOut);
78  }
79  ImmutableMap popMax(const value_type &valueOut) const {
80  return elts.popMax(valueOut);
81  }
82 
83  iterator begin() const {
84  return elts.begin();
85  }
86  iterator end() const {
87  return elts.end();
88  }
89  iterator find(const key_type &key) const {
90  return elts.find(key);
91  }
92  iterator lower_bound(const key_type &key) const {
93  return elts.lower_bound(key);
94  }
95  iterator upper_bound(const key_type &key) const {
96  return elts.upper_bound(key);
97  }
98 
99  static size_t getAllocated() { return Tree::allocated; }
100  };
101 
102 }
103 
104 #endif
iterator end() const
ImmutableTree remove(const key_type &key) const
ImmutableTree< K, value_type, _Select1st< value_type, key_type >, CMP > Tree
Definition: ImmutableMap.h:30
iterator begin() const
ImmutableMap insert(const value_type &value) const
Definition: ImmutableMap.h:67
ImmutableTree insert(const value_type &value) const
const value_type & min() const
Definition: ImmutableMap.h:57
ImmutableMap & operator=(const ImmutableMap &b)
Definition: ImmutableMap.h:43
iterator lower_bound(const key_type &key) const
ImmutableMap popMin(const value_type &valueOut) const
Definition: ImmutableMap.h:76
ImmutableTree popMin(value_type &valueOut) const
const value_type * lookup_previous(const key_type &key) const
iterator lower_bound(const key_type &key) const
Definition: ImmutableMap.h:92
const value_type & max() const
Definition: ImmutableMap.h:60
const value_type * lookup(const key_type &key) const
size_t count(const key_type &key) const
Definition: ImmutableMap.h:48
ImmutableTree replace(const value_type &value) const
const value_type & max() const
ImmutableTree popMax(value_type &valueOut) const
ImmutableMap(const ImmutableMap &b)
Definition: ImmutableMap.h:40
const D & operator()(const V &a) const
Definition: ImmutableMap.h:21
ImmutableMap(const Tree &b)
Definition: ImmutableMap.h:36
size_t size() const
ImmutableMap popMax(const value_type &valueOut) const
Definition: ImmutableMap.h:79
ImmutableMap replace(const value_type &value) const
Definition: ImmutableMap.h:70
bool empty() const
Definition: ImmutableMap.h:45
iterator find(const key_type &key) const
iterator find(const key_type &key) const
Definition: ImmutableMap.h:89
static size_t getAllocated()
Definition: ImmutableMap.h:99
size_t size() const
Definition: ImmutableMap.h:63
D & operator()(V &a) const
Definition: ImmutableMap.h:20
const value_type * lookup(const key_type &key) const
Definition: ImmutableMap.h:51
const value_type * lookup_previous(const key_type &key) const
Definition: ImmutableMap.h:54
iterator upper_bound(const key_type &key) const
Definition: ImmutableMap.h:95
Tree::iterator iterator
Definition: ImmutableMap.h:31
bool empty() const
iterator end() const
Definition: ImmutableMap.h:86
iterator begin() const
Definition: ImmutableMap.h:83
const value_type & min() const
iterator upper_bound(const key_type &key) const
std::pair< K, D > value_type
Definition: ImmutableMap.h:28
size_t count(const key_type &key) const