Mercurial > hg > Game > Cerium
annotate Renderer/Engine/TextureHash.cc @ 1379:13065ad17328 draft
collada moved but only my mac.
author | e095732 <e095732@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 26 Jan 2012 21:56:32 +0900 |
parents | b8adf4e95e96 |
children |
rev | line source |
---|---|
539 | 1 #include <string.h> |
2 #include <stdlib.h> | |
3 #include "TextureHash.h" | |
4 | |
5 TextureHash::TextureHash(void) | |
6 { | |
1134
80c1d74f2c7f
change the scope of id_count to member variables
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1133
diff
changeset
|
7 id_count = 0; |
1087 | 8 int size = sizeof(hashtable)*TABLE_SIZE; |
9 #if defined(__SPU__) || ! defined(HAS_POSIX_MEMALIGN) | |
10 table = (hashtable*)malloc(size); | |
11 #else | |
1133 | 12 posix_memalign((void**)&table, 16, size); |
1087 | 13 #endif |
1133 | 14 |
539 | 15 for (int i = 0; i < TABLE_SIZE; i++) { |
16 table[i].tx_id = -1; | |
17 table[i].key = NULL; | |
18 } | |
19 } | |
20 | |
21 TextureHash::~TextureHash(void) | |
22 { | |
23 free(table); | |
24 } | |
25 | |
26 int | |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
27 TextureHash::hash_function(const unsigned char *key) |
539 | 28 { |
29 //float value = 0.0; | |
30 int value = 0; | |
31 | |
32 for (int i = 0; key[i]; i++) { | |
33 value += key[i]*(i+1)*17+1; | |
34 } | |
35 | |
36 return value%TABLE_SIZE; | |
37 } | |
38 | |
39 int | |
40 TextureHash::hash_regist(const char* key, int &id) | |
41 { | |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
42 int hash = hash_function((const unsigned char*)key); |
1114 | 43 for (int i = 0; ; i++) { |
44 if (table[hash].tx_id == -1) { | |
45 table[hash].key = (char*)key; | |
46 id = id_count++; | |
1184 | 47 return -1; |
1114 | 48 |
49 } else if (strcmp(key, table[hash].key) == 0 | |
50 && table[hash].tx_id != -1){ | |
51 id = table[hash].tx_id; | |
52 return 1; | |
53 } | |
54 hash = ((37*hash)^(11*i)) % TABLE_SIZE; | |
55 } | |
56 } | |
57 | |
58 int | |
59 TextureHash::sg_hash_regist(const char* key, int &id) | |
60 { | |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
61 int hash = hash_function((const unsigned char*)key); |
539 | 62 |
63 for (int i = 0; ; i++) { | |
64 if (table[hash].tx_id == -1) { | |
65 table[hash].key = (char*)key; | |
1114 | 66 table[hash].tx_id = id; |
1184 | 67 return -1; |
539 | 68 |
69 } else if (strcmp(key, table[hash].key) == 0 | |
70 && table[hash].tx_id != -1){ | |
1114 | 71 return table[hash].tx_id; |
539 | 72 } |
73 hash = ((37*hash)^(11*i)) % TABLE_SIZE; | |
74 } | |
75 } | |
1114 | 76 |
77 int | |
78 TextureHash::get_sgid(const char* key) | |
79 { | |
80 | |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
81 int hash = hash_function((const unsigned char*)key); |
1114 | 82 for (int i = 0; ; i++) { |
83 if (table[hash].tx_id == -1) { | |
84 return -1; | |
85 | |
86 } else if (strcmp(key, table[hash].key) == 0 | |
87 && table[hash].tx_id != -1){ | |
88 return table[hash].tx_id; | |
89 } | |
90 hash = ((37*hash)^(11*i)) % TABLE_SIZE; | |
91 } | |
92 } |