summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorSebastian Dransfeld <sd@tango.flipp.net>2006-12-28 15:23:47 +0000
committerSebastian Dransfeld <sd@tango.flipp.net>2006-12-28 15:23:47 +0000
commit98b5b625abcc8b1fb8188224e136e39e35c1d002 (patch)
tree5eab5bee85c346549cf0ea7e57cf605d15ec93b5 /legacy
parent4518aa12179346f090d7d88fb2c43c4cb17b3b63 (diff)
Move hash gen func to own file.
SVN revision: 27605
Diffstat (limited to 'legacy')
-rw-r--r--legacy/eet/src/lib/Eet_private.h37
-rw-r--r--legacy/eet/src/lib/Makefile.am1
-rw-r--r--legacy/eet/src/lib/eet_data.c4
-rw-r--r--legacy/eet/src/lib/eet_lib.c8
-rw-r--r--legacy/eet/src/lib/eet_utils.c35
5 files changed, 43 insertions, 42 deletions
diff --git a/legacy/eet/src/lib/Eet_private.h b/legacy/eet/src/lib/Eet_private.h
index 4f142fd464..f4e862634a 100644
--- a/legacy/eet/src/lib/Eet_private.h
+++ b/legacy/eet/src/lib/Eet_private.h
@@ -41,45 +41,10 @@ void _eet_memfile_read_close(FILE *f);
41FILE *_eet_memfile_write_open(void **data, size_t *size); 41FILE *_eet_memfile_write_open(void **data, size_t *size);
42void _eet_memfile_write_close(FILE *f); 42void _eet_memfile_write_close(FILE *f);
43void _eet_memfile_shutdown(void); 43void _eet_memfile_shutdown(void);
44int _eet_hash_gen(const char *key, int hash_size);
44 45
45#ifndef PATH_MAX 46#ifndef PATH_MAX
46#define PATH_MAX 4096 47#define PATH_MAX 4096
47#endif 48#endif
48 49
49/* caluclate hash table entry valu with bitmask size of hash_size */
50static int
51eet_hash_gen(const char *key, int hash_size)
52{
53 int hash_num = 0;
54 int value, i;
55 unsigned char *ptr;
56
57 const int masks[9] =
58 {
59 0x00,
60 0x01,
61 0x03,
62 0x07,
63 0x0f,
64 0x1f,
65 0x3f,
66 0x7f,
67 0xff
68 };
69
70 /* no string - index 0 */
71 if (!key) return 0;
72
73 /* calc hash num */
74 for (i = 0, ptr = (unsigned char *)key, value = (int)(*ptr);
75 value;
76 ptr++, i++, value = (int)(*ptr))
77 hash_num ^= (value | (value << 8)) >> (i & 0x7);
78
79 /* mask it */
80 hash_num &= masks[hash_size];
81 /* return it */
82 return hash_num;
83}
84
85#endif 50#endif
diff --git a/legacy/eet/src/lib/Makefile.am b/legacy/eet/src/lib/Makefile.am
index a98bd04c10..0829fbd993 100644
--- a/legacy/eet/src/lib/Makefile.am
+++ b/legacy/eet/src/lib/Makefile.am
@@ -17,6 +17,7 @@ eet_lib.c \
17eet_data.c \ 17eet_data.c \
18eet_image.c \ 18eet_image.c \
19eet_memfile.c \ 19eet_memfile.c \
20eet_utils.c \
20Eet_private.h 21Eet_private.h
21 22
22libeet_la_LIBADD = -lz -ljpeg @fnmatch_libs@ @winsock_libs@ 23libeet_la_LIBADD = -lz -ljpeg @fnmatch_libs@ @winsock_libs@
diff --git a/legacy/eet/src/lib/eet_data.c b/legacy/eet/src/lib/eet_data.c
index 6ddeb22a8a..363351cb00 100644
--- a/legacy/eet/src/lib/eet_data.c
+++ b/legacy/eet/src/lib/eet_data.c
@@ -610,7 +610,7 @@ _eet_descriptor_hash_new(Eet_Data_Descriptor *edd)
610 int hash; 610 int hash;
611 611
612 ede = &(edd->elements.set[i]); 612 ede = &(edd->elements.set[i]);
613 hash = eet_hash_gen((char *) ede->name, 6); 613 hash = _eet_hash_gen((char *) ede->name, 6);
614 if (!edd->elements.hash.buckets[hash].element) 614 if (!edd->elements.hash.buckets[hash].element)
615 edd->elements.hash.buckets[hash].element = ede; 615 edd->elements.hash.buckets[hash].element = ede;
616 else 616 else
@@ -651,7 +651,7 @@ _eet_descriptor_hash_find(Eet_Data_Descriptor *edd, char *name)
651 int hash; 651 int hash;
652 Eet_Data_Descriptor_Hash *bucket; 652 Eet_Data_Descriptor_Hash *bucket;
653 653
654 hash = eet_hash_gen(name, 6); 654 hash = _eet_hash_gen(name, 6);
655 if (!edd->elements.hash.buckets[hash].element) return NULL; 655 if (!edd->elements.hash.buckets[hash].element) return NULL;
656 if (!strcmp(edd->elements.hash.buckets[hash].element->name, name)) 656 if (!strcmp(edd->elements.hash.buckets[hash].element->name, name))
657 return edd->elements.hash.buckets[hash].element; 657 return edd->elements.hash.buckets[hash].element;
diff --git a/legacy/eet/src/lib/eet_lib.c b/legacy/eet/src/lib/eet_lib.c
index c075b88ee9..902e7fcfd9 100644
--- a/legacy/eet/src/lib/eet_lib.c
+++ b/legacy/eet/src/lib/eet_lib.c
@@ -701,7 +701,7 @@ eet_open(const char *file, Eet_File_Mode mode)
701 efn->name = (char*)((uint8_t*)(p + HEADER_SIZE)); 701 efn->name = (char*)((uint8_t*)(p + HEADER_SIZE));
702 702
703 /* get hash bucket it should go in */ 703 /* get hash bucket it should go in */
704 hash = eet_hash_gen(efn->name, ef->header->directory->size); 704 hash = _eet_hash_gen(efn->name, ef->header->directory->size);
705 efn->next = ef->header->directory->nodes[hash]; 705 efn->next = ef->header->directory->nodes[hash];
706 ef->header->directory->nodes[hash] = efn; 706 ef->header->directory->nodes[hash] = efn;
707 707
@@ -1020,7 +1020,7 @@ eet_write(Eet_File *ef, const char *name, const void *data, int size, int compre
1020 } 1020 }
1021 1021
1022 /* figure hash bucket */ 1022 /* figure hash bucket */
1023 hash = eet_hash_gen(name, ef->header->directory->size); 1023 hash = _eet_hash_gen(name, ef->header->directory->size);
1024 1024
1025 data_size = compress ? 12 + ((size * 101) / 100) : size; 1025 data_size = compress ? 12 + ((size * 101) / 100) : size;
1026 1026
@@ -1124,7 +1124,7 @@ eet_delete(Eet_File *ef, const char *name)
1124 return 0; 1124 return 0;
1125 1125
1126 /* figure hash bucket */ 1126 /* figure hash bucket */
1127 hash = eet_hash_gen(name, ef->header->directory->size); 1127 hash = _eet_hash_gen(name, ef->header->directory->size);
1128 1128
1129 /* Does this node already exist? */ 1129 /* Does this node already exist? */
1130 for (pefn = NULL, efn = ef->header->directory->nodes[hash]; 1130 for (pefn = NULL, efn = ef->header->directory->nodes[hash];
@@ -1252,7 +1252,7 @@ find_node_by_name(Eet_File *ef, const char *name)
1252 int hash; 1252 int hash;
1253 1253
1254 /* get hash bucket this should be in */ 1254 /* get hash bucket this should be in */
1255 hash = eet_hash_gen(name, ef->header->directory->size); 1255 hash = _eet_hash_gen(name, ef->header->directory->size);
1256 1256
1257 for (efn = ef->header->directory->nodes[hash]; efn; efn = efn->next) 1257 for (efn = ef->header->directory->nodes[hash]; efn; efn = efn->next)
1258 { 1258 {
diff --git a/legacy/eet/src/lib/eet_utils.c b/legacy/eet/src/lib/eet_utils.c
new file mode 100644
index 0000000000..898d87fa1f
--- /dev/null
+++ b/legacy/eet/src/lib/eet_utils.c
@@ -0,0 +1,35 @@
1int
2_eet_hash_gen(const char *key, int hash_size)
3{
4 int hash_num = 0;
5 int value, i;
6 unsigned char *ptr;
7
8 const int masks[9] =
9 {
10 0x00,
11 0x01,
12 0x03,
13 0x07,
14 0x0f,
15 0x1f,
16 0x3f,
17 0x7f,
18 0xff
19 };
20
21 /* no string - index 0 */
22 if (!key) return 0;
23
24 /* calc hash num */
25 for (i = 0, ptr = (unsigned char *)key, value = (int)(*ptr);
26 value;
27 ptr++, i++, value = (int)(*ptr))
28 hash_num ^= (value | (value << 8)) >> (i & 0x7);
29
30 /* mask it */
31 hash_num &= masks[hash_size];
32 /* return it */
33 return hash_num;
34}
35