GLES2N64 (from mupen64plus-ae) plugin. Compile and run on the OpenPandora
[mupen64plus-pandora.git] / source / gles2n64 / src / Hash.h
diff --git a/source/gles2n64/src/Hash.h b/source/gles2n64/src/Hash.h
new file mode 100644 (file)
index 0000000..1f26ec9
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef __HASH_H__
+#define __HASH_H__
+
+#include <stdlib.h>
+
+template<typename T>
+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