libfaster API Documentation  Development Version
Super fast distributted computing
hasher.h
1 #include <string>
2 
3 namespace faster{
4  template <typename K>
5  class hasher{
6  private:
7  int _spectrum;
8  public:
9  hasher(int spectrum){
10  _spectrum = spectrum;
11  }
12  int get ( K key ){
13  return key % _spectrum;
14  //return ( key >> 6 ) % _spectrum;
15  }
16 
17  };
18  template <>
19  class hasher<float>{
20  private:
21  int _spectrum;
22  public:
23  hasher(int spectrum){
24  _spectrum = spectrum;
25  }
26  int get ( float key ){
27  return ((int) key) % _spectrum;
28  }
29 
30  };
31  template <>
32  class hasher<double>{
33  private:
34  int _spectrum;
35  public:
36  hasher(int spectrum){
37  _spectrum = spectrum;
38  }
39  int get ( double key ){
40  return ((long long) key) % _spectrum;
41  }
42 
43  };
44  template <>
45  class hasher<std::string>{
46  private:
47  int _spectrum;
48  public:
49  hasher(int spectrum){
50  _spectrum = spectrum;
51  }
52  int get ( std::string key ){
53  return ( key[0] ) % _spectrum;
54  }
55 
56  };
57 }
STL namespace.
libfaster main namespace
Definition: _workerFdd.h:11