Make the unordered constructors from allocators explicit.
And clean of the FNV-1 example & documentation a little.
Merged revisions 47085,47132,47143-47146 via svnmerge from
https://svn.boost.org/svn/boost/trunk
........
r47085 | danieljames | 2008-07-04 23:57:20 +0100 (Fri, 04 Jul 2008) | 4 lines
Require explicit conversion from allocators.
(Not what it says in the draft standard, but I think that might be a defect).
........
r47132 | danieljames | 2008-07-06 13:41:09 +0100 (Sun, 06 Jul 2008) | 2 lines
'Bias' should be 'basis'.
........
r47143 | danieljames | 2008-07-06 22:06:52 +0100 (Sun, 06 Jul 2008) | 1 line
Clean up the FNV-1 comments.
........
r47144 | danieljames | 2008-07-06 22:07:31 +0100 (Sun, 06 Jul 2008) | 1 line
I've only got one hash function for release, so no need for its own directory.
........
r47145 | danieljames | 2008-07-06 22:08:11 +0100 (Sun, 06 Jul 2008) | 1 line
Remove the hash_functions directory (for now).
........
r47146 | danieljames | 2008-07-06 22:29:47 +0100 (Sun, 06 Jul 2008) | 1 line
Update the docs for the new location of FNV-1.
........
[SVN r47150]
2008-07-06 22:00:18 +00:00
|
|
|
|
Merge hash and unordered changes.
Remove deprecated headers, move hash_fwd.hpp into hash subdirectory. And
several minor internal changes.
Mostly minor internal details.
Merged revisions 51262-51263,51407-51409,51504-51505,51644-51646,51667 via svnmerge from
https://svn.boost.org/svn/boost/trunk
........
r51262 | danieljames | 2009-02-15 19:32:04 +0000 (Sun, 15 Feb 2009) | 1 line
Use the new 'boost:' links for the hash, unordered and quickbook documentation.
........
r51263 | danieljames | 2009-02-15 19:32:19 +0000 (Sun, 15 Feb 2009) | 2 lines
Don't copy images for the standalone hash and unordered documentation, was only
really required before the libraries were integrated into boost.
........
r51407 | danieljames | 2009-02-22 23:49:51 +0000 (Sun, 22 Feb 2009) | 1 line
Fix the hash dirname.
........
r51408 | danieljames | 2009-02-22 23:50:04 +0000 (Sun, 22 Feb 2009) | 1 line
Make copy_buckets and move_buckets member functions - so that calling them is a bit simpler.
........
r51409 | danieljames | 2009-02-22 23:50:20 +0000 (Sun, 22 Feb 2009) | 1 line
Move some of the data structure classes out of hash table data.
........
r51504 | danieljames | 2009-03-01 14:15:09 +0000 (Sun, 01 Mar 2009) | 1 line
Add missing return for operator=.
........
r51505 | danieljames | 2009-03-01 14:15:39 +0000 (Sun, 01 Mar 2009) | 3 lines
Make the sort stable.
Doesn't really matter, but it might as well be.
........
r51644 | danieljames | 2009-03-08 09:44:51 +0000 (Sun, 08 Mar 2009) | 1 line
Detab.
........
r51645 | danieljames | 2009-03-08 09:45:11 +0000 (Sun, 08 Mar 2009) | 4 lines
Move hash_fwd into the hash subdirectory.
I should have done this in the last release. But now all of the hash
implementation is in the hash subdirectory.
........
r51646 | danieljames | 2009-03-08 09:45:30 +0000 (Sun, 08 Mar 2009) | 3 lines
Remove deprecated headers.
Fixes #2412.
........
r51667 | danieljames | 2009-03-09 20:56:23 +0000 (Mon, 09 Mar 2009) | 1 line
Update copyright dates in hash and unordered.
........
[SVN r51729]
2009-03-11 22:51:09 +00:00
|
|
|
// Copyright 2008-2009 Daniel James.
|
Make the unordered constructors from allocators explicit.
And clean of the FNV-1 example & documentation a little.
Merged revisions 47085,47132,47143-47146 via svnmerge from
https://svn.boost.org/svn/boost/trunk
........
r47085 | danieljames | 2008-07-04 23:57:20 +0100 (Fri, 04 Jul 2008) | 4 lines
Require explicit conversion from allocators.
(Not what it says in the draft standard, but I think that might be a defect).
........
r47132 | danieljames | 2008-07-06 13:41:09 +0100 (Sun, 06 Jul 2008) | 2 lines
'Bias' should be 'basis'.
........
r47143 | danieljames | 2008-07-06 22:06:52 +0100 (Sun, 06 Jul 2008) | 1 line
Clean up the FNV-1 comments.
........
r47144 | danieljames | 2008-07-06 22:07:31 +0100 (Sun, 06 Jul 2008) | 1 line
I've only got one hash function for release, so no need for its own directory.
........
r47145 | danieljames | 2008-07-06 22:08:11 +0100 (Sun, 06 Jul 2008) | 1 line
Remove the hash_functions directory (for now).
........
r47146 | danieljames | 2008-07-06 22:29:47 +0100 (Sun, 06 Jul 2008) | 1 line
Update the docs for the new location of FNV-1.
........
[SVN r47150]
2008-07-06 22:00:18 +00:00
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
|
|
|
// This code is also released into the public domain.
|
|
|
|
|
|
|
|
// Algorithm from: http://www.isthe.com/chongo/tech/comp/fnv/
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace hash
|
|
|
|
{
|
|
|
|
template <std::size_t FnvPrime, std::size_t OffsetBasis>
|
|
|
|
struct basic_fnv_1
|
|
|
|
{
|
|
|
|
std::size_t operator()(std::string const& text) const
|
|
|
|
{
|
|
|
|
std::size_t hash = OffsetBasis;
|
|
|
|
for(std::string::const_iterator it = text.begin(), end = text.end();
|
|
|
|
it != end; ++it)
|
|
|
|
{
|
|
|
|
hash *= FnvPrime;
|
|
|
|
hash ^= *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <std::size_t FnvPrime, std::size_t OffsetBasis>
|
|
|
|
struct basic_fnv_1a
|
|
|
|
{
|
|
|
|
std::size_t operator()(std::string const& text) const
|
|
|
|
{
|
|
|
|
std::size_t hash = OffsetBasis;
|
|
|
|
for(std::string::const_iterator it = text.begin(), end = text.end();
|
|
|
|
it != end; ++it)
|
|
|
|
{
|
|
|
|
hash ^= *it;
|
|
|
|
hash *= FnvPrime;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// For 32 bit machines:
|
|
|
|
const std::size_t fnv_prime = 16777619u;
|
|
|
|
const std::size_t fnv_offset_basis = 2166136261u;
|
|
|
|
|
|
|
|
// For 64 bit machines:
|
|
|
|
// const std::size_t fnv_prime = 1099511628211u;
|
|
|
|
// const std::size_t fnv_offset_basis = 14695981039346656037u;
|
|
|
|
|
|
|
|
// For 128 bit machines:
|
|
|
|
// const std::size_t fnv_prime = 309485009821345068724781401u;
|
2010-01-08 05:39:54 +00:00
|
|
|
// const std::size_t fnv_offset_basis =
|
|
|
|
// 275519064689413815358837431229664493455u;
|
Make the unordered constructors from allocators explicit.
And clean of the FNV-1 example & documentation a little.
Merged revisions 47085,47132,47143-47146 via svnmerge from
https://svn.boost.org/svn/boost/trunk
........
r47085 | danieljames | 2008-07-04 23:57:20 +0100 (Fri, 04 Jul 2008) | 4 lines
Require explicit conversion from allocators.
(Not what it says in the draft standard, but I think that might be a defect).
........
r47132 | danieljames | 2008-07-06 13:41:09 +0100 (Sun, 06 Jul 2008) | 2 lines
'Bias' should be 'basis'.
........
r47143 | danieljames | 2008-07-06 22:06:52 +0100 (Sun, 06 Jul 2008) | 1 line
Clean up the FNV-1 comments.
........
r47144 | danieljames | 2008-07-06 22:07:31 +0100 (Sun, 06 Jul 2008) | 1 line
I've only got one hash function for release, so no need for its own directory.
........
r47145 | danieljames | 2008-07-06 22:08:11 +0100 (Sun, 06 Jul 2008) | 1 line
Remove the hash_functions directory (for now).
........
r47146 | danieljames | 2008-07-06 22:29:47 +0100 (Sun, 06 Jul 2008) | 1 line
Update the docs for the new location of FNV-1.
........
[SVN r47150]
2008-07-06 22:00:18 +00:00
|
|
|
|
|
|
|
// For 256 bit machines:
|
2010-01-08 05:39:54 +00:00
|
|
|
// const std::size_t fnv_prime =
|
|
|
|
// 374144419156711147060143317175368453031918731002211u;
|
|
|
|
// const std::size_t fnv_offset_basis =
|
|
|
|
// 100029257958052580907070968620625704837092796014241193945225284501741471925557u;
|
Make the unordered constructors from allocators explicit.
And clean of the FNV-1 example & documentation a little.
Merged revisions 47085,47132,47143-47146 via svnmerge from
https://svn.boost.org/svn/boost/trunk
........
r47085 | danieljames | 2008-07-04 23:57:20 +0100 (Fri, 04 Jul 2008) | 4 lines
Require explicit conversion from allocators.
(Not what it says in the draft standard, but I think that might be a defect).
........
r47132 | danieljames | 2008-07-06 13:41:09 +0100 (Sun, 06 Jul 2008) | 2 lines
'Bias' should be 'basis'.
........
r47143 | danieljames | 2008-07-06 22:06:52 +0100 (Sun, 06 Jul 2008) | 1 line
Clean up the FNV-1 comments.
........
r47144 | danieljames | 2008-07-06 22:07:31 +0100 (Sun, 06 Jul 2008) | 1 line
I've only got one hash function for release, so no need for its own directory.
........
r47145 | danieljames | 2008-07-06 22:08:11 +0100 (Sun, 06 Jul 2008) | 1 line
Remove the hash_functions directory (for now).
........
r47146 | danieljames | 2008-07-06 22:29:47 +0100 (Sun, 06 Jul 2008) | 1 line
Update the docs for the new location of FNV-1.
........
[SVN r47150]
2008-07-06 22:00:18 +00:00
|
|
|
|
|
|
|
typedef basic_fnv_1<fnv_prime, fnv_offset_basis> fnv_1;
|
|
|
|
typedef basic_fnv_1a<fnv_prime, fnv_offset_basis> fnv_1a;
|
|
|
|
}
|