BALL  1.4.1
hash.h
Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 
00005 #ifndef BALL_COMMON_HASH_H
00006 #define BALL_COMMON_HASH_H
00007 
00008 #ifndef BALL_COMMON_H
00009 # include <BALL/common.h>
00010 #endif
00011 
00012 #ifndef BALL_DATATYPE_STRING_H
00013 # include <BALL/DATATYPE/string.h>
00014 #endif
00015 
00016 namespace BALL 
00017 {
00025   template <typename T>
00026   class HashFunction
00027   {
00028     public:
00029     
00030     HashIndex operator () (const T& t) const
00031     {
00032       return Hash(t);
00033     }
00034   };
00035 
00039   
00042   BALL_EXPORT extern HashIndex hashPointer(void *const ptr);
00043 
00046   BALL_EXPORT extern HashIndex hashString(const char* str);
00047 
00050   BALL_EXPORT extern HashIndex hashPJWString(const char* str);
00051 
00054   BALL_EXPORT extern HashIndex hashElfString(const char* str);
00055 
00064   template <typename T>
00065   inline HashIndex Hash(const T& key)
00066   {
00067     return static_cast<HashIndex>((PointerSizeUInt)key);
00068   }
00069 
00074   BALL_EXPORT inline HashIndex Hash(const string& s)
00075   {
00076     return hashString(s.c_str());
00077   }
00078 
00083   BALL_EXPORT inline HashIndex Hash(const String& s)
00084   {
00085     return hashString(s.c_str());
00086   }
00087 
00091   BALL_EXPORT inline HashIndex Hash(void *const& ptr)
00092   {
00093     return hashPointer(ptr);
00094   }
00095 
00097     
00099 
00104   BALL_EXPORT HashIndex getNextPrime(HashIndex l);
00105 
00107 
00108 } // namespace BALL
00109 
00110 #endif // BALL_COMMON_HASH_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines