2 * nghttp2 - HTTP/2 C Library
4 * Copyright (c) 2012 Tatsuhiro Tsujikawa
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #endif /* HAVE_CONFIG_H */
32 #include <nghttp2/nghttp2.h>
33 #include "nghttp2_int.h"
34 #include "nghttp2_mem.h"
36 /* Implementation of unordered map */
38 typedef uint32_t key_type;
40 typedef struct nghttp2_map_entry {
41 struct nghttp2_map_entry *next;
44 /* we requires 8 bytes aligment */
50 nghttp2_map_entry **table;
57 * Initializes the map |map|.
59 * This function returns 0 if it succeeds, or one of the following
60 * negative error codes:
65 int nghttp2_map_init(nghttp2_map *map, nghttp2_mem *mem);
68 * Deallocates any resources allocated for |map|. The stored entries
69 * are not freed by this function. Use nghttp2_map_each_free() to free
72 void nghttp2_map_free(nghttp2_map *map);
75 * Deallocates each entries using |func| function and any resources
76 * allocated for |map|. The |func| function is responsible for freeing
77 * given the |entry| object. The |ptr| will be passed to the |func| as
78 * send argument. The return value of the |func| will be ignored.
80 void nghttp2_map_each_free(nghttp2_map *map,
81 int (*func)(nghttp2_map_entry *entry, void *ptr),
85 * Initializes the |entry| with the |key|. All entries to be inserted
86 * to the map must be initialized with this function.
88 void nghttp2_map_entry_init(nghttp2_map_entry *entry, key_type key);
91 * Inserts the new |entry| with the key |entry->key| to the map |map|.
93 * This function returns 0 if it succeeds, or one of the following
94 * negative error codes:
96 * NGHTTP2_ERR_INVALID_ARGUMENT
97 * The item associated by |key| already exists.
101 int nghttp2_map_insert(nghttp2_map *map, nghttp2_map_entry *entry);
104 * Returns the entry associated by the key |key|. If there is no such
105 * entry, this function returns NULL.
107 nghttp2_map_entry *nghttp2_map_find(nghttp2_map *map, key_type key);
110 * Removes the entry associated by the key |key| from the |map|. The
111 * removed entry is not freed by this function.
113 * This function returns 0 if it succeeds, or one of the following
114 * negative error codes:
116 * NGHTTP2_ERR_INVALID_ARGUMENT
117 * The entry associated by |key| does not exist.
119 int nghttp2_map_remove(nghttp2_map *map, key_type key);
122 * Returns the number of items stored in the map |map|.
124 size_t nghttp2_map_size(nghttp2_map *map);
127 * Applies the function |func| to each entry in the |map| with the
128 * optional user supplied pointer |ptr|.
130 * If the |func| returns 0, this function calls the |func| with the
131 * next entry. If the |func| returns nonzero, it will not call the
132 * |func| for further entries and return the return value of the
133 * |func| immediately. Thus, this function returns 0 if all the
134 * invocations of the |func| return 0, or nonzero value which the last
135 * invocation of |func| returns.
137 * Don't use this function to free each entry. Use
138 * nghttp2_map_each_free() instead.
140 int nghttp2_map_each(nghttp2_map *map,
141 int (*func)(nghttp2_map_entry *entry, void *ptr),
144 #endif /* NGHTTP2_MAP_H */