diff Renderer/Engine/TextureHash.cc @ 1114:ee481853d5dd draft

SgidHash remove.
author tkaito
date Tue, 18 Jan 2011 19:53:01 +0900
parents 20f09564c586
children bb17a03bab60
line wrap: on
line diff
--- a/Renderer/Engine/TextureHash.cc	Tue Jan 18 18:53:23 2011 +0900
+++ b/Renderer/Engine/TextureHash.cc	Tue Jan 18 19:53:01 2011 +0900
@@ -7,6 +7,7 @@
 TextureHash::TextureHash(void)
 {
     int size = sizeof(hashtable)*TABLE_SIZE;
+
 #if defined(__SPU__) || ! defined(HAS_POSIX_MEMALIGN)
         table =  (hashtable*)malloc(size);
 #else
@@ -39,19 +40,54 @@
 int
 TextureHash::hash_regist(const char* key, int &id)
 {
+  int hash = hash_function(key);
+  for (int i = 0; ; i++) {
+    if (table[hash].tx_id == -1) {
+      table[hash].key   = (char*)key;
+      id = id_count++;
+      return 0;
+      
+    } else if (strcmp(key, table[hash].key) == 0
+	       && table[hash].tx_id != -1){
+      id = table[hash].tx_id;
+      return 1;
+    }
+    hash = ((37*hash)^(11*i)) % TABLE_SIZE;
+  }  
+}
+
+int
+TextureHash::sg_hash_regist(const char* key, int &id)
+{
     int hash = hash_function(key);
 
     for (int i = 0; ; i++) {
         if (table[hash].tx_id == -1) {
             table[hash].key   = (char*)key;
-            id = id_count++;
+	    table[hash].tx_id = id;
             return 0;
 
         } else if (strcmp(key, table[hash].key) == 0
                    && table[hash].tx_id != -1){
-            id = table[hash].tx_id;
-            return 1;
+            return table[hash].tx_id;
         }
         hash = ((37*hash)^(11*i)) % TABLE_SIZE;
     }
 }
+
+int
+TextureHash::get_sgid(const char* key)
+{
+
+    int hash = hash_function(key);
+    for (int i = 0; ; i++) {
+        if (table[hash].tx_id == -1) {
+            return -1;
+
+        } else if (strcmp(key, table[hash].key) == 0
+                   && table[hash].tx_id != -1){
+            return table[hash].tx_id;
+        }
+        hash = ((37*hash)^(11*i)) % TABLE_SIZE;
+    }
+}