Skip to content
Snippets Groups Projects
Commit 10e69621 authored by Christian Engwer's avatar Christian Engwer
Browse files

[hash]

Make bigunsignedint hashable using Dune::hash

This patch adds the required hooks to enable hashing of bigunsignedint
and makes sure the hasher can be invoked in bigunsignedinttest.

Making bigunsignedint hashable also makes it possible to use hash-based
containers for EntityIDs with YaspGrid and SGrid, as those grids implement
the EntityID as a plain bigunsignedint.

The patch also adds a little test to bigunsignedinttest, trying to hash
a bigunsignedint with Dune::hash as well as any of the detected backends
(std::hash and std::tr1::hash).

Kudos to Steffen Müthing, see FS#1192

[[Imported from SVN: r7066]]
parent 76733f41
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
#include <limits>
#include <cstdlib>
#include <dune/common/exceptions.hh>
#include <dune/common/hash.hh>
/**
* @file
......@@ -133,6 +134,15 @@ namespace Dune
friend class bigunsignedint<k/2>;
friend struct std::numeric_limits< bigunsignedint<k> >;
#if HAVE_DUNE_HASH
inline friend std::size_t hash_value(const bigunsignedint& arg)
{
return hash_range(arg.digit,arg.digit + arg.n);
}
#endif // HAVE_DUNE_HASH
private:
unsigned short digit[n];
#if HAVE_MPI
......@@ -628,4 +638,6 @@ namespace std
}
DUNE_DEFINE_HASH(DUNE_HASH_TEMPLATE_ARGS(int k),DUNE_HASH_TYPE(Dune::bigunsignedint<k>))
#endif
......@@ -63,6 +63,30 @@ int main()
b=a;
a=a*b*b;
std::cout<<a.todouble()<<std::endl;
#if HAVE_DUNE_HASH
{
Dune::hash<Dune::bigunsignedint<100> > hasher;
std::cout << "Dune::hash: " << hasher(a) << std::endl;
}
#if HAVE_STD_HASH
{
std::hash<Dune::bigunsignedint<100> > hasher;
std::cout << "std::hash: " << hasher(a) << std::endl;
}
#endif
#if HAVE_TR1_HASH
{
std::tr1::hash<Dune::bigunsignedint<100> > hasher;
std::cout << "std::tr1::hash: " << hasher(a) << std::endl;
}
#endif
#endif // HAVE_DUNE_HASH
}
catch(Dune::MathError e) {
std::cout<<e<<std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment