diff TaskManager/Test/test_render/TextureHash.cpp @ 349:51ffd144f62c

fix hash_regist
author admin@mcbk.cr.ie.u-ryukyu.ac.jp
date Fri, 10 Jul 2009 16:06:15 +0900
parents fc314f28b66e
children
line wrap: on
line diff
--- a/TaskManager/Test/test_render/TextureHash.cpp	Thu Jul 09 17:59:44 2009 +0900
+++ b/TaskManager/Test/test_render/TextureHash.cpp	Fri Jul 10 16:06:15 2009 +0900
@@ -2,15 +2,15 @@
 #include <stdlib.h>
 #include "TextureHash.h"
 
-int id_count;
+static int id_count;
 
 TextureHash::TextureHash(void)
 {
     table = (hashtable*)malloc(sizeof(hashtable)*TABLE_SIZE);
 
     for (int i = 0; i < TABLE_SIZE; i++) {
-	table[i].tx_id = -1;
-	table[i].key = NULL;
+        table[i].tx_id = -1;
+        table[i].key = NULL;
     }
 }
 
@@ -26,26 +26,28 @@
     int value = 0;
 
     for (int i = 0; key[i]; i++) {
-	value += key[i]*(i+1)*17+1;
+        value += key[i]*(i+1)*17+1;
     }
 
     return value%TABLE_SIZE;
 }
 
 int
-TextureHash::hash_regist(const char* key)
+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;
-	    table[hash].tx_id = id_count++;
-	    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;
+        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;
     }
 }