"Fossies" - the Fresh Open Source Software Archive

Member "erltools/stl/hash_set.h" (25 Jul 1999, 11819 Bytes) of package /linux/misc/old/erltools-4.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "hash_set.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 1996
    3  * Silicon Graphics Computer Systems, Inc.
    4  *
    5  * Permission to use, copy, modify, distribute and sell this software
    6  * and its documentation for any purpose is hereby granted without fee,
    7  * provided that the above copyright notice appear in all copies and
    8  * that both that copyright notice and this permission notice appear
    9  * in supporting documentation.  Silicon Graphics makes no
   10  * representations about the suitability of this software for any
   11  * purpose.  It is provided "as is" without express or implied warranty.
   12  *
   13  *
   14  * Copyright (c) 1994
   15  * Hewlett-Packard Company
   16  *
   17  * Permission to use, copy, modify, distribute and sell this software
   18  * and its documentation for any purpose is hereby granted without fee,
   19  * provided that the above copyright notice appear in all copies and
   20  * that both that copyright notice and this permission notice appear
   21  * in supporting documentation.  Hewlett-Packard Company makes no
   22  * representations about the suitability of this software for any
   23  * purpose.  It is provided "as is" without express or implied warranty.
   24  *
   25  */
   26 
   27 #ifndef __SGI_STL_HASH_SET_H
   28 #define __SGI_STL_HASH_SET_H
   29 
   30 #ifndef __SGI_STL_HASHTABLE_H
   31 #include <hashtable.h>
   32 #endif /* __SGI_STL_HASHTABLE_H */
   33 
   34 #ifndef __STL_LIMITED_DEFAULT_TEMPLATES
   35 template <class Value, class HashFcn = hash<Value>,
   36           class EqualKey = equal_to<Value>,
   37           class Alloc = alloc>
   38 #else
   39 template <class Value, class HashFcn, class EqualKey, class Alloc = alloc>
   40 #endif
   41 class hash_set
   42 {
   43 private:
   44   typedef hashtable<Value, Value, HashFcn, identity<Value>, 
   45                     EqualKey, Alloc> ht;
   46   ht rep;
   47 
   48 public:
   49   typedef ht::key_type key_type;
   50   typedef ht::value_type value_type;
   51   typedef ht::hasher hasher;
   52   typedef ht::key_equal key_equal;
   53 
   54   typedef ht::size_type size_type;
   55   typedef ht::difference_type difference_type;
   56   typedef ht::const_pointer pointer;
   57   typedef ht::const_pointer const_pointer;
   58   typedef ht::const_reference reference;
   59   typedef ht::const_reference const_reference;
   60 
   61   typedef ht::const_iterator iterator;
   62   typedef ht::const_iterator const_iterator;
   63 
   64   hasher hash_funct() const { return rep.hash_funct(); }
   65   key_equal key_eq() const { return rep.key_eq(); }
   66 
   67 public:
   68   hash_set() : rep(100, hasher(), key_equal()) {}
   69   explicit hash_set(size_type n) : rep(n, hasher(), key_equal()) {}
   70   hash_set(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
   71   hash_set(size_type n, const hasher& hf, const key_equal& eql)
   72     : rep(n, hf, eql) {}
   73 
   74 #ifdef __STL_MEMBER_TEMPLATES
   75   template <class InputIterator>
   76   hash_set(InputIterator f, InputIterator l)
   77     : rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
   78   template <class InputIterator>
   79   hash_set(InputIterator f, InputIterator l, size_type n)
   80     : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
   81   template <class InputIterator>
   82   hash_set(InputIterator f, InputIterator l, size_type n,
   83            const hasher& hf)
   84     : rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
   85   template <class InputIterator>
   86   hash_set(InputIterator f, InputIterator l, size_type n,
   87            const hasher& hf, const key_equal& eql)
   88     : rep(n, hf, eql) { rep.insert_unique(f, l); }
   89 #else
   90 
   91   hash_set(const value_type* f, const value_type* l)
   92     : rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
   93   hash_set(const value_type* f, const value_type* l, size_type n)
   94     : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
   95   hash_set(const value_type* f, const value_type* l, size_type n,
   96            const hasher& hf)
   97     : rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
   98   hash_set(const value_type* f, const value_type* l, size_type n,
   99            const hasher& hf, const key_equal& eql)
  100     : rep(n, hf, eql) { rep.insert_unique(f, l); }
  101 
  102   hash_set(const_iterator f, const_iterator l)
  103     : rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
  104   hash_set(const_iterator f, const_iterator l, size_type n)
  105     : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
  106   hash_set(const_iterator f, const_iterator l, size_type n,
  107            const hasher& hf)
  108     : rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
  109   hash_set(const_iterator f, const_iterator l, size_type n,
  110            const hasher& hf, const key_equal& eql)
  111     : rep(n, hf, eql) { rep.insert_unique(f, l); }
  112 #endif /*__STL_MEMBER_TEMPLATES */
  113 
  114 public:
  115   size_type size() const { return rep.size(); }
  116   size_type max_size() const { return rep.max_size(); }
  117   bool empty() const { return rep.empty(); }
  118   void swap(hash_set& hs) { rep.swap(hs.rep); }
  119   friend bool operator==(const hash_set<Value,HashFcn,EqualKey,Alloc>&,
  120                          const hash_set<Value,HashFcn,EqualKey,Alloc>&);
  121 
  122   iterator begin() const { return rep.begin(); }
  123   iterator end() const { return rep.end(); }
  124 
  125 public:
  126   pair<iterator, bool> insert(const value_type& obj)
  127     {
  128       pair<ht::iterator, bool> p = rep.insert_unique(obj);
  129       return pair<iterator, bool>(p.first, p.second);
  130     }
  131 #ifdef __STL_MEMBER_TEMPLATES
  132   template <class InputIterator>
  133   void insert(InputIterator f, InputIterator l) { rep.insert_unique(f,l); }
  134 #else
  135   void insert(const value_type* f, const value_type* l) {
  136     rep.insert_unique(f,l);
  137   }
  138   void insert(const_iterator f, const_iterator l) {rep.insert_unique(f, l); }
  139 #endif /*__STL_MEMBER_TEMPLATES */
  140   pair<iterator, bool> insert_noresize(const value_type& obj)
  141     {
  142       pair<ht::iterator, bool> p = rep.insert_unique_noresize(obj);
  143       return pair<iterator, bool>(p.first, p.second);
  144     }
  145 
  146   iterator find(const key_type& key) const { return rep.find(key); }
  147 
  148   size_type count(const key_type& key) const { return rep.count(key); }
  149   
  150   pair<iterator, iterator> equal_range(const key_type& key) const
  151     { return rep.equal_range(key); }
  152 
  153   size_type erase(const key_type& key) {return rep.erase(key); }
  154   void erase(iterator it) { rep.erase(it); }
  155   void erase(iterator f, iterator l) { rep.erase(f, l); }
  156   void clear() { rep.clear(); }
  157 
  158 public:
  159   void resize(size_type hint) { rep.resize(hint); }
  160   size_type bucket_count() const { return rep.bucket_count(); }
  161   size_type max_bucket_count() const { return rep.max_bucket_count(); }
  162   size_type elems_in_bucket(size_type n) const
  163     { return rep.elems_in_bucket(n); }
  164 };
  165 
  166 template <class Value, class HashFcn, class EqualKey, class Alloc>
  167 inline bool operator==(const hash_set<Value, HashFcn, EqualKey, Alloc>& hs1,
  168                        const hash_set<Value, HashFcn, EqualKey, Alloc>& hs2)
  169 {
  170   return hs1.rep == hs2.rep;
  171 }
  172 
  173 #ifndef __STL_LIMITED_DEFAULT_TEMPLATES
  174 template <class Value, class HashFcn = hash<Value>,
  175           class EqualKey = equal_to<Value>,
  176           class Alloc = alloc>
  177 #else
  178 template <class Value, class HashFcn, class EqualKey, class Alloc = alloc>
  179 #endif
  180 class hash_multiset
  181 {
  182 private:
  183   typedef hashtable<Value, Value, HashFcn, identity<Value>, 
  184                     EqualKey, Alloc> ht;
  185   ht rep;
  186 
  187 public:
  188   typedef ht::key_type key_type;
  189   typedef ht::value_type value_type;
  190   typedef ht::hasher hasher;
  191   typedef ht::key_equal key_equal;
  192 
  193   typedef ht::size_type size_type;
  194   typedef ht::difference_type difference_type;
  195   typedef ht::const_pointer pointer;
  196   typedef ht::const_pointer const_pointer;
  197   typedef ht::const_reference reference;
  198   typedef ht::const_reference const_reference;
  199 
  200   typedef ht::const_iterator iterator;
  201   typedef ht::const_iterator const_iterator;
  202 
  203   hasher hash_funct() const { return rep.hash_funct(); }
  204   key_equal key_eq() const { return rep.key_eq(); }
  205 
  206 public:
  207   hash_multiset() : rep(100, hasher(), key_equal()) {}
  208   explicit hash_multiset(size_type n) : rep(n, hasher(), key_equal()) {}
  209   hash_multiset(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
  210   hash_multiset(size_type n, const hasher& hf, const key_equal& eql)
  211     : rep(n, hf, eql) {}
  212 
  213 #ifdef __STL_MEMBER_TEMPLATES
  214   template <class InputIterator>
  215   hash_multiset(InputIterator f, InputIterator l)
  216     : rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
  217   template <class InputIterator>
  218   hash_multiset(InputIterator f, InputIterator l, size_type n)
  219     : rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
  220   template <class InputIterator>
  221   hash_multiset(InputIterator f, InputIterator l, size_type n,
  222                 const hasher& hf)
  223     : rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
  224   template <class InputIterator>
  225   hash_multiset(InputIterator f, InputIterator l, size_type n,
  226                 const hasher& hf, const key_equal& eql)
  227     : rep(n, hf, eql) { rep.insert_equal(f, l); }
  228 #else
  229 
  230   hash_multiset(const value_type* f, const value_type* l)
  231     : rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
  232   hash_multiset(const value_type* f, const value_type* l, size_type n)
  233     : rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
  234   hash_multiset(const value_type* f, const value_type* l, size_type n,
  235                 const hasher& hf)
  236     : rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
  237   hash_multiset(const value_type* f, const value_type* l, size_type n,
  238                 const hasher& hf, const key_equal& eql)
  239     : rep(n, hf, eql) { rep.insert_equal(f, l); }
  240 
  241   hash_multiset(const_iterator f, const_iterator l)
  242     : rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
  243   hash_multiset(const_iterator f, const_iterator l, size_type n)
  244     : rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
  245   hash_multiset(const_iterator f, const_iterator l, size_type n,
  246                 const hasher& hf)
  247     : rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
  248   hash_multiset(const_iterator f, const_iterator l, size_type n,
  249                 const hasher& hf, const key_equal& eql)
  250     : rep(n, hf, eql) { rep.insert_equal(f, l); }
  251 #endif /*__STL_MEMBER_TEMPLATES */
  252 
  253 public:
  254   size_type size() const { return rep.size(); }
  255   size_type max_size() const { return rep.max_size(); }
  256   bool empty() const { return rep.empty(); }
  257   void swap(hash_multiset& hs) { rep.swap(hs.rep); }
  258   friend bool operator==(const hash_multiset<Value,HashFcn,EqualKey,Alloc>&,
  259                          const hash_multiset<Value,HashFcn,EqualKey,Alloc>&);
  260 
  261   iterator begin() const { return rep.begin(); }
  262   iterator end() const { return rep.end(); }
  263 
  264 public:
  265   iterator insert(const value_type& obj) { return rep.insert_equal(obj); }
  266 #ifdef __STL_MEMBER_TEMPLATES
  267   template <class InputIterator>
  268   void insert(InputIterator f, InputIterator l) { rep.insert_equal(f,l); }
  269 #else
  270   void insert(const value_type* f, const value_type* l) {
  271     rep.insert_equal(f,l);
  272   }
  273   void insert(const_iterator f, const_iterator l) { rep.insert_equal(f, l); }
  274 #endif /*__STL_MEMBER_TEMPLATES */
  275   iterator insert_noresize(const value_type& obj)
  276     { return rep.insert_equal_noresize(obj); }    
  277 
  278   iterator find(const key_type& key) const { return rep.find(key); }
  279 
  280   size_type count(const key_type& key) const { return rep.count(key); }
  281   
  282   pair<iterator, iterator> equal_range(const key_type& key) const
  283     { return rep.equal_range(key); }
  284 
  285   size_type erase(const key_type& key) {return rep.erase(key); }
  286   void erase(iterator it) { rep.erase(it); }
  287   void erase(iterator f, iterator l) { rep.erase(f, l); }
  288   void clear() { rep.clear(); }
  289 
  290 public:
  291   void resize(size_type hint) { rep.resize(hint); }
  292   size_type bucket_count() const { return rep.bucket_count(); }
  293   size_type max_bucket_count() const { return rep.max_bucket_count(); }
  294   size_type elems_in_bucket(size_type n) const
  295     { return rep.elems_in_bucket(n); }
  296 };
  297 
  298 template <class Val, class HashFcn, class EqualKey, class Alloc>
  299 inline bool operator==(const hash_multiset<Val, HashFcn, EqualKey, Alloc>& hs1,
  300                        const hash_multiset<Val, HashFcn, EqualKey, Alloc>& hs2)
  301 {
  302   return hs1.rep == hs2.rep;
  303 }
  304 
  305 
  306 #endif /* __SGI_STL_HASH_SET_H */