diff options
author | Craig Tiller <ctiller@google.com> | 2016-11-18 12:45:16 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2016-11-18 12:45:16 -0800 |
commit | ac5f518016fbdce5f054e725be1eb1851ac4901d (patch) | |
tree | ca8270ae0986c479cbf8cd5a352547aedb9fd7ec /src/core/lib/slice/slice_hash_table.c | |
parent | e17029353010d0ef393d0feeb14df20321d6c984 (diff) | |
parent | b28c7e8710638b362e5bfdd7dd81a45241c376e8 (diff) |
Merge branch 'slice_with_exec_ctx' into eliminate_mdstr
Diffstat (limited to 'src/core/lib/slice/slice_hash_table.c')
-rw-r--r-- | src/core/lib/slice/slice_hash_table.c | 44 |
1 files changed, 2 insertions, 42 deletions
diff --git a/src/core/lib/slice/slice_hash_table.c b/src/core/lib/slice/slice_hash_table.c index 10b41343ea..55f20155f3 100644 --- a/src/core/lib/slice/slice_hash_table.c +++ b/src/core/lib/slice/slice_hash_table.c @@ -46,7 +46,6 @@ static const grpc_slice terminal_slice = {&terminal_slice_refcount, struct grpc_slice_hash_table { gpr_refcount refs; - size_t num_entries; size_t size; grpc_slice_hash_table_entry* entries; }; @@ -90,7 +89,6 @@ grpc_slice_hash_table* grpc_slice_hash_table_create( grpc_slice_hash_table* table = gpr_malloc(sizeof(*table)); memset(table, 0, sizeof(*table)); gpr_ref_init(&table->refs, 1); - table->num_entries = num_entries; // Quadratic probing gets best performance when the table is no more // than half full. table->size = num_entries * 2; @@ -112,8 +110,8 @@ grpc_slice_hash_table* grpc_slice_hash_table_ref(grpc_slice_hash_table* table) { return table; } -int grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, - grpc_slice_hash_table* table) { +void grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, + grpc_slice_hash_table* table) { if (table != NULL && gpr_unref(&table->refs)) { for (size_t i = 0; i < table->size; ++i) { grpc_slice_hash_table_entry* entry = &table->entries[i]; @@ -124,13 +122,7 @@ int grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, } gpr_free(table->entries); gpr_free(table); - return 1; } - return 0; -} - -size_t grpc_slice_hash_table_num_entries(const grpc_slice_hash_table* table) { - return table->num_entries; } void* grpc_slice_hash_table_get(const grpc_slice_hash_table* table, @@ -140,35 +132,3 @@ void* grpc_slice_hash_table_get(const grpc_slice_hash_table* table, if (idx == table->size) return NULL; // Not found. return table->entries[idx].value; } - -int grpc_slice_hash_table_cmp(const grpc_slice_hash_table* table1, - const grpc_slice_hash_table* table2) { - // Compare by num_entries. - if (table1->num_entries < table2->num_entries) return -1; - if (table1->num_entries > table2->num_entries) return 1; - for (size_t i = 0; i < table1->num_entries; ++i) { - grpc_slice_hash_table_entry* e1 = &table1->entries[i]; - grpc_slice_hash_table_entry* e2 = &table2->entries[i]; - // Compare keys by hash value. - int cmp = grpc_slice_cmp(e1->key, e2->key); - if (cmp != 0) return cmp; - // Compare by vtable (pointer equality). - if (e1->vtable < e2->vtable) return -1; - if (e1->vtable > e2->vtable) return 1; - // Compare values via vtable. - const int value_result = e1->vtable->compare_value(e1->value, e2->value); - if (value_result != 0) return value_result; - } - return 0; -} - -void grpc_slice_hash_table_iterate( - const grpc_slice_hash_table* table, - void (*func)(const grpc_slice_hash_table_entry* entry, void* user_data), - void* user_data) { - for (size_t i = 0; i < table->size; ++i) { - if (!is_terminal(table->entries[i].key)) { - func(&table->entries[i], user_data); - } - } -} |