mirror of
https://github.com/boostorg/intrusive.git
synced 2025-07-30 20:47:36 +02:00
Use custom hash functions as Boost.ContainerHash requires C++11.
This commit is contained in:
@ -13,20 +13,27 @@
|
||||
#include <boost/intrusive/set.hpp>
|
||||
#include <boost/intrusive/unordered_set.hpp>
|
||||
#include <cstring>
|
||||
|
||||
using namespace boost::intrusive;
|
||||
#include <string>
|
||||
|
||||
// Hash function for strings
|
||||
struct StrHasher
|
||||
{
|
||||
std::size_t operator()(const char *str) const
|
||||
{
|
||||
//Simple example, use favorite hash function (like boost::hash_combine)
|
||||
std::size_t seed = 0;
|
||||
for(; *str; ++str) boost::hash_combine(seed, *str);
|
||||
for(; *str; ++str){
|
||||
std::size_t x = std::size_t(*str);
|
||||
x = ((x >> 16) ^ x) * 0x45d9f3b;
|
||||
x = (x >> 16) ^ x;
|
||||
seed += x;
|
||||
}
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
||||
using namespace boost::intrusive;
|
||||
|
||||
class Expensive : public set_base_hook<>, public unordered_set_base_hook<>
|
||||
{
|
||||
std::string key_;
|
||||
|
@ -11,7 +11,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//[doc_bucket_traits
|
||||
#include <boost/intrusive/unordered_set.hpp>
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
#include <vector>
|
||||
|
||||
using namespace boost::intrusive;
|
||||
@ -28,7 +27,9 @@ class MyClass : public unordered_set_base_hook<>
|
||||
friend bool operator==(const MyClass &l, const MyClass &r)
|
||||
{ return l.int_ == r.int_; }
|
||||
friend std::size_t hash_value(const MyClass &v)
|
||||
{ return boost::hash_value(v.int_); }
|
||||
{ //Use your favorite hash function, like boost::hash or std::hash
|
||||
return std::size_t(v.int_);
|
||||
}
|
||||
};
|
||||
|
||||
//Define the base hook option
|
||||
|
@ -12,7 +12,6 @@
|
||||
//[doc_iterator_from_value
|
||||
#include <boost/intrusive/list.hpp>
|
||||
#include <boost/intrusive/unordered_set.hpp>
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
#include <vector>
|
||||
|
||||
using namespace boost::intrusive;
|
||||
@ -39,7 +38,9 @@ class intrusive_data
|
||||
|
||||
//The hash function
|
||||
friend std::size_t hash_value(const intrusive_data &i)
|
||||
{ return boost::hash<int>()(i.data_id_); }
|
||||
{ //Use your favorite hash function, like boost::hash or std::hash
|
||||
return std::size_t(i.data_id_);
|
||||
}
|
||||
};
|
||||
|
||||
//Definition of the intrusive list that will hold intrusive_data
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include <boost/intrusive/unordered_set.hpp>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
|
||||
using namespace boost::intrusive;
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include<boost/intrusive/splaytree.hpp>
|
||||
#include<boost/intrusive/treap.hpp>
|
||||
#include<boost/intrusive/hashtable.hpp>
|
||||
#include<boost/functional/hash.hpp>
|
||||
|
||||
#include <vector> //std::vector
|
||||
#include <cstddef> //std::size_t
|
||||
|
||||
@ -47,7 +47,7 @@ class MyClass : public any_base_hook<>
|
||||
{ return l.int_ == r.int_; }
|
||||
|
||||
friend std::size_t hash_value(const MyClass &o)
|
||||
{ return boost::hash<int>()(o.get()); }
|
||||
{ return std::size_t(o.get()); }
|
||||
|
||||
friend bool priority_order(const MyClass &a, const MyClass &b)
|
||||
{ return a.int_ < b.int_; }
|
||||
|
@ -11,7 +11,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#include <boost/intrusive/unordered_set.hpp>
|
||||
#include <boost/intrusive/detail/mpl.hpp>
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <vector>
|
||||
|
||||
@ -30,7 +29,7 @@ class MyClass : public unordered_set_base_hook<>
|
||||
{ return l.int_ == r.int_; }
|
||||
|
||||
friend std::size_t hash_value(const MyClass &v)
|
||||
{ return boost::hash_value(v.int_); }
|
||||
{ return std::size_t(v.int_); }
|
||||
};
|
||||
|
||||
struct uset_value_traits
|
||||
|
@ -53,7 +53,7 @@ class MyClass
|
||||
{ return l.int_ == r.int_; }
|
||||
|
||||
friend std::size_t hash_value(const MyClass &v)
|
||||
{ return boost::hash_value(v.int_); }
|
||||
{ return std::size_t(v.int_); }
|
||||
|
||||
friend bool priority_order(const MyClass &l, const MyClass &r)
|
||||
{ return l.int_ < r.int_; }
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include <boost/intrusive/slist.hpp>
|
||||
#include <boost/intrusive/set.hpp>
|
||||
#include <boost/intrusive/unordered_set.hpp>
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
|
||||
using namespace boost::intrusive;
|
||||
|
||||
|
@ -12,8 +12,6 @@
|
||||
#ifndef BOOST_INTRUSIVE_DETAIL_INT_HOLDER_HPP
|
||||
#define BOOST_INTRUSIVE_DETAIL_INT_HOLDER_HPP
|
||||
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
|
||||
//GCC has some false array_bounds warnings starting in GCC 12
|
||||
#if defined(BOOST_CLANG) || (defined(BOOST_GCC) && (BOOST_GCC >= 120000))
|
||||
#pragma GCC diagnostic push
|
||||
@ -88,10 +86,7 @@ struct int_holder
|
||||
{ return int_ != i; }
|
||||
|
||||
friend std::size_t hash_value(const int_holder &t)
|
||||
{
|
||||
boost::hash<int> hasher;
|
||||
return hasher((&t)->int_value());
|
||||
}
|
||||
{ return std::size_t((&t)->int_value()); }
|
||||
|
||||
int int_;
|
||||
};
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/intrusive/options.hpp>
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
#include <boost/intrusive/pointer_traits.hpp>
|
||||
#include "nonhook_node.hpp"
|
||||
#include "int_holder.hpp"
|
||||
@ -127,33 +126,8 @@ struct testvalue
|
||||
{ return other1.value_.int_ != other2; }
|
||||
|
||||
friend std::size_t hash_value(const testvalue&t)
|
||||
{
|
||||
boost::hash<int> hasher;
|
||||
return hasher((&t)->int_value());
|
||||
}
|
||||
/*
|
||||
static std::size_t priority_hash(const testvalue &t)
|
||||
{ return boost::hash<int>()((&t)->int_value()); }
|
||||
{ return hash_value(t.value_); }
|
||||
|
||||
static std::size_t priority_hash(int i)
|
||||
{ return boost::hash<int>()(i); }
|
||||
|
||||
template <class T, class U>
|
||||
static bool priority_order_impl(const T& t1, const U& t2)
|
||||
{
|
||||
std::size_t hash1 = (priority_hash)(t1);
|
||||
boost::hash_combine(hash1, -hash1);
|
||||
std::size_t hash2 = (priority_hash)(t2);
|
||||
boost::hash_combine(hash2, -hash2);
|
||||
return hash1 < hash2;
|
||||
}
|
||||
|
||||
friend bool priority_order(const testvalue &t1, int t2)
|
||||
{ return (priority_order_impl)(t1, t2); }
|
||||
|
||||
friend bool priority_order(int t1, const testvalue &t2)
|
||||
{ return (priority_order_impl)(t1, t2); }
|
||||
*/
|
||||
template < typename Node_Algorithms >
|
||||
friend void swap_nodes(testvalue& lhs, testvalue& rhs)
|
||||
{ lhs.swap_nodes(rhs); }
|
||||
@ -163,17 +137,6 @@ struct testvalue
|
||||
{ return s << t.value_.int_value(); }
|
||||
};
|
||||
|
||||
/*
|
||||
bool priority_order(int t1, int t2)
|
||||
{
|
||||
std::size_t hash1 = boost::hash<int>()(t1);
|
||||
boost::hash_combine(hash1, &t1);
|
||||
std::size_t hash2 = boost::hash<int>()(t2);
|
||||
boost::hash_combine(hash2, &t2);
|
||||
return hash1 < hash2;
|
||||
}
|
||||
*/
|
||||
|
||||
struct even_odd
|
||||
{
|
||||
template < typename key_type_1, typename key_type_2 >
|
||||
|
@ -71,7 +71,7 @@ class MyClass
|
||||
{ return l.int_ == r.int_; }
|
||||
|
||||
friend std::size_t hash_value(const MyClass &v)
|
||||
{ return boost::hash_value(v.int_); }
|
||||
{ return std::size_t(v.int_); }
|
||||
|
||||
friend bool priority_order(const MyClass &l, const MyClass &r)
|
||||
{ return l.int_ < r.int_; }
|
||||
|
@ -55,7 +55,7 @@ class MyClass
|
||||
{ return l.int_ == r.int_; }
|
||||
|
||||
friend std::size_t hash_value(const MyClass &v)
|
||||
{ return boost::hash_value(v.int_); }
|
||||
{ return std::size_t(v.int_); }
|
||||
|
||||
friend bool priority_order(const MyClass &l, const MyClass &r)
|
||||
{ return l.int_ < r.int_; }
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include <boost/intrusive/slist.hpp>
|
||||
#include <boost/intrusive/set.hpp>
|
||||
#include <boost/intrusive/unordered_set.hpp>
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
#include <boost/intrusive/pointer_traits.hpp>
|
||||
#include <vector>
|
||||
|
||||
@ -35,7 +34,7 @@ class MyClass
|
||||
{ return l.int_ == r.int_; }
|
||||
|
||||
friend std::size_t hash_value(const MyClass &v)
|
||||
{ return boost::hash_value(v.int_); }
|
||||
{ return std::size_t(v.int_); }
|
||||
};
|
||||
|
||||
template<class T, class NodeTraits>
|
||||
|
Reference in New Issue
Block a user