24 #ifndef GRAPHLAB_DHT_HPP
25 #define GRAPHLAB_DHT_HPP
27 #include <boost/functional/hash.hpp>
28 #include <boost/unordered_map.hpp>
29 #include <graphlab/parallel/pthread_tools.hpp>
30 #include <graphlab/rpc/dc_dist_object.hpp>
38 template <
typename KeyType,
typename ValueType>
42 typedef boost::unordered_map<size_t, ValueType> storage_type;
48 boost::hash<KeyType> hasher;
67 std::pair<bool, ValueType>
get(
const KeyType &key)
const {
70 const size_t hashvalue = hasher(key);
71 const size_t owningmachine = hashvalue % rpc.
numprocs();
72 std::pair<bool, ValueType> retval;
74 if (owningmachine == rpc.
dc().
procid()) {
77 typename storage_type::const_iterator iter = storage.find(hashvalue);
78 retval.first = iter != storage.end();
79 if (retval.first) retval.second = iter->second;
97 const size_t hashvalue = hasher(key);
98 const size_t owningmachine = hashvalue % rpc.
numprocs();
99 std::pair<bool, ValueType> retval;
101 if (owningmachine == rpc.
dc().
procid()) {
104 typename storage_type::const_iterator iter = storage.find(hashvalue);
105 retval.first = iter != storage.end();
106 if (retval.first) retval.second = iter->second;
122 void set(
const KeyType &key,
const ValueType &newval) {
124 const size_t hashvalue = hasher(key);
125 const size_t owningmachine = hashvalue % rpc.
numprocs();
128 if (owningmachine == rpc.
dc().
procid()) {
130 storage[hashvalue] = newval;
139 void print_stats()
const {
140 std::cerr << rpc.
calls_sent() <<
" calls sent\n";