Commit a3c888d7 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttp2_map: Implement hash table

parent 1f0dfd43
This diff is collapsed.
......@@ -32,26 +32,31 @@
#include <nghttp2/nghttp2.h>
#include "nghttp2_int.h"
/* Implementation of ordered map */
/* Implementation of unordered map */
typedef uint32_t key_type;
typedef uint32_t pri_type;
typedef struct nghttp2_map_entry {
key_type key;
struct nghttp2_map_entry *parent, *left, *right;
pri_type priority;
struct nghttp2_map_entry *next;
} nghttp2_map_entry;
typedef struct {
nghttp2_map_entry *root;
nghttp2_map_entry **table;
size_t tablelen;
size_t size;
} nghttp2_map;
/*
* Initializes the map |map|.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP2_ERR_NOMEM
* Out of memory
*/
void nghttp2_map_init(nghttp2_map *map);
int nghttp2_map_init(nghttp2_map *map);
/*
* Deallocates any resources allocated for |map|. The stored entries
......@@ -80,10 +85,12 @@ void nghttp2_map_entry_init(nghttp2_map_entry *entry, key_type key);
* Inserts the new |entry| with the key |entry->key| to the map |map|.
*
* This function returns 0 if it succeeds, or one of the following
* negative error code:
* negative error codes:
*
* NGHTTP2_ERR_INVALID_ARGUMENT
* The item associated by |key| already exists.
* NGHTTP2_ERR_NOMEM
* Out of memory
*/
int nghttp2_map_insert(nghttp2_map *map, nghttp2_map_entry *entry);
......
......@@ -233,7 +233,10 @@ static int nghttp2_session_new(nghttp2_session **session_ptr,
if(r != 0) {
goto fail_hd_inflater;
}
nghttp2_map_init(&(*session_ptr)->streams);
r = nghttp2_map_init(&(*session_ptr)->streams);
if(r != 0) {
goto fail_map;
}
r = nghttp2_pq_init(&(*session_ptr)->ob_pq, nghttp2_outbound_item_compar);
if(r != 0) {
goto fail_ob_pq;
......@@ -294,7 +297,8 @@ static int nghttp2_session_new(nghttp2_session **session_ptr,
fail_ob_ss_pq:
nghttp2_pq_free(&(*session_ptr)->ob_pq);
fail_ob_pq:
/* No need to free (*session_ptr)->streams) here. */
nghttp2_map_free(&(*session_ptr)->streams);
fail_map:
nghttp2_hd_inflate_free(&(*session_ptr)->hd_inflater);
fail_hd_inflater:
nghttp2_hd_deflate_free(&(*session_ptr)->hd_deflater);
......@@ -389,6 +393,7 @@ void nghttp2_session_del(nghttp2_session *session)
free(session->inflight_iv);
nghttp2_inbound_frame_reset(session);
nghttp2_map_each_free(&session->streams, nghttp2_free_streams, NULL);
nghttp2_map_free(&session->streams);
nghttp2_session_ob_pq_free(&session->ob_pq);
nghttp2_session_ob_pq_free(&session->ob_ss_pq);
nghttp2_hd_deflate_free(&session->hd_deflater);
......@@ -397,7 +402,7 @@ void nghttp2_session_del(nghttp2_session *session)
free(session->aob.framebuf);
free(session->nvbuf);
free(session->iframe.buf);
free(session);
free(session);
}
static int outbound_item_update_pri
......
......@@ -149,6 +149,7 @@ void test_nghttp2_map_functional(void)
CU_ASSERT(0 == nghttp2_map_insert(&map, &arr[i].map_entry));
}
nghttp2_map_each_free(&map, eachfun, NULL);
nghttp2_map_free(&map);
}
static int entry_free(nghttp2_map_entry *entry, void *ptr)
......@@ -177,4 +178,5 @@ void test_nghttp2_map_each_free(void)
nghttp2_map_insert(&map, &shrubbery->map_entry);
nghttp2_map_each_free(&map, entry_free, NULL);
nghttp2_map_free(&map);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment