hash_set.hh
Go to the documentation of this file.
00001 /* -*- C++ -*-
00002  * $Id: hash_set.hh 959 2005-03-11 13:19:19Z fpy $
00003  */
00004 #ifndef UTILMM_HASH_SET_HEADER
00005 # define UTILMM_HASH_SET_HEADER
00006 #include "utilmm/config/config.h"
00007 
00008 #include "utilmm/functional/utils.hh"
00009 
00010 #include "utilmm/hash/bits/table.hh"
00011 
00012 namespace utilmm {
00013   
00028   template< typename Key, class Hash = hash<Key>, 
00029             class Equal = std::equal_to<Key> >
00030   class hash_set {
00031   private:
00032     typedef identity<Key> key_extractor;
00033     typedef hash_toolbox::table< Key, Key const, key_extractor,
00034                                  Hash, Equal > container_type;
00035     typedef typename container_type::key_arg key_arg;
00036 
00037     container_type the_table;
00038     
00039   public:
00046     typedef typename container_type::value_type     value_type;
00051     typedef typename container_type::iterator       iterator;
00056     typedef typename container_type::const_iterator const_iterator;
00057 
00062     void swap(hash_set &other) {
00063       the_table.swap(other.the_table);
00064     }
00065 
00070     size_t size() const {
00071       return the_table.size();
00072     }
00077     size_t max_size() const {
00078       return the_table.max_size();
00079     }
00080     
00085     bool empty() const {
00086       return the_table.empty();
00087     }
00088 
00093     iterator begin() {
00094       return the_table.begin();
00095     }
00100     iterator end() {
00101       return the_table.end();
00102     }
00107     const_iterator begin() const {
00108       return the_table.begin();
00109     }
00114     const_iterator end() const {
00115       return the_table.end();
00116     }
00117 
00128     iterator find(key_arg key) {
00129       return the_table.equal_range(key).first;
00130     }
00135     const_iterator find(key_arg key) const {
00136       return the_table.equal_range(key).first;
00137     }
00138 
00148     iterator insert(key_arg key) {
00149       return the_table.insert_unique(key).first;
00150     }
00151 
00156     void erase(iterator const &first, iterator const &last) {
00157       the_table.erase(first, last);
00158     }
00165    void erase(iterator const &i) {
00166       if( end()!=i )
00167         erase(i, i+1);
00168     }
00175     void erase(key_arg key) {
00176       erase(find(key));
00177     }
00178     
00183     void clear() {
00184       the_table.clear();
00185     }
00186     
00187   }; // class utilmm::hash_set<>
00188   
00189 } // namespace utilmm
00190 
00191 #endif // UTILMM_HASH_SET_HEADER
00192 


utilmm
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Thu Jan 2 2014 11:38:31