X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=source%2Fgles2n64%2Fsrc%2FHash.h;fp=source%2Fgles2n64%2Fsrc%2FHash.h;h=1f26ec98d66c89aa952128f12df7a40303fd1af0;hb=34cf40586ac07c54d9bfc5be30f28743232b6d67;hp=0000000000000000000000000000000000000000;hpb=22726e4d55be26faa48b57b22689cbedde27ae44;p=mupen64plus-pandora.git diff --git a/source/gles2n64/src/Hash.h b/source/gles2n64/src/Hash.h new file mode 100644 index 0000000..1f26ec9 --- /dev/null +++ b/source/gles2n64/src/Hash.h @@ -0,0 +1,42 @@ +#ifndef __HASH_H__ +#define __HASH_H__ + +#include + +template +class HashMap +{ +public: + void init(unsigned power2) + { + _mask = (1 << power2) - 1; + _hashmap = (T**)malloc((_mask+1) * sizeof(T*)); + reset(); + } + + void destroy() + { + free(_hashmap); + } + + void reset() + { + memset(_hashmap, 0, (_mask+1) * sizeof(T*)); + } + + void insert(unsigned hash, T* data) + { + _hashmap[hash & _mask] = data; + } + + T* find(unsigned hash) + { + return _hashmap[hash & _mask]; + } + +protected: + T **_hashmap; + unsigned _mask; +}; + +#endif