X-Git-Url: http://review.tizen.org/git/?p=platform%2Fupstream%2Fisl.git;a=blobdiff_plain;f=isl_hash.c;h=7b96c51cd2f8e4fdfe9e68c500ed316013269f7c;hp=15df05af0e29cb83731ac709cb50c52a26646674;hb=63fb8a7f484648c3caa25351c8c94ac2395ec563;hpb=4652b6bea64a717276dd595b57494977b9bbd8d8 diff --git a/isl_hash.c b/isl_hash.c index 15df05a..7b96c51 100644 --- a/isl_hash.c +++ b/isl_hash.c @@ -1,15 +1,16 @@ /* * Copyright 2008-2009 Katholieke Universiteit Leuven * - * Use of this software is governed by the GNU LGPLv2.1 license + * Use of this software is governed by the MIT license * * Written by Sven Verdoolaege, K.U.Leuven, Departement * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium */ #include -#include "isl_hash.h" -#include "isl_ctx.h" +#include +#include +#include uint32_t isl_hash_string(uint32_t hash, const char *s) { @@ -18,6 +19,15 @@ uint32_t isl_hash_string(uint32_t hash, const char *s) return hash; } +uint32_t isl_hash_mem(uint32_t hash, const void *p, size_t len) +{ + int i; + const char *s = p; + for (i = 0; i < len; ++i) + isl_hash_byte(hash, s[i]); + return hash; +} + static unsigned int round_up(unsigned int v) { int old_v = v; @@ -54,6 +64,7 @@ int isl_hash_table_init(struct isl_ctx *ctx, struct isl_hash_table *table, static int grow_table(struct isl_ctx *ctx, struct isl_hash_table *table, int (*eq)(const void *entry, const void *val)) { + int n; size_t old_size, size; struct isl_hash_table_entry *entries; uint32_t h; @@ -68,6 +79,8 @@ static int grow_table(struct isl_ctx *ctx, struct isl_hash_table *table, return -1; } + n = table->n; + table->n = 0; table->bits++; for (h = 0; h < old_size; ++h) { @@ -82,6 +95,7 @@ static int grow_table(struct isl_ctx *ctx, struct isl_hash_table *table, table->bits--; free(table->entries); table->entries = entries; + table->n = n; return -1; } @@ -154,14 +168,15 @@ struct isl_hash_table_entry *isl_hash_table_find(struct isl_ctx *ctx, int isl_hash_table_foreach(struct isl_ctx *ctx, struct isl_hash_table *table, - int (*fn)(void *entry)) + int (*fn)(void **entry, void *user), void *user) { size_t size; uint32_t h; size = 1 << table->bits; for (h = 0; h < size; ++ h) - if (table->entries[h].data && fn(table->entries[h].data) < 0) + if (table->entries[h].data && + fn(&table->entries[h].data, user) < 0) return -1; return 0;