ImmutableSet.h

Go to the documentation of this file.
00001 //===-- ImmutableSet.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_IMMUTABLESET_H__
00011 #define __UTIL_IMMUTABLESET_H__
00012 
00013 #include <functional>
00014 
00015 #include "ImmutableTree.h"
00016 
00017 namespace klee {
00018   template<class T>
00019   struct _Identity {
00020     T &operator()(T &a) const { return a; }
00021     const T &operator()(const T &a) const { return a; }
00022   };
00023   
00024   template<class T, class CMP=std::less<T> >
00025   class ImmutableSet {
00026   public:
00027     typedef T key_type;
00028     typedef T value_type;
00029 
00030     typedef ImmutableTree<T, T, _Identity<T>, CMP> Tree;
00031     typedef typename Tree::iterator iterator;
00032 
00033   private:
00034     Tree elts;
00035 
00036     ImmutableSet(const Tree &b): elts(b) {}
00037 
00038   public:
00039     ImmutableSet() {}
00040     ImmutableSet(const ImmutableSet &b) : elts(b.elts) {}
00041     ~ImmutableSet() {}
00042 
00043     ImmutableSet &operator=(const ImmutableSet &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 &min() const { 
00055       return elts.min(); 
00056     }
00057     const value_type &max() const { 
00058       return elts.max(); 
00059     }
00060     unsigned size() { 
00061       return elts.size(); 
00062     }
00063 
00064     ImmutableSet insert(const value_type &value) const {
00065       return elts.insert(value); 
00066     }
00067     ImmutableSet replace(const value_type &value) const {
00068       return elts.replace(value); 
00069     }
00070     ImmutableSet remove(const key_type &key) const { 
00071       return elts.remove(key); 
00072     }
00073     ImmutableSet popMin(const value_type &valueOut) const { 
00074       return elts.popMin(valueOut); 
00075     }
00076     ImmutableSet popMax(const value_type &valueOut) const { 
00077       return elts.popMax(valueOut); 
00078     }
00079 
00080     iterator begin() const { 
00081       return elts.begin(); 
00082     }
00083     iterator end() const { 
00084       return elts.end(); 
00085     }
00086     iterator find(const key_type &key) const { 
00087       return elts.find(key); 
00088     }
00089     iterator lower_bound(const key_type &key) const { 
00090       return elts.lower_bound(key); 
00091     }
00092     iterator upper_bound(const key_type &key) const { 
00093       return elts.upper_bound(key); 
00094     }
00095 
00096     static unsigned getAllocated() { return Tree::allocated; }
00097   };
00098 
00099 }
00100 
00101 #endif

Generated on Fri Jun 5 03:31:31 2009 for klee by  doxygen 1.5.8