]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/include/backward/hashtable.h
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / include / backward / hashtable.h
index ca04c76fd37bb2a08c4f879d105d3936c198769a..86121af8c37b816d4296a7bec28bc7c71e53bd3b 100644 (file)
@@ -1,7 +1,6 @@
 // Hashtable implementation used by containers -*- C++ -*-
 
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
-// Free Software Foundation, Inc.
+// Copyright (C) 2001-2014 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -54,8 +53,8 @@
  *  containing extensions from the HP/SGI STL subset).
  */
 
-#ifndef _HASHTABLE_H
-#define _HASHTABLE_H 1
+#ifndef _BACKWARD_HASHTABLE_H
+#define _BACKWARD_HASHTABLE_H 1
 
 // Hashtable class, used to implement the hashed associative containers
 // hash_set, hash_map, hash_multiset, and hash_multimap.
@@ -66,7 +65,9 @@
 #include <bits/stl_function.h>
 #include <backward/hash_fun.h>
 
-_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
+namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   using std::size_t;
   using std::ptrdiff_t;
@@ -207,7 +208,17 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
   // Note: assumes long is at least 32 bits.
   enum { _S_num_primes = 29 };
 
-  static const unsigned long __stl_prime_list[_S_num_primes] =
+  template<typename _PrimeType>
+    struct _Hashtable_prime_list
+    {
+      static const _PrimeType  __stl_prime_list[_S_num_primes];
+
+      static const _PrimeType*
+      _S_get_prime_list();
+    };
+
+  template<typename _PrimeType> const _PrimeType
+  _Hashtable_prime_list<_PrimeType>::__stl_prime_list[_S_num_primes] =
     {
       5ul,          53ul,         97ul,         193ul,       389ul,
       769ul,        1543ul,       3079ul,       6151ul,      12289ul,
@@ -217,11 +228,17 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
       805306457ul,  1610612741ul, 3221225473ul, 4294967291ul
     };
 
+ template<class _PrimeType> inline const _PrimeType*
+ _Hashtable_prime_list<_PrimeType>::_S_get_prime_list()
+ {
+   return __stl_prime_list;
+ }
+
   inline unsigned long
   __stl_next_prime(unsigned long __n)
   {
-    const unsigned long* __first = __stl_prime_list;
-    const unsigned long* __last = __stl_prime_list + (int)_S_num_primes;
+    const unsigned long* __first = _Hashtable_prime_list<unsigned long>::_S_get_prime_list();
+    const unsigned long* __last = __first + (int)_S_num_primes;
     const unsigned long* pos = std::lower_bound(__first, __last, __n);
     return pos == __last ? *(__last - 1) : *pos;
   }
@@ -415,7 +432,9 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
 
       size_type
       max_bucket_count() const
-      { return __stl_prime_list[(int)_S_num_primes - 1]; }
+      { return _Hashtable_prime_list<unsigned long>::
+               _S_get_prime_list()[(int)_S_num_primes - 1];
+      }
 
       size_type
       elems_in_bucket(size_type __bucket) const
@@ -896,13 +915,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
                  __next = __cur->_M_next;
                }
            }
-         if (_M_equals(_M_get_key(__first->_M_val), __key))
-           {
-             _M_buckets[__n] = __first->_M_next;
-             _M_delete_node(__first);
-             ++__erased;
-             --_M_num_elements;
-           }
+         bool __delete_first = _M_equals(_M_get_key(__first->_M_val), __key);
          if (__saved_slot)
            {
              __next = __saved_slot->_M_next;
@@ -911,6 +924,13 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
              ++__erased;
              --_M_num_elements;
            }
+         if (__delete_first)
+           {
+             _M_buckets[__n] = __first->_M_next;
+             _M_delete_node(__first);
+             ++__erased;
+             --_M_num_elements;
+           }
        }
       return __erased;
     }
@@ -1141,6 +1161,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
        }
     }
 
-_GLIBCXX_END_NAMESPACE
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
 
 #endif