Mercurial > hg > Game > Cerium
diff Renderer/test_render/TextureHash.cpp @ 283:15bfacccde99 draft
fix test_render
author | e065746@localhost.localdomain |
---|---|
date | Fri, 05 Jun 2009 16:49:12 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/test_render/TextureHash.cpp Fri Jun 05 16:49:12 2009 +0900 @@ -0,0 +1,51 @@ +#include <string.h> +#include <stdlib.h> +#include "TextureHash.h" + +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; + } +} + +TextureHash::~TextureHash(void) +{ + free(table); +} + +int +TextureHash::hash_function(const char *key) +{ + //float value = 0.0; + int value = 0; + + for (int i = 0; key[i]; i++) { + value += key[i]*(i+1)*17+1; + } + + return value%TABLE_SIZE; +} + +int +TextureHash::hash_regist(const char* key) +{ + 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; + } +}