Made return value of spdylay_map_init() void. Updated doc.

This commit is contained in:
Tatsuhiro Tsujikawa 2012-02-21 23:23:47 +09:00
parent 37944253d2
commit 9fa8357bbc
4 changed files with 45 additions and 9 deletions

View File

@ -24,11 +24,10 @@
*/
#include "spdylay_map.h"
int spdylay_map_init(spdylay_map *map)
void spdylay_map_init(spdylay_map *map)
{
map->root = NULL;
map->size = 0;
return 0;
}
static void spdylay_map_entry_free(spdylay_map_entry *entry)

View File

@ -49,18 +49,59 @@ typedef struct {
size_t size;
} spdylay_map;
int spdylay_map_init(spdylay_map *map);
/*
* Initializes the map |map|.
*/
void spdylay_map_init(spdylay_map *map);
/*
* Deallocates any resources allocated for |map|. The stored items are
* not freed by this function. Use spdylay_map_each() to free each
* item.
*/
void spdylay_map_free(spdylay_map *map);
/*
* Inserts the new item |val| with the key |key| to the map |map|.
*
* This function returns 0 if it succeeds, or one of the following
* negative error code:
*
* SPDYLAY_ERR_INVALID_ARGUMENT
* The item associated by |key| already exists.
*
* SPDYLAY_ERR_NOMEM
* Out of memory.
*/
int spdylay_map_insert(spdylay_map *map, key_type key, void *val);
/*
* Returns the item associated by the key |key|. If there is no such
* item, this function returns NULL.
*/
void* spdylay_map_find(spdylay_map *map, key_type key);
/*
* Erases the item associated by the key |key|. The erased item is
* not freed by this function.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* SPDYLAY_ERR_INVALID_ARGUMENT
* The item associated by |key| does not exist.
*/
void spdylay_map_erase(spdylay_map *map, key_type key);
/*
* Returns the number of items stored in the map |map|.
*/
size_t spdylay_map_size(spdylay_map *map);
/*
* Applies the function |func| to each key/item pair in the map |map|.
* This function is useful to free item in the map.
*/
void spdylay_map_each(spdylay_map *map, void (*func)(key_type key, void *val));
#endif /* SPDYLAY_MAP_H */

View File

@ -102,10 +102,7 @@ static int spdylay_session_new(spdylay_session **session_ptr,
if(r != 0) {
goto fail_hd_inflater;
}
r = spdylay_map_init(&(*session_ptr)->streams);
if(r != 0) {
goto fail_streams;
}
spdylay_map_init(&(*session_ptr)->streams);
r = spdylay_pq_init(&(*session_ptr)->ob_pq, spdylay_outbound_item_compar);
if(r != 0) {
goto fail_ob_pq;
@ -159,7 +156,6 @@ static int spdylay_session_new(spdylay_session **session_ptr,
spdylay_pq_free(&(*session_ptr)->ob_pq);
fail_ob_pq:
spdylay_map_free(&(*session_ptr)->streams);
fail_streams:
spdylay_zlib_inflate_free(&(*session_ptr)->hd_inflater);
fail_hd_inflater:
spdylay_zlib_deflate_free(&(*session_ptr)->hd_deflater);

View File

@ -31,7 +31,7 @@
void test_spdylay_map()
{
spdylay_map map;
CU_ASSERT(0 == spdylay_map_init(&map));
spdylay_map_init(&map);
CU_ASSERT(0 == spdylay_map_insert(&map, 1, "foo"));
CU_ASSERT(strcmp("foo", spdylay_map_find(&map, 1)) == 0);
CU_ASSERT(1 == spdylay_map_size(&map));