Triton Repository branch, master, updated. 662361693c4537a90d3dc0cd9b5aaa08588e6cb2
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Triton Repository". The branch, master has been updated via 662361693c4537a90d3dc0cd9b5aaa08588e6cb2 (commit) via c568756ba28adf23e89bfe398987d5401640e3e8 (commit) via 705d839eedd93b9c0dc59fc75c078be7721d0ee1 (commit) via 5ae8a3de0f3e3951e3f62a9de10b79bcc0ba1cb0 (commit) from c4d74ef3a992a37f38a92c0b258a8ccb5d40e816 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 662361693c4537a90d3dc0cd9b5aaa08588e6cb2 Author: Justin Wozniak <[email protected]> Date: Sat Apr 24 01:13:30 2010 -0500 Cleanups commit c568756ba28adf23e89bfe398987d5401640e3e8 Author: Justin Wozniak <[email protected]> Date: Sat Apr 24 01:10:00 2010 -0500 Include strings as keys in testhash.c commit 705d839eedd93b9c0dc59fc75c078be7721d0ee1 Author: Justin Wozniak <[email protected]> Date: Sat Apr 24 00:56:47 2010 -0500 New triton_hash_string_hash() for triton_strings commit 5ae8a3de0f3e3951e3f62a9de10b79bcc0ba1cb0 Author: Justin Wozniak <[email protected]> Date: Sat Apr 24 00:54:36 2010 -0500 Minor bug fix and error check in triton-string ----------------------------------------------------------------------- Summary of changes: code/src/common/tests/testhash.c | 63 +++++++++++++++++++++++++++++++++++--- code/src/common/triton-hash.h | 11 ++++++ code/src/common/triton-string.h | 4 ++- 3 files changed, 72 insertions(+), 6 deletions(-) Diff of changes: diff --git a/code/src/common/tests/testhash.c b/code/src/common/tests/testhash.c index facc902..6a0d078 100644 --- a/code/src/common/tests/testhash.c +++ b/code/src/common/tests/testhash.c @@ -2,6 +2,7 @@ #include <stdlib.h> #include "src/common/triton-list.h" #include "src/common/triton-hash.h" +#include "src/common/triton-string.h" struct e { @@ -9,6 +10,12 @@ struct e triton_list_link_t link; }; +struct s +{ + triton_string_t *v; + triton_list_link_t link; +}; + int e_compare(void *key, struct triton_hash_link *link) { int *value1 = (int *)key; @@ -19,18 +26,28 @@ int e_compare(void *key, struct triton_hash_link *link) return (value2->v == *value1); } +int s_compare(void *key, struct triton_hash_link *link) +{ + triton_string_t *value1 = (triton_string_t *)key; + struct s *value2 = triton_hash_get_entry(link, struct s, link); + assert(key); + assert(link); + + return (!strcmp(value2->v->string, value1->string)); +} + void e_destroy(struct e *entry) {} int main(int argc, char *argv[]) { - triton_list_t l; struct triton_hash_table *table; struct e *entry; struct e *es; + struct s *ss; struct triton_hash_link *result; - // triton_list_link_t *p, *s; - int i, testsize, delcount; + int i, j, testsize, hash; + triton_string_t *string; assert(argc == 2); @@ -40,10 +57,10 @@ int main(int argc, char *argv[]) es = malloc(sizeof(*es) * testsize); - triton_list_init(&l); + // Begin integer tests... + table = triton_hash_init(e_compare, triton_hash_32bit_hash, 16); - /* test push/pop */ for(i = 0; i < testsize; ++i) { es[i].v = i; @@ -66,6 +83,42 @@ int main(int argc, char *argv[]) triton_hash_destroy_and_finalize(table, struct e, link, e_destroy); + // Begin string tests... + + for (i = 0; i < 10; i++) + { + string = malloc(sizeof(triton_string_t)); + triton_string_init(string, "string: _%d_", i); + hash = triton_hash_string_hash(string, 23); + printf("hash(\"%s\") -> %i\n", string->string, hash); + triton_string_destroy(string); + free(string); + } + + table = triton_hash_init(s_compare, triton_hash_string_hash, 23); + + for(i = 0; i < testsize; ++i) + { + ss = malloc(sizeof(*ss)); + string = malloc(sizeof(triton_string_t)); + triton_string_init(string, "[%i]", i); + ss->v = string; + triton_hash_add(table, string, &(ss->link)); + } + + assert(table->table_count == testsize); + + for(i = 0; i < testsize; ++i) + { + string = malloc(sizeof(triton_string_t)); + triton_string_init(string, "[%i]", i); + result = triton_hash_search(table, string); + ss = triton_hash_get_entry(result, struct s, link); + sscanf(ss->v->string, "[%i]", &j); + assert(i == j); + free(string); + } + free(es); return 0; } diff --git a/code/src/common/triton-hash.h b/code/src/common/triton-hash.h index bca9ca6..aeaa042 100644 --- a/code/src/common/triton-hash.h +++ b/code/src/common/triton-hash.h @@ -7,6 +7,7 @@ #define TRITON_HASH_H #include "src/common/triton-list.h" +#include "src/common/triton-string.h" #include "src/common/triton-thread.h" #include "src/common/jenkins-hash.h" @@ -289,6 +290,16 @@ static inline int triton_hash_strhash(void *k, int table_size) return pc & (table_size - 1); } +static inline int triton_hash_string_hash(void *k, int table_size) +{ + uint32_t pc = 0, pb = 0; + triton_string_t *s; + s = (triton_string_t *)k; + assert(s->string); + bj_hashlittle2(s->string, s->size, &pc, &pb); + return pc & (table_size - 1); +} + #endif /* TRITON_HASH_H */ /* diff --git a/code/src/common/triton-string.h b/code/src/common/triton-string.h index a4572f7..b9feb35 100644 --- a/code/src/common/triton-string.h +++ b/code/src/common/triton-string.h @@ -18,6 +18,7 @@ typedef struct static inline void triton_string_init(triton_string_t *s, const char *format, ...) { va_list ap, aap; + int err; if(format) { va_start(ap, format); @@ -25,7 +26,8 @@ static inline void triton_string_init(triton_string_t *s, const char *format, .. s->size = vsnprintf(NULL, 0, format, ap) + 1; va_end(ap); s->string = malloc(s->size); - vsnprintf(s->string, s->size, format, ap); + err = vsnprintf(s->string, s->size, format, aap); + assert(err >= 0 && err < s->size); va_end(aap); } else hooks/post-receive -- Triton Repository
participants (1)
-
noreply@mcs.anl.gov