BALL  1.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
hash.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_COMMON_HASH_H
6 #define BALL_COMMON_HASH_H
7 
8 #ifndef BALL_COMMON_H
9 # include <BALL/common.h>
10 #endif
11 
12 #ifndef BALL_DATATYPE_STRING_H
13 # include <BALL/DATATYPE/string.h>
14 #endif
15 
16 namespace BALL
17 {
25  template <typename T>
27  {
28  public:
29 
30  HashIndex operator () (const T& t) const
31  {
32  return Hash(t);
33  }
34  };
35 
39 
42  BALL_EXPORT extern HashIndex hashPointer(void *const ptr);
43 
46  BALL_EXPORT extern HashIndex hashString(const char* str);
47 
50  BALL_EXPORT extern HashIndex hashPJWString(const char* str);
51 
54  BALL_EXPORT extern HashIndex hashElfString(const char* str);
55 
64  template <typename T>
65  inline HashIndex Hash(const T& key)
66  {
67  return static_cast<HashIndex>((PointerSizeUInt)key);
68  }
69 
74  BALL_EXPORT inline HashIndex Hash(const string& s)
75  {
76  return hashString(s.c_str());
77  }
78 
83  BALL_EXPORT inline HashIndex Hash(const String& s)
84  {
85  return hashString(s.c_str());
86  }
87 
91  BALL_EXPORT inline HashIndex Hash(void *const& ptr)
92  {
93  return hashPointer(ptr);
94  }
95 
97 
99 
105 
107 
108 } // namespace BALL
109 
110 #endif // BALL_COMMON_HASH_H