GEL
2
GEL is a library for Geometry and Linear Algebra
|
00001 #ifndef __UTIL_HASHKEY_H 00002 #define __UTIL_HASHKEY_H 00003 00004 #include <stdlib.h> 00005 #include <limits.h> 00006 #include "CGLA/Vec3uc.h" 00007 #include "CGLA/Vec3usi.h" 00008 00009 namespace Util 00010 { 00011 00012 00013 extern int randoms1[UCHAR_MAX]; 00014 extern int randoms2[UCHAR_MAX]; 00015 extern int randoms3[UCHAR_MAX]; 00016 00017 bool init_randoms(); 00018 void do_init_randoms(); 00019 00020 struct HashKey3uc 00021 { 00022 CGLA::Vec3uc key; 00023 00024 HashKey3uc() {do_init_randoms();} 00025 HashKey3uc(CGLA::Vec3uc _key): key(_key) {do_init_randoms();} 00026 HashKey3uc(CGLA::Vec3i _key): key(_key) {do_init_randoms();} 00027 00028 int hash(int use_size) const 00029 { 00030 return int((randoms1[key[0]] >> (key[1]&0x0f)) + 00031 (randoms2[key[1]] >> (key[2]&0x0f)) + 00032 (randoms3[key[2]] >> (key[0]&0x0f))) & (use_size-1); 00033 } 00034 00035 bool operator==(const HashKey3uc& k2) const {return key==k2.key;} 00036 bool operator!=(const HashKey3uc& k2) const {return !(key==k2.key);} 00037 }; 00038 00039 struct HashKey3usi 00040 { 00041 CGLA::Vec3usi key; 00042 00043 HashKey3usi() {do_init_randoms();} 00044 HashKey3usi(CGLA::Vec3usi _key): key(_key) {do_init_randoms();} 00045 HashKey3usi(CGLA::Vec3i _key): key(_key) {do_init_randoms();} 00046 00047 int hash(int use_size) const 00048 { 00049 return int( 00050 ((randoms1[key[0]&0xff00>>8] * randoms2[key[1]&0xff] >> (key[2]&0x0f)) 00051 + (randoms2[key[1]&0xff00>>8] * randoms1[key[2]&0xff] >> (key[0]&0x0f)) 00052 + (randoms3[key[2]&0xff00>>8] * randoms3[key[0]&0xff] >> (key[1]&0x0f))) 00053 & (use_size-1)); 00054 } 00055 00056 bool operator==(const HashKey3usi& k2) const {return key==k2.key;} 00057 bool operator!=(const HashKey3usi& k2) const {return !(key==k2.key);} 00058 }; 00059 00060 struct HashKey1c 00061 { 00062 unsigned char key; 00063 00064 HashKey1c() {do_init_randoms();} 00065 HashKey1c(unsigned char _key): key(_key) {do_init_randoms();} 00066 00067 int hash(int use_size) const 00068 { 00069 return int(randoms1[key] & (use_size-1)); 00070 } 00071 00072 bool operator==(const HashKey1c& k2) const {return key==k2.key;} 00073 bool operator!=(const HashKey1c& k2) const {return !(key==k2.key);} 00074 }; 00075 } 00076 00077 00078 #endif