aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2016-10-14 12:43:34 -0700
committerGravatar Mark D. Roth <roth@google.com>2016-10-14 12:43:34 -0700
commit6a721b5b3f253b86eac3f34c66e6b2d47bb08c9e (patch)
tree41cadd41b2689ab48f0c1dd640ec1538f46e9d15 /src/core
parent55f25b6c27b42b81ccb9bd9c7adf9a87cadd6da0 (diff)
Rename grpc_hash_table to grpc_mdstr_hash_table.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ext/client_config/method_config.c58
-rw-r--r--src/core/ext/client_config/method_config.h4
-rw-r--r--src/core/lib/transport/mdstr_hash_table.c (renamed from src/core/lib/transport/hashtable.c)54
-rw-r--r--src/core/lib/transport/mdstr_hash_table.h (renamed from src/core/lib/transport/hashtable.h)33
4 files changed, 78 insertions, 71 deletions
diff --git a/src/core/ext/client_config/method_config.c b/src/core/ext/client_config/method_config.c
index 3699c22810..f8a82323e7 100644
--- a/src/core/ext/client_config/method_config.c
+++ b/src/core/ext/client_config/method_config.c
@@ -39,7 +39,7 @@
#include <grpc/support/string_util.h>
#include <grpc/support/time.h>
-#include "src/core/lib/transport/hashtable.h"
+#include "src/core/lib/transport/mdstr_hash_table.h"
#include "src/core/lib/transport/metadata.h"
//
@@ -63,7 +63,8 @@ static int bool_cmp(void* v1, void* v2) {
return 0;
}
-static grpc_hash_table_vtable bool_vtable = {gpr_free, bool_copy, bool_cmp};
+static grpc_mdstr_hash_table_vtable bool_vtable = {gpr_free, bool_copy,
+ bool_cmp};
// timespec vtable
@@ -78,8 +79,8 @@ static int timespec_cmp(void* v1, void* v2) {
return gpr_time_cmp(*(gpr_timespec*)v1, *(gpr_timespec*)v2);
}
-static grpc_hash_table_vtable timespec_vtable = {gpr_free, timespec_copy,
- timespec_cmp};
+static grpc_mdstr_hash_table_vtable timespec_vtable = {gpr_free, timespec_copy,
+ timespec_cmp};
// int32 vtable
@@ -98,7 +99,8 @@ static int int32_cmp(void* v1, void* v2) {
return 0;
}
-static grpc_hash_table_vtable int32_vtable = {gpr_free, int32_copy, int32_cmp};
+static grpc_mdstr_hash_table_vtable int32_vtable = {gpr_free, int32_copy,
+ int32_cmp};
// Hash table keys.
#define GRPC_METHOD_CONFIG_WAIT_FOR_READY "grpc.wait_for_ready" // bool
@@ -109,7 +111,7 @@ static grpc_hash_table_vtable int32_vtable = {gpr_free, int32_copy, int32_cmp};
"grpc.max_response_message_bytes" // int32
struct grpc_method_config {
- grpc_hash_table* table;
+ grpc_mdstr_hash_table* table;
grpc_mdstr* wait_for_ready_key;
grpc_mdstr* timeout_key;
grpc_mdstr* max_request_message_bytes_key;
@@ -129,7 +131,7 @@ grpc_method_config* grpc_method_config_create(
grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_REQUEST_MESSAGE_BYTES);
method_config->max_response_message_bytes_key =
grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_RESPONSE_MESSAGE_BYTES);
- grpc_hash_table_entry entries[4];
+ grpc_mdstr_hash_table_entry entries[4];
size_t num_entries = 0;
if (wait_for_ready != NULL) {
entries[num_entries].key = method_config->wait_for_ready_key;
@@ -155,17 +157,17 @@ grpc_method_config* grpc_method_config_create(
entries[num_entries].vtable = &int32_vtable;
++num_entries;
}
- method_config->table = grpc_hash_table_create(num_entries, entries);
+ method_config->table = grpc_mdstr_hash_table_create(num_entries, entries);
return method_config;
}
grpc_method_config* grpc_method_config_ref(grpc_method_config* method_config) {
- grpc_hash_table_ref(method_config->table);
+ grpc_mdstr_hash_table_ref(method_config->table);
return method_config;
}
void grpc_method_config_unref(grpc_method_config* method_config) {
- if (grpc_hash_table_unref(method_config->table)) {
+ if (grpc_mdstr_hash_table_unref(method_config->table)) {
GRPC_MDSTR_UNREF(method_config->wait_for_ready_key);
GRPC_MDSTR_UNREF(method_config->timeout_key);
GRPC_MDSTR_UNREF(method_config->max_request_message_bytes_key);
@@ -176,30 +178,32 @@ void grpc_method_config_unref(grpc_method_config* method_config) {
int grpc_method_config_cmp(const grpc_method_config* method_config1,
const grpc_method_config* method_config2) {
- return grpc_hash_table_cmp(method_config1->table, method_config2->table);
+ return grpc_mdstr_hash_table_cmp(method_config1->table,
+ method_config2->table);
}
const bool* grpc_method_config_get_wait_for_ready(
const grpc_method_config* method_config) {
- return grpc_hash_table_get(method_config->table,
- method_config->wait_for_ready_key);
+ return grpc_mdstr_hash_table_get(method_config->table,
+ method_config->wait_for_ready_key);
}
const gpr_timespec* grpc_method_config_get_timeout(
const grpc_method_config* method_config) {
- return grpc_hash_table_get(method_config->table, method_config->timeout_key);
+ return grpc_mdstr_hash_table_get(method_config->table,
+ method_config->timeout_key);
}
const int32_t* grpc_method_config_get_max_request_message_bytes(
const grpc_method_config* method_config) {
- return grpc_hash_table_get(method_config->table,
- method_config->max_request_message_bytes_key);
+ return grpc_mdstr_hash_table_get(
+ method_config->table, method_config->max_request_message_bytes_key);
}
const int32_t* grpc_method_config_get_max_response_message_bytes(
const grpc_method_config* method_config) {
- return grpc_hash_table_get(method_config->table,
- method_config->max_response_message_bytes_key);
+ return grpc_mdstr_hash_table_get(
+ method_config->table, method_config->max_response_message_bytes_key);
}
//
@@ -218,41 +222,41 @@ static int method_config_cmp(void* valuep1, void* valuep2) {
return grpc_method_config_cmp(valuep1, valuep2);
}
-static const grpc_hash_table_vtable method_config_table_vtable = {
+static const grpc_mdstr_hash_table_vtable method_config_table_vtable = {
method_config_unref, method_config_ref, method_config_cmp};
grpc_method_config_table* grpc_method_config_table_create(
size_t num_entries, grpc_method_config_table_entry* entries) {
- grpc_hash_table_entry* hash_table_entries =
- gpr_malloc(sizeof(grpc_hash_table_entry) * num_entries);
+ grpc_mdstr_hash_table_entry* hash_table_entries =
+ gpr_malloc(sizeof(grpc_mdstr_hash_table_entry) * num_entries);
for (size_t i = 0; i < num_entries; ++i) {
hash_table_entries[i].key = entries[i].method_name;
hash_table_entries[i].value = entries[i].method_config;
hash_table_entries[i].vtable = &method_config_table_vtable;
}
grpc_method_config_table* method_config_table =
- grpc_hash_table_create(num_entries, hash_table_entries);
+ grpc_mdstr_hash_table_create(num_entries, hash_table_entries);
gpr_free(hash_table_entries);
return method_config_table;
}
grpc_method_config_table* grpc_method_config_table_ref(
grpc_method_config_table* table) {
- return grpc_hash_table_ref(table);
+ return grpc_mdstr_hash_table_ref(table);
}
void grpc_method_config_table_unref(grpc_method_config_table* table) {
- grpc_hash_table_unref(table);
+ grpc_mdstr_hash_table_unref(table);
}
int grpc_method_config_table_cmp(const grpc_method_config_table* table1,
const grpc_method_config_table* table2) {
- return grpc_hash_table_cmp(table1, table2);
+ return grpc_mdstr_hash_table_cmp(table1, table2);
}
grpc_method_config* grpc_method_config_table_get_method_config(
const grpc_method_config_table* table, const grpc_mdstr* path) {
- grpc_method_config* method_config = grpc_hash_table_get(table, path);
+ grpc_method_config* method_config = grpc_mdstr_hash_table_get(table, path);
// If we didn't find a match for the path, try looking for a wildcard
// entry (i.e., change "/service/method" to "/service/*").
if (method_config == NULL) {
@@ -265,7 +269,7 @@ grpc_method_config* grpc_method_config_table_get_method_config(
buf[len + 1] = '\0';
grpc_mdstr* wildcard_path = grpc_mdstr_from_string(buf);
gpr_free(buf);
- method_config = grpc_hash_table_get(table, wildcard_path);
+ method_config = grpc_mdstr_hash_table_get(table, wildcard_path);
GRPC_MDSTR_UNREF(wildcard_path);
}
return method_config;
diff --git a/src/core/ext/client_config/method_config.h b/src/core/ext/client_config/method_config.h
index d228b97948..1302ac425d 100644
--- a/src/core/ext/client_config/method_config.h
+++ b/src/core/ext/client_config/method_config.h
@@ -37,7 +37,7 @@
#include <grpc/impl/codegen/gpr_types.h>
#include <grpc/impl/codegen/grpc_types.h>
-#include "src/core/lib/transport/hashtable.h"
+#include "src/core/lib/transport/mdstr_hash_table.h"
#include "src/core/lib/transport/metadata.h"
/// Per-method configuration.
@@ -79,7 +79,7 @@ const int32_t* grpc_method_config_get_max_response_message_bytes(
const grpc_method_config* method_config);
/// A table of method configs.
-typedef grpc_hash_table grpc_method_config_table;
+typedef grpc_mdstr_hash_table grpc_method_config_table;
typedef struct grpc_method_config_table_entry {
/// The name is of one of the following forms:
diff --git a/src/core/lib/transport/hashtable.c b/src/core/lib/transport/mdstr_hash_table.c
index a016daa0ec..4be0536dd7 100644
--- a/src/core/lib/transport/hashtable.c
+++ b/src/core/lib/transport/mdstr_hash_table.c
@@ -29,7 +29,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
-#include "src/core/lib/transport/hashtable.h"
+#include "src/core/lib/transport/mdstr_hash_table.h"
#include <stdbool.h>
#include <string.h>
@@ -39,17 +39,17 @@
#include "src/core/lib/transport/metadata.h"
-struct grpc_hash_table {
+struct grpc_mdstr_hash_table {
gpr_refcount refs;
size_t num_entries;
- grpc_hash_table_entry* entries;
+ grpc_mdstr_hash_table_entry* entries;
};
// Helper function for insert and get operations that performs quadratic
// probing (https://en.wikipedia.org/wiki/Quadratic_probing).
-static size_t grpc_hash_table_find_index(const grpc_hash_table* table,
- const grpc_mdstr* key,
- bool find_empty) {
+static size_t grpc_mdstr_hash_table_find_index(
+ const grpc_mdstr_hash_table* table, const grpc_mdstr* key,
+ bool find_empty) {
for (size_t i = 0; i < table->num_entries; ++i) {
const size_t idx = (key->hash + i * i) % table->num_entries;
if (table->entries[idx].key == NULL)
@@ -59,46 +59,47 @@ static size_t grpc_hash_table_find_index(const grpc_hash_table* table,
return table->num_entries; // Not found.
}
-static void grpc_hash_table_add(grpc_hash_table* table, grpc_mdstr* key,
- void* value,
- const grpc_hash_table_vtable* vtable) {
+static void grpc_mdstr_hash_table_add(
+ grpc_mdstr_hash_table* table, grpc_mdstr* key, void* value,
+ const grpc_mdstr_hash_table_vtable* vtable) {
GPR_ASSERT(value != NULL);
const size_t idx =
- grpc_hash_table_find_index(table, key, true /* find_empty */);
+ grpc_mdstr_hash_table_find_index(table, key, true /* find_empty */);
GPR_ASSERT(idx != table->num_entries); // Table should never be full.
- grpc_hash_table_entry* entry = &table->entries[idx];
+ grpc_mdstr_hash_table_entry* entry = &table->entries[idx];
entry->key = GRPC_MDSTR_REF(key);
entry->value = vtable->copy_value(value);
entry->vtable = vtable;
}
-grpc_hash_table* grpc_hash_table_create(size_t num_entries,
- grpc_hash_table_entry* entries) {
- grpc_hash_table* table = gpr_malloc(sizeof(*table));
+grpc_mdstr_hash_table* grpc_mdstr_hash_table_create(
+ size_t num_entries, grpc_mdstr_hash_table_entry* entries) {
+ grpc_mdstr_hash_table* table = gpr_malloc(sizeof(*table));
memset(table, 0, sizeof(*table));
gpr_ref_init(&table->refs, 1);
// Quadratic probing gets best performance when the table is no more
// than half full.
table->num_entries = num_entries * 2;
- const size_t entry_size = sizeof(grpc_hash_table_entry) * table->num_entries;
+ const size_t entry_size =
+ sizeof(grpc_mdstr_hash_table_entry) * table->num_entries;
table->entries = gpr_malloc(entry_size);
memset(table->entries, 0, entry_size);
for (size_t i = 0; i < num_entries; ++i) {
- grpc_hash_table_entry* entry = &entries[i];
- grpc_hash_table_add(table, entry->key, entry->value, entry->vtable);
+ grpc_mdstr_hash_table_entry* entry = &entries[i];
+ grpc_mdstr_hash_table_add(table, entry->key, entry->value, entry->vtable);
}
return table;
}
-grpc_hash_table* grpc_hash_table_ref(grpc_hash_table* table) {
+grpc_mdstr_hash_table* grpc_mdstr_hash_table_ref(grpc_mdstr_hash_table* table) {
if (table != NULL) gpr_ref(&table->refs);
return table;
}
-int grpc_hash_table_unref(grpc_hash_table* table) {
+int grpc_mdstr_hash_table_unref(grpc_mdstr_hash_table* table) {
if (table != NULL && gpr_unref(&table->refs)) {
for (size_t i = 0; i < table->num_entries; ++i) {
- grpc_hash_table_entry* entry = &table->entries[i];
+ grpc_mdstr_hash_table_entry* entry = &table->entries[i];
if (entry->key != NULL) {
GRPC_MDSTR_UNREF(entry->key);
entry->vtable->destroy_value(entry->value);
@@ -111,21 +112,22 @@ int grpc_hash_table_unref(grpc_hash_table* table) {
return 0;
}
-void* grpc_hash_table_get(const grpc_hash_table* table, const grpc_mdstr* key) {
+void* grpc_mdstr_hash_table_get(const grpc_mdstr_hash_table* table,
+ const grpc_mdstr* key) {
const size_t idx =
- grpc_hash_table_find_index(table, key, false /* find_empty */);
+ grpc_mdstr_hash_table_find_index(table, key, false /* find_empty */);
if (idx == table->num_entries) return NULL; // Not found.
return table->entries[idx].value;
}
-int grpc_hash_table_cmp(const grpc_hash_table* table1,
- const grpc_hash_table* table2) {
+int grpc_mdstr_hash_table_cmp(const grpc_mdstr_hash_table* table1,
+ const grpc_mdstr_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_hash_table_entry* e1 = &table1->entries[i];
- grpc_hash_table_entry* e2 = &table2->entries[i];
+ grpc_mdstr_hash_table_entry* e1 = &table1->entries[i];
+ grpc_mdstr_hash_table_entry* e2 = &table2->entries[i];
// Compare keys by hash value.
if (e1->key->hash < e2->key->hash) return -1;
if (e1->key->hash > e2->key->hash) return 1;
diff --git a/src/core/lib/transport/hashtable.h b/src/core/lib/transport/mdstr_hash_table.h
index d5f40a2cf7..52e5b023db 100644
--- a/src/core/lib/transport/hashtable.h
+++ b/src/core/lib/transport/mdstr_hash_table.h
@@ -29,8 +29,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef GRPC_CORE_LIB_TRANSPORT_HASHTABLE_H
-#define GRPC_CORE_LIB_TRANSPORT_HASHTABLE_H
+#ifndef GRPC_CORE_LIB_TRANSPORT_MDSTR_HASH_TABLE_H
+#define GRPC_CORE_LIB_TRANSPORT_MDSTR_HASH_TABLE_H
#include "src/core/lib/transport/metadata.h"
@@ -46,37 +46,38 @@
* Hash tables are intentionally immutable, to avoid the need for locking.
*/
-typedef struct grpc_hash_table grpc_hash_table;
+typedef struct grpc_mdstr_hash_table grpc_mdstr_hash_table;
-typedef struct grpc_hash_table_vtable {
+typedef struct grpc_mdstr_hash_table_vtable {
void (*destroy_value)(void* value);
void* (*copy_value)(void* value);
int (*compare_value)(void* value1, void* value2);
-} grpc_hash_table_vtable;
+} grpc_mdstr_hash_table_vtable;
-typedef struct grpc_hash_table_entry {
+typedef struct grpc_mdstr_hash_table_entry {
grpc_mdstr* key;
void* value; /* Must not be NULL. */
- const grpc_hash_table_vtable* vtable;
-} grpc_hash_table_entry;
+ const grpc_mdstr_hash_table_vtable* vtable;
+} grpc_mdstr_hash_table_entry;
/** Creates a new hash table of containing \a entries, which is an array
of length \a num_entries.
Creates its own copy of all keys and values from \a entries. */
-grpc_hash_table* grpc_hash_table_create(size_t num_entries,
- grpc_hash_table_entry* entries);
+grpc_mdstr_hash_table* grpc_mdstr_hash_table_create(
+ size_t num_entries, grpc_mdstr_hash_table_entry* entries);
-grpc_hash_table* grpc_hash_table_ref(grpc_hash_table* table);
+grpc_mdstr_hash_table* grpc_mdstr_hash_table_ref(grpc_mdstr_hash_table* table);
/** Returns 1 when \a table is destroyed. */
-int grpc_hash_table_unref(grpc_hash_table* table);
+int grpc_mdstr_hash_table_unref(grpc_mdstr_hash_table* table);
/** Returns the value from \a table associated with \a key.
Returns NULL if \a key is not found. */
-void* grpc_hash_table_get(const grpc_hash_table* table, const grpc_mdstr* key);
+void* grpc_mdstr_hash_table_get(const grpc_mdstr_hash_table* table,
+ const grpc_mdstr* key);
/** Compares two hash tables.
The sort order is stable but undefined. */
-int grpc_hash_table_cmp(const grpc_hash_table* table1,
- const grpc_hash_table* table2);
+int grpc_mdstr_hash_table_cmp(const grpc_mdstr_hash_table* table1,
+ const grpc_mdstr_hash_table* table2);
-#endif /* GRPC_CORE_LIB_TRANSPORT_HASHTABLE_H */
+#endif /* GRPC_CORE_LIB_TRANSPORT_MDSTR_HASH_TABLE_H */