hash_map.hh
Go to the documentation of this file.
00001 /* -*- C++ -*-
00002  * $Id: hash_map.hh 957 2005-03-07 16:01:20Z sjoyeux $
00003  */
00004 #ifndef UTILMM_HASH_MAP_HEADER
00005 # define UTILMM_HASH_MAP_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   
00029   template< typename Key, typename Data, class Hash = hash<Key>, 
00030             class Equal = std::equal_to<Key> >
00031   class hash_map {
00032   public:
00034     typedef Key  key_type;
00039     typedef Data data_type;
00047     typedef std::pair<Key const, Data> value_type;
00048 
00049   private:
00050     typedef hash_toolbox::table<key_type, value_type, select_1st<value_type>,
00051                                 Hash, Equal> container_type;
00052     typedef typename container_type::value_arg value_arg;
00053     typedef typename container_type::key_arg key_arg;
00054 
00055     container_type the_table;
00056     
00057   public:
00062     typedef typename container_type::iterator       iterator;
00067     typedef typename container_type::const_iterator const_iterator;
00068 
00073     void swap(hash_map &other) {
00074       the_table.swap(other.the_table);
00075     }
00076 
00081     size_t size() const {
00082       return the_table.size();
00083     }
00088     size_t max_size() const {
00089       return the_table.max_size();
00090     }
00091     
00096     bool empty() const {
00097       return the_table.empty();
00098     }
00099 
00104     iterator begin() {
00105       return the_table.begin();
00106     }
00111     iterator end() {
00112       return the_table.end();
00113     }
00118     const_iterator begin() const {
00119       return the_table.begin();
00120     }
00125     const_iterator end() const {
00126       return the_table.end();
00127     }
00128     
00139     iterator find(key_arg key) {
00140       return the_table.equal_range(key).first;
00141     }
00146     const_iterator find(key_arg key) const {
00147       return the_table.equal_range(key).first;
00148     }
00149 
00162     std::pair<iterator, bool> insert(value_arg val) {
00163       return the_table.insert_unique(val);
00164     }
00165 
00170     void erase(iterator const &first, iterator const &last) {
00171       the_table.erase(first, last);
00172     }
00179     void erase(iterator const &i) {
00180       if( end()!=i )
00181         erase(i, i+1);
00182     }
00189     void erase(key_arg key) {
00190       erase(find(key));
00191     }
00192     
00197     void clear() {
00198       the_table.clear();
00199     }
00200     
00201   }; // class utilmm::hash_map<>
00202 
00203 } // namespace utilmm
00204 
00205 #endif // UTILMM_HASH_MAP_HEADER
00206 


utilmm
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Wed Sep 16 2015 07:05:43