00001 //===-- ImmutableMap.h ------------------------------------------*- C++ -*-===// 00002 // 00003 // The KLEE Symbolic Virtual Machine 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef __UTIL_IMMUTABLEMAP_H__ 00011 #define __UTIL_IMMUTABLEMAP_H__ 00012 00013 #include <functional> 00014 00015 #include "ImmutableTree.h" 00016 00017 namespace klee { 00018 template<class V, class D> 00019 struct _Select1st { 00020 D &operator()(V &a) const { return a.first; } 00021 const D &operator()(const V &a) const { return a.first; } 00022 }; 00023 00024 template<class K, class D, class CMP=std::less<K> > 00025 class ImmutableMap { 00026 public: 00027 typedef K key_type; 00028 typedef std::pair<K,D> value_type; 00029 00030 typedef ImmutableTree<K, value_type, _Select1st<value_type,key_type>, CMP> Tree; 00031 typedef typename Tree::iterator iterator; 00032 00033 private: 00034 Tree elts; 00035 00036 ImmutableMap(const Tree &b): elts(b) {} 00037 00038 public: 00039 ImmutableMap() {} 00040 ImmutableMap(const ImmutableMap &b) : elts(b.elts) {} 00041 ~ImmutableMap() {} 00042 00043 ImmutableMap &operator=(const ImmutableMap &b) { elts = b.elts; return *this; } 00044 00045 bool empty() const { 00046 return elts.empty(); 00047 } 00048 unsigned count(const key_type &key) const { 00049 return elts.count(key); 00050 } 00051 const value_type *lookup(const key_type &key) const { 00052 return elts.lookup(key); 00053 } 00054 const value_type *lookup_previous(const key_type &key) const { 00055 return elts.lookup_previous(key); 00056 } 00057 const value_type &min() const { 00058 return elts.min(); 00059 } 00060 const value_type &max() const { 00061 return elts.max(); 00062 } 00063 unsigned size() const { 00064 return elts.size(); 00065 } 00066 00067 ImmutableMap insert(const value_type &value) const { 00068 return elts.insert(value); 00069 } 00070 ImmutableMap replace(const value_type &value) const { 00071 return elts.replace(value); 00072 } 00073 ImmutableMap remove(const key_type &key) const { 00074 return elts.remove(key); 00075 } 00076 ImmutableMap popMin(const value_type &valueOut) const { 00077 return elts.popMin(valueOut); 00078 } 00079 ImmutableMap popMax(const value_type &valueOut) const { 00080 return elts.popMax(valueOut); 00081 } 00082 00083 iterator begin() const { 00084 return elts.begin(); 00085 } 00086 iterator end() const { 00087 return elts.end(); 00088 } 00089 iterator find(const key_type &key) const { 00090 return elts.find(key); 00091 } 00092 iterator lower_bound(const key_type &key) const { 00093 return elts.lower_bound(key); 00094 } 00095 iterator upper_bound(const key_type &key) const { 00096 return elts.upper_bound(key); 00097 } 00098 00099 static unsigned getAllocated() { return Tree::allocated; } 00100 }; 00101 00102 } 00103 00104 #endif
1.5.8