home *** CD-ROM | disk | FTP | other *** search
/ Chip: 2001 Haziran / CHIP Haziran2001.iso / prog / share / 17 / dings_e.exe / Compiler / Include / stl_hash_map.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-08  |  13.2 KB  |  359 lines

  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. /* NOTE: This is an internal header file, included by other STL headers.
  28.  *   You should not attempt to use it directly.
  29.  */
  30.  
  31. #ifndef __SGI_STL_INTERNAL_HASH_MAP_H
  32. #define __SGI_STL_INTERNAL_HASH_MAP_H
  33.  
  34.  
  35. __STL_BEGIN_NAMESPACE
  36.  
  37. #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
  38. #pragma set woff 1174
  39. #endif
  40.  
  41. #ifndef __STL_LIMITED_DEFAULT_TEMPLATES
  42. template <class Key, class T, class HashFcn = hash<Key>,
  43.           class EqualKey = equal_to<Key>,
  44.           class Alloc = alloc>
  45. #else
  46. template <class Key, class T, class HashFcn, class EqualKey, 
  47.           class Alloc = alloc>
  48. #endif
  49. class hash_map
  50. {
  51. private:
  52.   typedef hashtable<pair<const Key, T>, Key, HashFcn,
  53.                     select1st<pair<const Key, T> >, EqualKey, Alloc> ht;
  54.   ht rep;
  55.  
  56. public:
  57.   typedef typename ht::key_type key_type;
  58.   typedef T data_type;
  59.   typedef T mapped_type;
  60.   typedef typename ht::value_type value_type;
  61.   typedef typename ht::hasher hasher;
  62.   typedef typename ht::key_equal key_equal;
  63.  
  64.   typedef typename ht::size_type size_type;
  65.   typedef typename ht::difference_type difference_type;
  66.   typedef typename ht::pointer pointer;
  67.   typedef typename ht::const_pointer const_pointer;
  68.   typedef typename ht::reference reference;
  69.   typedef typename ht::const_reference const_reference;
  70.  
  71.   typedef typename ht::iterator iterator;
  72.   typedef typename ht::const_iterator const_iterator;
  73.  
  74.   hasher hash_funct() const { return rep.hash_funct(); }
  75.   key_equal key_eq() const { return rep.key_eq(); }
  76.  
  77. public:
  78.   hash_map() : rep(100, hasher(), key_equal()) {}
  79.   explicit hash_map(size_type n) : rep(n, hasher(), key_equal()) {}
  80.   hash_map(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
  81.   hash_map(size_type n, const hasher& hf, const key_equal& eql)
  82.     : rep(n, hf, eql) {}
  83.  
  84. #ifdef __STL_MEMBER_TEMPLATES
  85.   template <class InputIterator>
  86.   hash_map(InputIterator f, InputIterator l)
  87.     : rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
  88.   template <class InputIterator>
  89.   hash_map(InputIterator f, InputIterator l, size_type n)
  90.     : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
  91.   template <class InputIterator>
  92.   hash_map(InputIterator f, InputIterator l, size_type n,
  93.            const hasher& hf)
  94.     : rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
  95.   template <class InputIterator>
  96.   hash_map(InputIterator f, InputIterator l, size_type n,
  97.            const hasher& hf, const key_equal& eql)
  98.     : rep(n, hf, eql) { rep.insert_unique(f, l); }
  99.  
  100. #else
  101.   hash_map(const value_type* f, const value_type* l)
  102.     : rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
  103.   hash_map(const value_type* f, const value_type* l, size_type n)
  104.     : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
  105.   hash_map(const value_type* f, const value_type* l, size_type n,
  106.            const hasher& hf)
  107.     : rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
  108.   hash_map(const value_type* f, const value_type* l, size_type n,
  109.            const hasher& hf, const key_equal& eql)
  110.     : rep(n, hf, eql) { rep.insert_unique(f, l); }
  111.  
  112.   hash_map(const_iterator f, const_iterator l)
  113.     : rep(100, hasher(), key_equal()) { rep.insert_unique(f, l); }
  114.   hash_map(const_iterator f, const_iterator l, size_type n)
  115.     : rep(n, hasher(), key_equal()) { rep.insert_unique(f, l); }
  116.   hash_map(const_iterator f, const_iterator l, size_type n,
  117.            const hasher& hf)
  118.     : rep(n, hf, key_equal()) { rep.insert_unique(f, l); }
  119.   hash_map(const_iterator f, const_iterator l, size_type n,
  120.            const hasher& hf, const key_equal& eql)
  121.     : rep(n, hf, eql) { rep.insert_unique(f, l); }
  122. #endif /*__STL_MEMBER_TEMPLATES */
  123.  
  124. public:
  125.   size_type size() const { return rep.size(); }
  126.   size_type max_size() const { return rep.max_size(); }
  127.   bool empty() const { return rep.empty(); }
  128.   void swap(hash_map& hs) { rep.swap(hs.rep); }
  129.   friend bool
  130.   operator== __STL_NULL_TMPL_ARGS (const hash_map&, const hash_map&);
  131.  
  132.   iterator begin() { return rep.begin(); }
  133.   iterator end() { return rep.end(); }
  134.   const_iterator begin() const { return rep.begin(); }
  135.   const_iterator end() const { return rep.end(); }
  136.  
  137. public:
  138.   pair<iterator, bool> insert(const value_type& obj)
  139.     { return rep.insert_unique(obj); }
  140. #ifdef __STL_MEMBER_TEMPLATES
  141.   template <class InputIterator>
  142.   void insert(InputIterator f, InputIterator l) { rep.insert_unique(f,l); }
  143. #else
  144.   void insert(const value_type* f, const value_type* l) {
  145.     rep.insert_unique(f,l);
  146.   }
  147.   void insert(const_iterator f, const_iterator l) { rep.insert_unique(f, l); }
  148. #endif /*__STL_MEMBER_TEMPLATES */
  149.   pair<iterator, bool> insert_noresize(const value_type& obj)
  150.     { return rep.insert_unique_noresize(obj); }    
  151.  
  152.   iterator find(const key_type& key) { return rep.find(key); }
  153.   const_iterator find(const key_type& key) const { return rep.find(key); }
  154.  
  155.   T& operator[](const key_type& key) {
  156.     return rep.find_or_insert(value_type(key, T())).second;
  157.   }
  158.  
  159.   size_type count(const key_type& key) const { return rep.count(key); }
  160.   
  161.   pair<iterator, iterator> equal_range(const key_type& key)
  162.     { return rep.equal_range(key); }
  163.   pair<const_iterator, const_iterator> equal_range(const key_type& key) const
  164.     { return rep.equal_range(key); }
  165.  
  166.   size_type erase(const key_type& key) {return rep.erase(key); }
  167.   void erase(iterator it) { rep.erase(it); }
  168.   void erase(iterator f, iterator l) { rep.erase(f, l); }
  169.   void clear() { rep.clear(); }
  170.  
  171. public:
  172.   void resize(size_type hint) { rep.resize(hint); }
  173.   size_type bucket_count() const { return rep.bucket_count(); }
  174.   size_type max_bucket_count() const { return rep.max_bucket_count(); }
  175.   size_type elems_in_bucket(size_type n) const
  176.     { return rep.elems_in_bucket(n); }
  177. };
  178.  
  179. template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
  180. inline bool operator==(const hash_map<Key, T, HashFcn, EqualKey, Alloc>& hm1,
  181.                        const hash_map<Key, T, HashFcn, EqualKey, Alloc>& hm2)
  182. {
  183.   return hm1.rep == hm2.rep;
  184. }
  185.  
  186. #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
  187.  
  188. template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
  189. inline void swap(hash_map<Key, T, HashFcn, EqualKey, Alloc>& hm1,
  190.                  hash_map<Key, T, HashFcn, EqualKey, Alloc>& hm2)
  191. {
  192.   hm1.swap(hm2);
  193. }
  194.  
  195. #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
  196.  
  197. #ifndef __STL_LIMITED_DEFAULT_TEMPLATES
  198. template <class Key, class T, class HashFcn = hash<Key>,
  199.           class EqualKey = equal_to<Key>,
  200.           class Alloc = alloc>
  201. #else
  202. template <class Key, class T, class HashFcn, class EqualKey,
  203.           class Alloc = alloc>
  204. #endif
  205. class hash_multimap
  206. {
  207. private:
  208.   typedef hashtable<pair<const Key, T>, Key, HashFcn,
  209.                     select1st<pair<const Key, T> >, EqualKey, Alloc> ht;
  210.   ht rep;
  211.  
  212. public:
  213.   typedef typename ht::key_type key_type;
  214.   typedef T data_type;
  215.   typedef T mapped_type;
  216.   typedef typename ht::value_type value_type;
  217.   typedef typename ht::hasher hasher;
  218.   typedef typename ht::key_equal key_equal;
  219.  
  220.   typedef typename ht::size_type size_type;
  221.   typedef typename ht::difference_type difference_type;
  222.   typedef typename ht::pointer pointer;
  223.   typedef typename ht::const_pointer const_pointer;
  224.   typedef typename ht::reference reference;
  225.   typedef typename ht::const_reference const_reference;
  226.  
  227.   typedef typename ht::iterator iterator;
  228.   typedef typename ht::const_iterator const_iterator;
  229.  
  230.   hasher hash_funct() const { return rep.hash_funct(); }
  231.   key_equal key_eq() const { return rep.key_eq(); }
  232.  
  233. public:
  234.   hash_multimap() : rep(100, hasher(), key_equal()) {}
  235.   explicit hash_multimap(size_type n) : rep(n, hasher(), key_equal()) {}
  236.   hash_multimap(size_type n, const hasher& hf) : rep(n, hf, key_equal()) {}
  237.   hash_multimap(size_type n, const hasher& hf, const key_equal& eql)
  238.     : rep(n, hf, eql) {}
  239.  
  240. #ifdef __STL_MEMBER_TEMPLATES
  241.   template <class InputIterator>
  242.   hash_multimap(InputIterator f, InputIterator l)
  243.     : rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
  244.   template <class InputIterator>
  245.   hash_multimap(InputIterator f, InputIterator l, size_type n)
  246.     : rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
  247.   template <class InputIterator>
  248.   hash_multimap(InputIterator f, InputIterator l, size_type n,
  249.                 const hasher& hf)
  250.     : rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
  251.   template <class InputIterator>
  252.   hash_multimap(InputIterator f, InputIterator l, size_type n,
  253.                 const hasher& hf, const key_equal& eql)
  254.     : rep(n, hf, eql) { rep.insert_equal(f, l); }
  255.  
  256. #else
  257.   hash_multimap(const value_type* f, const value_type* l)
  258.     : rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
  259.   hash_multimap(const value_type* f, const value_type* l, size_type n)
  260.     : rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
  261.   hash_multimap(const value_type* f, const value_type* l, size_type n,
  262.                 const hasher& hf)
  263.     : rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
  264.   hash_multimap(const value_type* f, const value_type* l, size_type n,
  265.                 const hasher& hf, const key_equal& eql)
  266.     : rep(n, hf, eql) { rep.insert_equal(f, l); }
  267.  
  268.   hash_multimap(const_iterator f, const_iterator l)
  269.     : rep(100, hasher(), key_equal()) { rep.insert_equal(f, l); }
  270.   hash_multimap(const_iterator f, const_iterator l, size_type n)
  271.     : rep(n, hasher(), key_equal()) { rep.insert_equal(f, l); }
  272.   hash_multimap(const_iterator f, const_iterator l, size_type n,
  273.                 const hasher& hf)
  274.     : rep(n, hf, key_equal()) { rep.insert_equal(f, l); }
  275.   hash_multimap(const_iterator f, const_iterator l, size_type n,
  276.                 const hasher& hf, const key_equal& eql)
  277.     : rep(n, hf, eql) { rep.insert_equal(f, l); }
  278. #endif /*__STL_MEMBER_TEMPLATES */
  279.  
  280. public:
  281.   size_type size() const { return rep.size(); }
  282.   size_type max_size() const { return rep.max_size(); }
  283.   bool empty() const { return rep.empty(); }
  284.   void swap(hash_multimap& hs) { rep.swap(hs.rep); }
  285.   friend bool
  286.   operator== __STL_NULL_TMPL_ARGS (const hash_multimap&, const hash_multimap&);
  287.  
  288.   iterator begin() { return rep.begin(); }
  289.   iterator end() { return rep.end(); }
  290.   const_iterator begin() const { return rep.begin(); }
  291.   const_iterator end() const { return rep.end(); }
  292.  
  293. public:
  294.   iterator insert(const value_type& obj) { return rep.insert_equal(obj); }
  295. #ifdef __STL_MEMBER_TEMPLATES
  296.   template <class InputIterator>
  297.   void insert(InputIterator f, InputIterator l) { rep.insert_equal(f,l); }
  298. #else
  299.   void insert(const value_type* f, const value_type* l) {
  300.     rep.insert_equal(f,l);
  301.   }
  302.   void insert(const_iterator f, const_iterator l) { rep.insert_equal(f, l); }
  303. #endif /*__STL_MEMBER_TEMPLATES */
  304.   iterator insert_noresize(const value_type& obj)
  305.     { return rep.insert_equal_noresize(obj); }    
  306.  
  307.   iterator find(const key_type& key) { return rep.find(key); }
  308.   const_iterator find(const key_type& key) const { return rep.find(key); }
  309.  
  310.   size_type count(const key_type& key) const { return rep.count(key); }
  311.   
  312.   pair<iterator, iterator> equal_range(const key_type& key)
  313.     { return rep.equal_range(key); }
  314.   pair<const_iterator, const_iterator> equal_range(const key_type& key) const
  315.     { return rep.equal_range(key); }
  316.  
  317.   size_type erase(const key_type& key) {return rep.erase(key); }
  318.   void erase(iterator it) { rep.erase(it); }
  319.   void erase(iterator f, iterator l) { rep.erase(f, l); }
  320.   void clear() { rep.clear(); }
  321.  
  322. public:
  323.   void resize(size_type hint) { rep.resize(hint); }
  324.   size_type bucket_count() const { return rep.bucket_count(); }
  325.   size_type max_bucket_count() const { return rep.max_bucket_count(); }
  326.   size_type elems_in_bucket(size_type n) const
  327.     { return rep.elems_in_bucket(n); }
  328. };
  329.  
  330. template <class Key, class T, class HF, class EqKey, class Alloc>
  331. inline bool operator==(const hash_multimap<Key, T, HF, EqKey, Alloc>& hm1,
  332.                        const hash_multimap<Key, T, HF, EqKey, Alloc>& hm2)
  333. {
  334.   return hm1.rep == hm2.rep;
  335. }
  336.  
  337. #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
  338.  
  339. template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
  340. inline void swap(hash_multimap<Key, T, HashFcn, EqualKey, Alloc>& hm1,
  341.                  hash_multimap<Key, T, HashFcn, EqualKey, Alloc>& hm2)
  342. {
  343.   hm1.swap(hm2);
  344. }
  345.  
  346. #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
  347.  
  348. #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
  349. #pragma reset woff 1174
  350. #endif
  351.  
  352. __STL_END_NAMESPACE
  353.  
  354. #endif /* __SGI_STL_INTERNAL_HASH_MAP_H */
  355.  
  356. // Local Variables:
  357. // mode:C++
  358. // End:
  359.