static void test_hash_random_pool(pool_t pool) { #define KEYMAX 100000 HASH_TABLE(void *, void *) hash; unsigned int *keys; unsigned int i, key, keyidx, delidx; keys = i_new(unsigned int, KEYMAX); keyidx = 0; hash_table_create_direct(&hash, pool, 0); for (i = 0; i < KEYMAX; i++) { key = (rand() % KEYMAX) + 1; if (rand() % 5 > 0) { if (hash_table_lookup(hash, POINTER_CAST(key)) == NULL) { hash_table_insert(hash, POINTER_CAST(key), POINTER_CAST(1)); keys[keyidx++] = key; } } else if (keyidx > 0) { delidx = rand() % keyidx; hash_table_remove(hash, POINTER_CAST(keys[delidx])); memmove(&keys[delidx], &keys[delidx+1], (keyidx-delidx-1) * sizeof(*keys)); keyidx--; } } for (i = 0; i < keyidx; i++) hash_table_remove(hash, POINTER_CAST(keys[i])); hash_table_destroy(&hash); i_free(keys); }
static struct replicator_connection *replicator_connection_create(void) { struct replicator_connection *conn; unsigned int i; conn = i_new(struct replicator_connection, 1); conn->fd = -1; hash_table_create_direct(&conn->requests, default_pool, 0); for (i = REPLICATION_PRIORITY_LOW; i <= REPLICATION_PRIORITY_SYNC; i++) conn->queue[i] = buffer_create_dynamic(default_pool, 1024); return conn; }
struct auth_server_connection * auth_server_connection_init(struct auth_client *client) { struct auth_server_connection *conn; pool_t pool; pool = pool_alloconly_create("auth server connection", 1024); conn = p_new(pool, struct auth_server_connection, 1); conn->pool = pool; conn->client = client; conn->fd = -1; hash_table_create_direct(&conn->requests, pool, 100); i_array_init(&conn->available_auth_mechs, 8); return conn; }
struct master_login_auth * master_login_auth_init(const char *auth_socket_path, bool request_auth_token) { struct master_login_auth *auth; pool_t pool; pool = pool_alloconly_create("master login auth", 1024); auth = p_new(pool, struct master_login_auth, 1); auth->pool = pool; auth->auth_socket_path = p_strdup(pool, auth_socket_path); auth->request_auth_token = request_auth_token; auth->refcount = 1; auth->fd = -1; hash_table_create_direct(&auth->requests, pool, 0); auth->id_counter = (rand() % 32767) * 131072U; return auth; }
struct auth_request_handler * auth_request_handler_create(bool token_auth, auth_request_callback_t *callback, void *context, auth_request_callback_t *master_callback) { struct auth_request_handler *handler; pool_t pool; pool = pool_alloconly_create("auth request handler", 4096); handler = p_new(pool, struct auth_request_handler, 1); handler->refcount = 1; handler->pool = pool; hash_table_create_direct(&handler->requests, pool, 0); handler->callback = callback; handler->context = context; handler->master_callback = master_callback; handler->token_auth = token_auth; return handler; }
static void mailbox_list_index_init_pool(struct mailbox_list_index *ilist) { ilist->mailbox_pool = pool_alloconly_create("mailbox list index", 4096); hash_table_create_direct(&ilist->mailbox_names, ilist->mailbox_pool, 0); hash_table_create_direct(&ilist->mailbox_hash, ilist->mailbox_pool, 0); }