diff options
author | Junio C Hamano <gitster@pobox.com> | 2014-07-21 18:18:44 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-07-21 18:18:44 (GMT) |
commit | 9b1c2a3a8e625ea7f56e9ba3d3c0e31938faa738 (patch) | |
tree | aa21c9fad684c6f6e16d4a1c69a6c6bd70dd54c3 /test-hashmap.c | |
parent | 0ac744305f5885207bf96fc5488fcc59782ffa96 (diff) | |
parent | 7b64d42d22206d9995a8f0cb3b515e623cac4702 (diff) | |
download | git-9b1c2a3a8e625ea7f56e9ba3d3c0e31938faa738.zip git-9b1c2a3a8e625ea7f56e9ba3d3c0e31938faa738.tar.gz git-9b1c2a3a8e625ea7f56e9ba3d3c0e31938faa738.tar.bz2 |
Merge branch 'kb/hashmap-updates'
* kb/hashmap-updates:
hashmap: add string interning API
hashmap: add simplified hashmap_get_from_hash() API
hashmap: improve struct hashmap member documentation
hashmap: factor out getting a hash code from a SHA1
Diffstat (limited to 'test-hashmap.c')
-rw-r--r-- | test-hashmap.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/test-hashmap.c b/test-hashmap.c index f5183fb..07aa7ec 100644 --- a/test-hashmap.c +++ b/test-hashmap.c @@ -115,9 +115,8 @@ static void perf_hashmap(unsigned int method, unsigned int rounds) for (j = 0; j < rounds; j++) { for (i = 0; i < TEST_SIZE; i++) { - struct hashmap_entry key; - hashmap_entry_init(&key, hashes[i]); - hashmap_get(&map, &key, entries[i]->key); + hashmap_get_from_hash(&map, hashes[i], + entries[i]->key); } } @@ -199,12 +198,8 @@ int main(int argc, char *argv[]) } else if (!strcmp("get", cmd) && l1) { - /* setup static key */ - struct hashmap_entry key; - hashmap_entry_init(&key, hash); - /* lookup entry in hashmap */ - entry = hashmap_get(&map, &key, p1); + entry = hashmap_get_from_hash(&map, hash, p1); /* print result */ if (!entry) @@ -239,6 +234,20 @@ int main(int argc, char *argv[]) /* print table sizes */ printf("%u %u\n", map.tablesize, map.size); + } else if (!strcmp("intern", cmd) && l1) { + + /* test that strintern works */ + const char *i1 = strintern(p1); + const char *i2 = strintern(p1); + if (strcmp(i1, p1)) + printf("strintern(%s) returns %s\n", p1, i1); + else if (i1 == p1) + printf("strintern(%s) returns input pointer\n", p1); + else if (i1 != i2) + printf("strintern(%s) != strintern(%s)", i1, i2); + else + printf("%s\n", i1); + } else if (!strcmp("perfhashmap", cmd) && l1 && l2) { perf_hashmap(atoi(p1), atoi(p2)); |