mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-30 03:17:15 +02:00
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]
This commit is contained in:
@ -23,8 +23,8 @@ but not the equality predicate. For example, if you wanted to use the
|
|||||||
[import src_code/dictionary.cpp]
|
[import src_code/dictionary.cpp]
|
||||||
[case_sensitive_dictionary_fnv]
|
[case_sensitive_dictionary_fnv]
|
||||||
|
|
||||||
An example implementation of FNV-1, and some other hash functions are supplied
|
There is an [@../../libs/unordered/examples/fnv1.hpp implementation
|
||||||
in the examples directory.
|
of FNV-1] in the examples directory.
|
||||||
|
|
||||||
If you wish to use a different equality function,
|
If you wish to use a different equality function,
|
||||||
you will also need to use a matching hash function. For
|
you will also need to use a matching hash function. For
|
||||||
|
10
doc/ref.xml
10
doc/ref.xml
@ -181,7 +181,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|||||||
<para>The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.</para>
|
<para>The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.</para>
|
||||||
</description>
|
</description>
|
||||||
</constructor>
|
</constructor>
|
||||||
<constructor>
|
<constructor specifiers="explicit">
|
||||||
<parameter name="a">
|
<parameter name="a">
|
||||||
<paramtype>Allocator const&</paramtype>
|
<paramtype>Allocator const&</paramtype>
|
||||||
</parameter>
|
</parameter>
|
||||||
@ -928,7 +928,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|||||||
<para>The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.</para>
|
<para>The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.</para>
|
||||||
</description>
|
</description>
|
||||||
</constructor>
|
</constructor>
|
||||||
<constructor>
|
<constructor specifiers="explicit">
|
||||||
<parameter name="a">
|
<parameter name="a">
|
||||||
<paramtype>Allocator const&</paramtype>
|
<paramtype>Allocator const&</paramtype>
|
||||||
</parameter>
|
</parameter>
|
||||||
@ -1685,7 +1685,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|||||||
<para>The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.</para>
|
<para>The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.</para>
|
||||||
</description>
|
</description>
|
||||||
</constructor>
|
</constructor>
|
||||||
<constructor>
|
<constructor specifiers="explicit">
|
||||||
<parameter name="a">
|
<parameter name="a">
|
||||||
<paramtype>Allocator const&</paramtype>
|
<paramtype>Allocator const&</paramtype>
|
||||||
</parameter>
|
</parameter>
|
||||||
@ -2483,7 +2483,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|||||||
<para>The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.</para>
|
<para>The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.</para>
|
||||||
</description>
|
</description>
|
||||||
</constructor>
|
</constructor>
|
||||||
<constructor>
|
<constructor specifiers="explicit">
|
||||||
<parameter name="a">
|
<parameter name="a">
|
||||||
<paramtype>Allocator const&</paramtype>
|
<paramtype>Allocator const&</paramtype>
|
||||||
</parameter>
|
</parameter>
|
||||||
@ -3062,4 +3062,4 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|||||||
</class>
|
</class>
|
||||||
</namespace>
|
</namespace>
|
||||||
</header>
|
</header>
|
||||||
</library-reference>
|
</library-reference>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <boost/unordered_map.hpp>
|
#include <boost/unordered_map.hpp>
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include "../../examples/hash_functions/fnv-1.hpp"
|
#include "../../examples/fnv1.hpp"
|
||||||
|
|
||||||
//[case_insensitive_functions
|
//[case_insensitive_functions
|
||||||
struct iequal_to
|
struct iequal_to
|
||||||
|
66
examples/fnv1.hpp
Normal file
66
examples/fnv1.hpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
|
||||||
|
// Copyright 2008 Daniel James.
|
||||||
|
// 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;
|
||||||
|
// const std::size_t fnv_offset_basis = 275519064689413815358837431229664493455u;
|
||||||
|
|
||||||
|
// For 256 bit machines:
|
||||||
|
// const std::size_t fnv_prime = 374144419156711147060143317175368453031918731002211u;
|
||||||
|
// const std::size_t fnv_offset_basis = 100029257958052580907070968620625704837092796014241193945225284501741471925557u;
|
||||||
|
|
||||||
|
typedef basic_fnv_1<fnv_prime, fnv_offset_basis> fnv_1;
|
||||||
|
typedef basic_fnv_1a<fnv_prime, fnv_offset_basis> fnv_1a;
|
||||||
|
}
|
@ -1,71 +0,0 @@
|
|||||||
|
|
||||||
// Copyright 2008 Daniel James.
|
|
||||||
// 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)
|
|
||||||
|
|
||||||
// Algorithm from: http://www.isthe.com/chongo/tech/comp/fnv/
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace hash
|
|
||||||
{
|
|
||||||
template <std::size_t FnvPrime, std::size_t OffsetBias>
|
|
||||||
struct basic_fnv_1
|
|
||||||
{
|
|
||||||
std::size_t operator()(std::string const& text) const
|
|
||||||
{
|
|
||||||
std::size_t hash = OffsetBias;
|
|
||||||
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 OffsetBias>
|
|
||||||
struct basic_fnv_1a
|
|
||||||
{
|
|
||||||
std::size_t operator()(std::string const& text) const
|
|
||||||
{
|
|
||||||
std::size_t hash = OffsetBias;
|
|
||||||
for(std::string::const_iterator it = text.begin(), end = text.end();
|
|
||||||
it != end; ++it)
|
|
||||||
{
|
|
||||||
hash ^= *it;
|
|
||||||
hash *= FnvPrime;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Select Bias & Prime base on the size of std::size_t.
|
|
||||||
//
|
|
||||||
// 32 bit FNV_prime = 16777619
|
|
||||||
// 64 bit FNV_prime = 1099511628211
|
|
||||||
// 128 bit FNV_prime = 309485009821345068724781401
|
|
||||||
// 256 bit FNV_prime = 374144419156711147060143317175368453031918731002211
|
|
||||||
//
|
|
||||||
// 32 bit offset_basis = 2166136261
|
|
||||||
// 64 bit offset_basis = 14695981039346656037
|
|
||||||
// 128 bit offset_basis = 275519064689413815358837431229664493455
|
|
||||||
// 256 bit offset_basis = 100029257958052580907070968620625704837092796014241193945225284501741471925557
|
|
||||||
|
|
||||||
const std::size_t fnv_prime = 16777619;
|
|
||||||
// 64 bit FNV_prime = 1099511628211
|
|
||||||
// 128 bit FNV_prime = 309485009821345068724781401
|
|
||||||
// 256 bit FNV_prime = 374144419156711147060143317175368453031918731002211
|
|
||||||
|
|
||||||
const std::size_t fnv_offset_bias = 2166136261u;
|
|
||||||
// 64 bit offset_basis = 14695981039346656037
|
|
||||||
// 128 bit offset_basis = 275519064689413815358837431229664493455
|
|
||||||
// 256 bit offset_basis = 100029257958052580907070968620625704837092796014241193945225284501741471925557
|
|
||||||
|
|
||||||
typedef basic_fnv_1<fnv_prime, fnv_offset_bias> fnv_1;
|
|
||||||
typedef basic_fnv_1a<fnv_prime, fnv_offset_bias> fnv_1a;
|
|
||||||
|
|
||||||
}
|
|
@ -107,8 +107,7 @@ namespace boost
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Should this be explicit?
|
explicit unordered_map(allocator_type const& a)
|
||||||
unordered_map(allocator_type const& a)
|
|
||||||
: base(boost::unordered_detail::default_initial_bucket_count,
|
: base(boost::unordered_detail::default_initial_bucket_count,
|
||||||
hasher(), key_equal(), a)
|
hasher(), key_equal(), a)
|
||||||
{
|
{
|
||||||
@ -504,7 +503,7 @@ namespace boost
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
unordered_multimap(allocator_type const& a)
|
explicit unordered_multimap(allocator_type const& a)
|
||||||
: base(boost::unordered_detail::default_initial_bucket_count,
|
: base(boost::unordered_detail::default_initial_bucket_count,
|
||||||
hasher(), key_equal(), a)
|
hasher(), key_equal(), a)
|
||||||
{
|
{
|
||||||
|
@ -104,8 +104,7 @@ namespace boost
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Should this be explicit?
|
explicit unordered_set(allocator_type const& a)
|
||||||
unordered_set(allocator_type const& a)
|
|
||||||
: base(boost::unordered_detail::default_initial_bucket_count,
|
: base(boost::unordered_detail::default_initial_bucket_count,
|
||||||
hasher(), key_equal(), a)
|
hasher(), key_equal(), a)
|
||||||
{
|
{
|
||||||
@ -473,8 +472,7 @@ namespace boost
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Should this be explicit?
|
explicit unordered_multiset(allocator_type const& a)
|
||||||
unordered_multiset(allocator_type const& a)
|
|
||||||
: base(boost::unordered_detail::default_initial_bucket_count,
|
: base(boost::unordered_detail::default_initial_bucket_count,
|
||||||
hasher(), key_equal(), a)
|
hasher(), key_equal(), a)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user