forked from boostorg/unordered
https://svn.boost.org/svn/boost/branches/unordered/trunk ................ r42887 | danieljames | 2008-01-20 21:32:04 +0000 (Sun, 20 Jan 2008) | 10 lines Merged revisions 42590-42664,42667-42697,42699-42723,42725-42855,42857-42881 via svnmerge from https://svn.boost.org/svn/boost/trunk ........ r42881 | danieljames | 2008-01-20 17:37:21 +0000 (Sun, 20 Jan 2008) | 1 line Include <new> to get std::bad_alloc. ........ ................ r42892 | danieljames | 2008-01-21 13:03:16 +0000 (Mon, 21 Jan 2008) | 1 line On some compilers the Rogue Wave/Apache stdcxx library doesn't have the normal std::distance, but instead has a variant that takes the result as the third parameter so it doesn't have to work out the type from the iterator. ................ r42893 | danieljames | 2008-01-21 13:07:58 +0000 (Mon, 21 Jan 2008) | 1 line Fix a typo in the last commit. ................ r42895 | danieljames | 2008-01-21 13:33:29 +0000 (Mon, 21 Jan 2008) | 1 line Remove tabs from the last checkin. ................ r42896 | danieljames | 2008-01-21 15:51:40 +0000 (Mon, 21 Jan 2008) | 1 line Use Boost config to tell when we have a std::distance function. Also, no need for a macro. ................ r42908 | danieljames | 2008-01-21 21:37:04 +0000 (Mon, 21 Jan 2008) | 1 line Use boost::long_long_type and boost::ulong_long_type. ................ r42921 | danieljames | 2008-01-23 11:43:35 +0000 (Wed, 23 Jan 2008) | 1 line Remove some tabs. ................ r42922 | danieljames | 2008-01-23 11:46:28 +0000 (Wed, 23 Jan 2008) | 2 lines Add missing include. Refs #1596 ................ r42923 | danieljames | 2008-01-23 11:52:47 +0000 (Wed, 23 Jan 2008) | 2 lines Always use void const* for the second parameter of allocate. Refs #1596. ................ r42936 | danieljames | 2008-01-23 22:22:16 +0000 (Wed, 23 Jan 2008) | 1 line Use Boost style library name in the documentation. ................ r42937 | danieljames | 2008-01-23 22:22:32 +0000 (Wed, 23 Jan 2008) | 1 line More tabs. ................ r42941 | danieljames | 2008-01-23 23:35:01 +0000 (Wed, 23 Jan 2008) | 1 line Fix all the allocators. ................ [SVN r42943]
198 lines
6.7 KiB
C++
198 lines
6.7 KiB
C++
|
|
// Copyright (C) 2003-2004 Jeremy B. Maitin-Shepard.
|
|
// Copyright (C) 2005-2007 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)
|
|
|
|
#ifndef BOOST_UNORDERED_DETAIL_HASH_TABLE_HPP_INCLUDED
|
|
#define BOOST_UNORDERED_DETAIL_HASH_TABLE_HPP_INCLUDED
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
|
# pragma once
|
|
#endif
|
|
|
|
#include <boost/config.hpp>
|
|
|
|
#include <cstddef>
|
|
#include <cmath>
|
|
#include <algorithm>
|
|
#include <utility>
|
|
#include <stdexcept>
|
|
|
|
#include <boost/iterator.hpp>
|
|
#include <boost/iterator/iterator_categories.hpp>
|
|
#include <boost/limits.hpp>
|
|
#include <boost/assert.hpp>
|
|
#include <boost/static_assert.hpp>
|
|
#include <boost/unordered/detail/allocator.hpp>
|
|
#include <boost/type_traits/is_same.hpp>
|
|
#include <boost/mpl/if.hpp>
|
|
#include <boost/mpl/and.hpp>
|
|
#include <boost/detail/workaround.hpp>
|
|
|
|
#include <boost/mpl/aux_/config/eti.hpp>
|
|
|
|
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x0582)
|
|
#define BOOST_UNORDERED_BORLAND_BOOL(x) (bool)(x)
|
|
#else
|
|
#define BOOST_UNORDERED_BORLAND_BOOL(x) x
|
|
#endif
|
|
|
|
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
|
#define BOOST_UNORDERED_MSVC_RESET_PTR(x) unordered_detail::reset(x)
|
|
#else
|
|
#define BOOST_UNORDERED_MSVC_RESET_PTR(x)
|
|
#endif
|
|
|
|
namespace boost {
|
|
namespace unordered_detail {
|
|
template <class T> struct type_wrapper {};
|
|
|
|
static const std::size_t default_initial_bucket_count = 50;
|
|
static const float minimum_max_load_factor = 1e-3f;
|
|
inline std::size_t next_prime(std::size_t n);
|
|
|
|
template <class T>
|
|
inline void hash_swap(T& x, T& y)
|
|
{
|
|
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
|
|
std::swap(x,y);
|
|
#else
|
|
using std::swap;
|
|
swap(x, y);
|
|
#endif
|
|
}
|
|
|
|
inline std::size_t double_to_size_t(double f)
|
|
{
|
|
return f >= static_cast<double>((std::numeric_limits<std::size_t>::max)()) ?
|
|
(std::numeric_limits<std::size_t>::max)() :
|
|
static_cast<std::size_t>(f);
|
|
}
|
|
|
|
// prime number list, accessor
|
|
|
|
static const std::size_t prime_list[] = {
|
|
53ul, 97ul, 193ul, 389ul, 769ul,
|
|
1543ul, 3079ul, 6151ul, 12289ul, 24593ul,
|
|
49157ul, 98317ul, 196613ul, 393241ul, 786433ul,
|
|
1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul,
|
|
50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,
|
|
1610612741ul, 3221225473ul, 4294967291ul };
|
|
|
|
// no throw
|
|
inline std::size_t next_prime(std::size_t n) {
|
|
std::size_t const* const prime_list_end = prime_list +
|
|
sizeof(prime_list) / sizeof(*prime_list);
|
|
std::size_t const* bound =
|
|
std::lower_bound(prime_list,prime_list_end, n);
|
|
if(bound == prime_list_end)
|
|
bound--;
|
|
return *bound;
|
|
}
|
|
|
|
// no throw
|
|
inline std::size_t prev_prime(std::size_t n) {
|
|
std::size_t const* const prime_list_end = prime_list +
|
|
sizeof(prime_list) / sizeof(*prime_list);
|
|
std::size_t const* bound =
|
|
std::upper_bound(prime_list,prime_list_end, n);
|
|
if(bound != prime_list)
|
|
bound--;
|
|
return *bound;
|
|
}
|
|
|
|
// pair_cast - used to convert between pair types.
|
|
|
|
template <class Dst1, class Dst2, class Src1, class Src2>
|
|
inline std::pair<Dst1, Dst2> pair_cast(std::pair<Src1, Src2> const& x)
|
|
{
|
|
return std::pair<Dst1, Dst2>(Dst1(x.first), Dst2(x.second));
|
|
}
|
|
|
|
#if !defined(BOOST_NO_STD_DISTANCE)
|
|
using ::std::distance;
|
|
#else
|
|
template <class ForwardIterator>
|
|
inline std::size_t distance(ForwardIterator i, ForwardIterator j) {
|
|
std::size_t x;
|
|
std::distance(i, j, x);
|
|
return x;
|
|
}
|
|
#endif
|
|
|
|
}
|
|
}
|
|
|
|
#define BOOST_UNORDERED_EQUIVALENT_KEYS 1
|
|
#include <boost/unordered/detail/hash_table_impl.hpp>
|
|
#undef BOOST_UNORDERED_EQUIVALENT_KEYS
|
|
|
|
#define BOOST_UNORDERED_EQUIVALENT_KEYS 0
|
|
#include <boost/unordered/detail/hash_table_impl.hpp>
|
|
#undef BOOST_UNORDERED_EQUIVALENT_KEYS
|
|
|
|
namespace boost {
|
|
namespace unordered_detail {
|
|
class iterator_access
|
|
{
|
|
public:
|
|
template <class Iterator>
|
|
static BOOST_DEDUCED_TYPENAME Iterator::base const& get(Iterator const& it) {
|
|
return it.base_;
|
|
}
|
|
};
|
|
|
|
template <class ValueType, class KeyType,
|
|
class Hash, class Pred, class Alloc>
|
|
class hash_types_unique_keys
|
|
{
|
|
public:
|
|
typedef BOOST_DEDUCED_TYPENAME
|
|
boost::unordered_detail::rebind_wrap<Alloc, ValueType>::type
|
|
value_allocator;
|
|
|
|
typedef hash_table_unique_keys<ValueType, KeyType, Hash, Pred,
|
|
value_allocator> hash_table;
|
|
typedef hash_table_data_unique_keys<value_allocator> data;
|
|
typedef BOOST_DEDUCED_TYPENAME data::iterator_base iterator_base;
|
|
|
|
typedef hash_const_local_iterator_unique_keys<value_allocator> const_local_iterator;
|
|
typedef hash_local_iterator_unique_keys<value_allocator> local_iterator;
|
|
typedef hash_const_iterator_unique_keys<value_allocator> const_iterator;
|
|
typedef hash_iterator_unique_keys<value_allocator> iterator;
|
|
|
|
typedef BOOST_DEDUCED_TYPENAME data::size_type size_type;
|
|
typedef std::ptrdiff_t difference_type;
|
|
};
|
|
|
|
template <class ValueType, class KeyType,
|
|
class Hash, class Pred, class Alloc>
|
|
class hash_types_equivalent_keys
|
|
{
|
|
public:
|
|
typedef BOOST_DEDUCED_TYPENAME
|
|
boost::unordered_detail::rebind_wrap<Alloc, ValueType>::type
|
|
value_allocator;
|
|
|
|
typedef hash_table_equivalent_keys<ValueType, KeyType, Hash, Pred,
|
|
value_allocator> hash_table;
|
|
typedef hash_table_data_equivalent_keys<value_allocator> data;
|
|
typedef BOOST_DEDUCED_TYPENAME data::iterator_base iterator_base;
|
|
|
|
typedef hash_const_local_iterator_equivalent_keys<value_allocator> const_local_iterator;
|
|
typedef hash_local_iterator_equivalent_keys<value_allocator> local_iterator;
|
|
typedef hash_const_iterator_equivalent_keys<value_allocator> const_iterator;
|
|
typedef hash_iterator_equivalent_keys<value_allocator> iterator;
|
|
|
|
typedef BOOST_DEDUCED_TYPENAME data::size_type size_type;
|
|
typedef std::ptrdiff_t difference_type;
|
|
};
|
|
} // namespace boost::unordered_detail
|
|
} // namespace boost
|
|
|
|
#undef BOOST_UNORDERED_BORLAND_BOOL
|
|
#undef BOOST_UNORDERED_MSVC_RESET_PTR
|
|
|
|
#endif // BOOST_UNORDERED_DETAIL_HASH_TABLE_HPP_INCLUDED
|