Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_SPATIAL_HASHING_HASH_FUNCTIONS_SPATIAL_HASHING_SHIFTED_GOLDEN_MEAN_FUNCTION_H
00002 #define OPENTISSUE_COLLISION_SPATIAL_HASHING_HASH_FUNCTIONS_SPATIAL_HASHING_SHIFTED_GOLDEN_MEAN_FUNCTION_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <cassert>
00013
00014 namespace OpenTissue
00015 {
00016 namespace spatial_hashing
00017 {
00035 class ShiftedGoldenMeanHashFunction
00036 {
00037 protected:
00038
00039 size_t m_size;
00040
00041 public:
00042
00043 ShiftedGoldenMeanHashFunction()
00044 : m_size(1000)
00045 {};
00046
00047 ShiftedGoldenMeanHashFunction(size_t size)
00048 : m_size(size)
00049 {};
00050
00051 private:
00052
00053 size_t hash(size_t k) { return k*2654435769u; };
00054
00055 public:
00056
00057 size_t operator()( int i,int j, int k )
00058 {
00059 int hash_key = i ^ hash(j ^ hash(k));
00060 hash_key = hash_key % m_size;
00061 assert( hash_key >= 0 );
00062 assert( static_cast<size_t>(hash_key) < m_size );
00063 return hash_key;
00064 }
00065
00066 void resize(size_t new_size) { m_size = new_size ; }
00067 size_t size()const { return m_size; }
00068 };
00069
00070 }
00071
00072 }
00073
00074
00075 #endif