aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2010-02-25 13:32:52 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2010-02-25 13:32:52 +0000
commit640f8e65484943a0bc1c2c47cdbee438fc40b8ad (patch)
treeb9e6efc036872718e4cffb509db23e692c0321e5
parent0679656478759e3bfd02f6f0a4b22fd792b736d7 (diff)
downloadgcc-640f8e65484943a0bc1c2c47cdbee438fc40b8ad.zip
gcc-640f8e65484943a0bc1c2c47cdbee438fc40b8ad.tar.gz
gcc-640f8e65484943a0bc1c2c47cdbee438fc40b8ad.tar.bz2
functional_hash.h (__hash_combine): Remove.
2010-02-25 Paolo Carlini <paolo.carlini@oracle.com> * include/bits/functional_hash.h (__hash_combine): Remove. (_Fnv_hash_base<>::hash(const char*, size_t)): Add defaulted hash parameter. (_Fnv_hash::__hash_combine(const _Tp&, size_t)): Add. * include/std/system_error (hash<system_error>): Adjust. * src/compatibility-c++0x.cc (hash<system_error>): Likewise. From-SVN: r157065
-rw-r--r--libstdc++-v3/ChangeLog9
-rw-r--r--libstdc++-v3/include/bits/functional_hash.h49
-rw-r--r--libstdc++-v3/include/std/system_error2
-rw-r--r--libstdc++-v3/src/compatibility-c++0x.cc2
4 files changed, 33 insertions, 29 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 66d4120..d363282 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,12 @@
+2010-02-25 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/functional_hash.h (__hash_combine): Remove.
+ (_Fnv_hash_base<>::hash(const char*, size_t)): Add defaulted
+ hash parameter.
+ (_Fnv_hash::__hash_combine(const _Tp&, size_t)): Add.
+ * include/std/system_error (hash<system_error>): Adjust.
+ * src/compatibility-c++0x.cc (hash<system_error>): Likewise.
+
2010-02-24 Benjamin Kosnik <bkoz@redhat.com>
* doc/xml/faq.xml: Adjust structure for pdf index.
diff --git a/libstdc++-v3/include/bits/functional_hash.h b/libstdc++-v3/include/bits/functional_hash.h
index 8a29189..41fe11f 100644
--- a/libstdc++-v3/include/bits/functional_hash.h
+++ b/libstdc++-v3/include/bits/functional_hash.h
@@ -123,12 +123,11 @@ namespace std
struct _Fnv_hash_base
{
static size_t
- hash(const char* __first, size_t __length)
+ hash(const char* __first, size_t __length, size_t __hash = 0)
{
- size_t __result = 0;
- for (; __length > 0; --__length)
- __result = (__result * 131) + *__first++;
- return __result;
+ for (; __length; --__length)
+ __hash = (__hash * 131) + *__first++;
+ return __hash;
}
};
@@ -136,15 +135,15 @@ namespace std
struct _Fnv_hash_base<4>
{
static size_t
- hash(const char* __first, size_t __length)
+ hash(const char* __first, size_t __length,
+ size_t __hash = static_cast<size_t>(2166136261UL))
{
- size_t __result = static_cast<size_t>(2166136261UL);
- for (; __length > 0; --__length)
+ for (; __length; --__length)
{
- __result ^= static_cast<size_t>(*__first++);
- __result *= static_cast<size_t>(16777619UL);
+ __hash ^= static_cast<size_t>(*__first++);
+ __hash *= static_cast<size_t>(16777619UL);
}
- return __result;
+ return __hash;
}
};
@@ -152,16 +151,15 @@ namespace std
struct _Fnv_hash_base<8>
{
static size_t
- hash(const char* __first, size_t __length)
+ hash(const char* __first, size_t __length,
+ size_t __hash = static_cast<size_t>(14695981039346656037ULL))
{
- size_t __result =
- static_cast<size_t>(14695981039346656037ULL);
- for (; __length > 0; --__length)
+ for (; __length; --__length)
{
- __result ^= static_cast<size_t>(*__first++);
- __result *= static_cast<size_t>(1099511628211ULL);
+ __hash ^= static_cast<size_t>(*__first++);
+ __hash *= static_cast<size_t>(1099511628211ULL);
}
- return __result;
+ return __hash;
}
};
@@ -175,16 +173,13 @@ namespace std
hash(const _Tp& __val)
{ return hash(reinterpret_cast<const char*>(&__val),
sizeof(__val)); }
- };
- // Inspired by the Boost facility hash_combine.
- template<typename _Tp>
- inline size_t
- __hash_combine(size_t __hash, const _Tp& __val)
- {
- const size_t __tmp = std::_Fnv_hash::hash(__val);
- return __hash ^ (__tmp + 0x9e3779b9 + (__hash << 6) + (__hash >> 2));
- }
+ template<typename _Tp>
+ static size_t
+ __hash_combine(const _Tp& __val, size_t __hash)
+ { return hash(reinterpret_cast<const char*>(&__val),
+ sizeof(__val), __hash); }
+ };
/// Specialization for float.
template<>
diff --git a/libstdc++-v3/include/std/system_error b/libstdc++-v3/include/std/system_error
index 9b6eff8..920b9de 100644
--- a/libstdc++-v3/include/std/system_error
+++ b/libstdc++-v3/include/std/system_error
@@ -356,7 +356,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
operator()(const error_code& __e) const
{
const size_t __tmp = std::_Fnv_hash::hash(__e._M_value);
- return std::__hash_combine(__tmp, __e._M_cat);
+ return std::_Fnv_hash::__hash_combine(__e._M_cat, __tmp);
}
};
diff --git a/libstdc++-v3/src/compatibility-c++0x.cc b/libstdc++-v3/src/compatibility-c++0x.cc
index 7dd5768..759267a 100644
--- a/libstdc++-v3/src/compatibility-c++0x.cc
+++ b/libstdc++-v3/src/compatibility-c++0x.cc
@@ -57,6 +57,6 @@ namespace std
hash<error_code>::operator()(error_code __e) const
{
const size_t __tmp = std::_Fnv_hash::hash(__e._M_value);
- return std::__hash_combine(__tmp, __e._M_cat);
+ return std::_Fnv_hash::__hash_combine(__e._M_cat, __tmp);
}
}