Mercurial > hg > Members > kono > Cerium
comparison Renderer/test_render/TextureHash.cpp @ 283:55ea4465b1a2
fix test_render
author | e065746@localhost.localdomain |
---|---|
date | Fri, 05 Jun 2009 16:49:12 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
282:ef061be0baff | 283:55ea4465b1a2 |
---|---|
1 #include <string.h> | |
2 #include <stdlib.h> | |
3 #include "TextureHash.h" | |
4 | |
5 int id_count; | |
6 | |
7 TextureHash::TextureHash(void) | |
8 { | |
9 table = (hashtable*)malloc(sizeof(hashtable)*TABLE_SIZE); | |
10 | |
11 for (int i = 0; i < TABLE_SIZE; i++) { | |
12 table[i].tx_id = -1; | |
13 table[i].key = NULL; | |
14 } | |
15 } | |
16 | |
17 TextureHash::~TextureHash(void) | |
18 { | |
19 free(table); | |
20 } | |
21 | |
22 int | |
23 TextureHash::hash_function(const char *key) | |
24 { | |
25 //float value = 0.0; | |
26 int value = 0; | |
27 | |
28 for (int i = 0; key[i]; i++) { | |
29 value += key[i]*(i+1)*17+1; | |
30 } | |
31 | |
32 return value%TABLE_SIZE; | |
33 } | |
34 | |
35 int | |
36 TextureHash::hash_regist(const char* key) | |
37 { | |
38 int hash = hash_function(key); | |
39 | |
40 for (int i = 0; ; i++) { | |
41 if (table[hash].tx_id == -1) { | |
42 table[hash].key = (char*)key; | |
43 table[hash].tx_id = id_count++; | |
44 return -1; | |
45 } else if (strcmp(key, table[hash].key) == 0 | |
46 && table[hash].tx_id != -1){ | |
47 return table[hash].tx_id; | |
48 } | |
49 hash = ((37*hash)^(11*i)) % TABLE_SIZE; | |
50 } | |
51 } |