Adds parallel junction map test cases
[junction.git] / junction / MapTraits.h
1 /*------------------------------------------------------------------------
2   Junction: Concurrent data structures in C++
3   Copyright (c) 2016 Jeff Preshing
4
5   Distributed under the Simplified BSD License.
6   Original location: https://github.com/preshing/junction
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the LICENSE file for more information.
11 ------------------------------------------------------------------------*/
12
13 #ifndef JUNCTION_MAPTRAITS_H
14 #define JUNCTION_MAPTRAITS_H
15
16 #include <junction/Core.h>
17 #include <turf/Util.h>
18
19 namespace junction {
20
21 template <class T>
22 struct DefaultKeyTraits {
23     typedef T Key;
24     typedef typename turf::util::BestFit<T>::Unsigned Hash;
25     static const Key NullKey = Key(0);
26     static const Hash NullHash = Hash(0);
27     static Hash hash(T key) {
28         return turf::util::avalanche(Hash(key));
29     }
30     static Key dehash(Hash hash) {
31         return (T) turf::util::deavalanche(hash);
32     }
33 };
34
35 template <class T>
36 struct DefaultValueTraits {
37     typedef T Value;
38     typedef typename turf::util::BestFit<T>::Unsigned IntType;
39     static const IntType NullValue = 0;
40     static const IntType Redirect = 1;
41 };
42
43 } // namespace junction
44
45 #endif // JUNCTION_MAPTRAITS_H