diff options
Diffstat (limited to 'runtime/docs/html/map_8c-source.html')
-rw-r--r-- | runtime/docs/html/map_8c-source.html | 1004 |
1 files changed, 518 insertions, 486 deletions
diff --git a/runtime/docs/html/map_8c-source.html b/runtime/docs/html/map_8c-source.html index 1ff69e73..4dac0d8f 100644 --- a/runtime/docs/html/map_8c-source.html +++ b/runtime/docs/html/map_8c-source.html @@ -4,20 +4,20 @@ <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.4.1 --> -<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div> -<h1>map.c</h1><a href="map_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="preprocessor">#ifndef _MAP_C_</span> -00002 <span class="preprocessor"></span><span class="preprocessor">#define _MAP_C_</span> -00003 <span class="preprocessor"></span> -00004 <span class="comment">/* -*- linux-c -*- */</span><span class="comment"></span> -00005 <span class="comment">/** @file map.c</span> -00006 <span class="comment"> * @brief Implements maps (associative arrays) and lists</span> -00007 <span class="comment"> */</span> -00008 -00009 <span class="preprocessor">#include "<a class="code" href="map_8h.html">map.h</a>"</span> -00010 <span class="preprocessor">#include "<a class="code" href="alloc_8c.html">alloc.c</a>"</span> +<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div> +<h1>map.c</h1><a href="map_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="preprocessor">#ifndef _MAP_C_ </span><span class="comment">/* -*- linux-c -*- */</span> +00002 <span class="preprocessor">#define _MAP_C_</span> +00003 <span class="preprocessor"></span><span class="comment"></span> +00004 <span class="comment">/** @file map.c</span> +00005 <span class="comment"> * @brief Implements maps (associative arrays) and lists</span> +00006 <span class="comment"> */</span> +00007 +00008 <span class="preprocessor">#include "<a class="code" href="map_8h.html">map.h</a>"</span> +00009 <span class="preprocessor">#include "<a class="code" href="alloc_8c.html">alloc.c</a>"</span> +00010 <span class="preprocessor">#include "<a class="code" href="string_8c.html">string.c</a>"</span> 00011 00012 <span class="keyword">static</span> <span class="keywordtype">int</span> map_sizes[] = { -00013 <span class="keyword">sizeof</span>(<span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a>), +00013 <span class="keyword">sizeof</span>(<span class="keyword">struct </span>map_node_int64), 00014 sizeof(struct map_node_stat), 00015 sizeof(struct map_node_str), 00016 0 @@ -61,17 +61,17 @@ 00054 <span class="comment"> * @return A MAP on success or NULL on failure.</span> 00055 <span class="comment"> */</span> 00056 -<a name="l00057"></a><a class="code" href="group__maps.html#ga2">00057</a> <a class="code" href="structmap__root.html">MAP</a> _stp_map_new(<span class="keywordtype">unsigned</span> max_entries, enum valtype type) +<a name="l00057"></a><a class="code" href="group__maps.html#ga2">00057</a> <a class="code" href="group__maps.html#ga1">MAP</a> _stp_map_new(<span class="keywordtype">unsigned</span> max_entries, enum valtype type) 00058 { 00059 size_t size; -00060 <a class="code" href="structmap__root.html">MAP</a> m = (<a class="code" href="structmap__root.html">MAP</a>) <a class="code" href="group__alloc.html#ga3">_stp_valloc</a>(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> <a class="code" href="structmap__root.html">map_root</a>)); +00060 <a class="code" href="group__maps.html#ga1">MAP</a> m = (<a class="code" href="group__maps.html#ga1">MAP</a>) <a class="code" href="group__alloc.html#ga3">_stp_valloc</a>(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> map_root)); 00061 <span class="keywordflow">if</span> (m == NULL) 00062 <span class="keywordflow">return</span> NULL; 00063 -00064 INIT_LIST_HEAD(&m-><a class="code" href="structmap__root.html#o4">head</a>); +00064 INIT_LIST_HEAD(&m->head); 00065 -00066 m-><a class="code" href="structmap__root.html#o1">maxnum</a> = max_entries; -00067 m-><a class="code" href="structmap__root.html#o0">type</a> = type; +00066 m->maxnum = max_entries; +00067 m->type = type; 00068 <span class="keywordflow">if</span> (type >= END) { 00069 dbug (<span class="stringliteral">"map_new: unknown type %d\n"</span>, type); 00070 <span class="keywordflow">return</span> NULL; @@ -82,37 +82,37 @@ 00075 <span class="keywordtype">int</span> i; 00076 <span class="keyword">struct </span>list_head *e; 00077 -00078 INIT_LIST_HEAD(&m-><a class="code" href="structmap__root.html#o5">pool</a>); +00078 INIT_LIST_HEAD(&m->pool); 00079 size = map_sizes[type]; 00080 tmp = <a class="code" href="group__alloc.html#ga3">_stp_valloc</a>(max_entries * size); 00081 00082 <span class="keywordflow">for</span> (i = max_entries - 1; i >= 0; i--) { 00083 e = i * size + tmp; 00084 dbug (<span class="stringliteral">"e=%lx\n"</span>, (<span class="keywordtype">long</span>)e); -00085 list_add(e, &m-><a class="code" href="structmap__root.html#o5">pool</a>); +00085 list_add(e, &m->pool); 00086 } -00087 m-><a class="code" href="structmap__root.html#o14">membuf</a> = tmp; +00087 m->membuf = tmp; 00088 } 00089 <span class="keywordflow">return</span> m; 00090 } 00091 -00092 <span class="keyword">static</span> <span class="keywordtype">void</span> map_free_strings(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *n) +00092 <span class="keyword">static</span> <span class="keywordtype">void</span> map_free_strings(<a class="code" href="group__maps.html#ga1">MAP</a> map, <span class="keyword">struct</span> map_node *n) 00093 { 00094 <span class="keyword">struct </span>map_node_str *m = (<span class="keyword">struct </span>map_node_str *)n; 00095 dbug (<span class="stringliteral">"n = %lx\n"</span>, (<span class="keywordtype">long</span>)n); -00096 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o0">type</a> == STRING) { -00097 dbug (<span class="stringliteral">"val STRING %lx\n"</span>, (<span class="keywordtype">long</span>)m-><a class="code" href="structmap__node__str.html#o1">str</a>); -00098 <span class="keywordflow">if</span> (m-><a class="code" href="structmap__node__str.html#o1">str</a>) +00096 <span class="keywordflow">if</span> (map->type == STRING) { +00097 dbug (<span class="stringliteral">"val STRING %lx\n"</span>, (<span class="keywordtype">long</span>)m->str); +00098 <span class="keywordflow">if</span> (m->str) 00099 _stp_free(m->str); 00100 } 00101 if (m->n.key1type == STR) { -00102 dbug (<span class="stringliteral">"key1 STR %lx\n"</span>, (<span class="keywordtype">long</span>)<a class="code" href="group__maps.html#ga24">key1str</a>(m)); -00103 <span class="keywordflow">if</span> (<a class="code" href="group__maps.html#ga24">key1str</a>(m)) +00102 dbug (<span class="stringliteral">"key1 STR %lx\n"</span>, (<span class="keywordtype">long</span>)<a class="code" href="group__maps.html#ga25">key1str</a>(m)); +00103 <span class="keywordflow">if</span> (<a class="code" href="group__maps.html#ga25">key1str</a>(m)) 00104 _stp_free(key1str(m)); 00105 } 00106 if (m->n.key2type == STR) { -00107 dbug (<span class="stringliteral">"key2 STR %lx\n"</span>, (<span class="keywordtype">long</span>)<a class="code" href="group__maps.html#ga25">key2str</a>(m)); -00108 <span class="keywordflow">if</span> (<a class="code" href="group__maps.html#ga25">key2str</a>(m)) +00107 dbug (<span class="stringliteral">"key2 STR %lx\n"</span>, (<span class="keywordtype">long</span>)<a class="code" href="group__maps.html#ga26">key2str</a>(m)); +00108 <span class="keywordflow">if</span> (<a class="code" href="group__maps.html#ga26">key2str</a>(m)) 00109 _stp_free(key2str(m)); 00110 } 00111 } @@ -122,9 +122,9 @@ 00115 <span class="comment"> * @param map </span> 00116 <span class="comment"> */</span> 00117 -<a name="l00118"></a><a class="code" href="group__maps.html#ga4">00118</a> <span class="keywordtype">void</span> _stp_map_key_del(<a class="code" href="structmap__root.html">MAP</a> map) +<a name="l00118"></a><a class="code" href="group__maps.html#ga4">00118</a> <span class="keywordtype">void</span> _stp_map_key_del(<a class="code" href="group__maps.html#ga1">MAP</a> map) 00119 { -00120 <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *m; +00120 <span class="keyword">struct </span>map_node *m; 00121 00122 dbug (<span class="stringliteral">"create=%d key=%lx\n"</span>, map->create, (<span class="keywordtype">long</span>)map->key); 00123 <span class="keywordflow">if</span> (map == NULL) @@ -139,19 +139,19 @@ 00132 <span class="keywordflow">if</span> (map->key == NULL) 00133 <span class="keywordflow">return</span>; 00134 -00135 m = (<span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *)map->key; +00135 m = (<span class="keyword">struct </span>map_node *)map->key; 00136 00137 <span class="comment">/* remove node from old hash list */</span> -00138 hlist_del_init(&m-><a class="code" href="structmap__node.html#o1">hnode</a>); +00138 hlist_del_init(&m->hnode); 00139 00140 <span class="comment">/* remove from entry list */</span> -00141 list_del(&m-><a class="code" href="structmap__node.html#o0">lnode</a>); +00141 list_del(&m->lnode); 00142 00143 <span class="comment">/* remove any allocated string storage */</span> -00144 map_free_strings(map, (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)map->key); +00144 map_free_strings(map, (<span class="keyword">struct</span> map_node *)map->key); 00145 00146 <span class="keywordflow">if</span> (map->maxnum) -00147 list_add(&m-><a class="code" href="structmap__node.html#o0">lnode</a>, &map->pool); +00147 list_add(&m->lnode, &map->pool); 00148 <span class="keywordflow">else</span> 00149 <a class="code" href="group__alloc.html#ga4">_stp_free</a>(m); 00150 @@ -167,17 +167,17 @@ 00160 <span class="comment"> * @sa foreach</span> 00161 <span class="comment"> */</span> 00162 -<a name="l00163"></a><a class="code" href="group__maps.html#ga5">00163</a> <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *<a class="code" href="group__maps.html#ga5">_stp_map_start</a>(<a class="code" href="structmap__root.html">MAP</a> map) +<a name="l00163"></a><a class="code" href="group__maps.html#ga5">00163</a> <span class="keyword">struct </span>map_node *<a class="code" href="group__maps.html#ga5">_stp_map_start</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map) 00164 { 00165 <span class="keywordflow">if</span> (map == NULL) 00166 <span class="keywordflow">return</span> NULL; 00167 -00168 dbug (<span class="stringliteral">"%lx\n"</span>, (<span class="keywordtype">long</span>)map-><a class="code" href="structmap__root.html#o4">head</a>.next); +00168 dbug (<span class="stringliteral">"%lx\n"</span>, (<span class="keywordtype">long</span>)map->head.next); 00169 -00170 <span class="keywordflow">if</span> (list_empty(&map-><a class="code" href="structmap__root.html#o4">head</a>)) +00170 <span class="keywordflow">if</span> (list_empty(&map->head)) 00171 <span class="keywordflow">return</span> NULL; 00172 -00173 <span class="keywordflow">return</span> (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)map-><a class="code" href="structmap__root.html#o4">head</a>.next; +00173 <span class="keywordflow">return</span> (<span class="keyword">struct</span> map_node *)map->head.next; 00174 } 00175 <span class="comment"></span> 00176 <span class="comment">/** Get the next element in a map.</span> @@ -190,18 +190,18 @@ 00183 <span class="comment"> * @sa foreach</span> 00184 <span class="comment"> */</span> 00185 -<a name="l00186"></a><a class="code" href="group__maps.html#ga6">00186</a> <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *<a class="code" href="group__maps.html#ga6">_stp_map_iter</a>(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *m) +<a name="l00186"></a><a class="code" href="group__maps.html#ga6">00186</a> <span class="keyword">struct </span>map_node *<a class="code" href="group__maps.html#ga6">_stp_map_iter</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, <span class="keyword">struct</span> map_node *m) 00187 { 00188 <span class="keywordflow">if</span> (map == NULL) 00189 <span class="keywordflow">return</span> NULL; 00190 00191 dbug (<span class="stringliteral">"%lx next=%lx prev=%lx map->head.next=%lx\n"</span>, (<span class="keywordtype">long</span>)m, -00192 (<span class="keywordtype">long</span>)m->lnode.next, (<span class="keywordtype">long</span>)m->lnode.prev, (<span class="keywordtype">long</span>)map-><a class="code" href="structmap__root.html#o4">head</a>.next); +00192 (<span class="keywordtype">long</span>)m->lnode.next, (<span class="keywordtype">long</span>)m->lnode.prev, (<span class="keywordtype">long</span>)map->head.next); 00193 -00194 <span class="keywordflow">if</span> (m->lnode.next == &map-><a class="code" href="structmap__root.html#o4">head</a>) +00194 <span class="keywordflow">if</span> (m->lnode.next == &map->head) 00195 <span class="keywordflow">return</span> NULL; 00196 -00197 <span class="keywordflow">return</span> (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)m-><a class="code" href="structmap__node.html#o0">lnode</a>.next; +00197 <span class="keywordflow">return</span> (<span class="keyword">struct</span> map_node *)m->lnode.next; 00198 } 00199 <span class="comment"></span> 00200 <span class="comment">/** Deletes a map.</span> @@ -209,19 +209,19 @@ 00202 <span class="comment"> * @param map</span> 00203 <span class="comment"> */</span> 00204 -<a name="l00205"></a><a class="code" href="group__maps.html#ga7">00205</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga7">_stp_map_del</a>(<a class="code" href="structmap__root.html">MAP</a> map) +<a name="l00205"></a><a class="code" href="group__maps.html#ga7">00205</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga7">_stp_map_del</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map) 00206 { 00207 <span class="keywordflow">if</span> (map == NULL) 00208 <span class="keywordflow">return</span>; 00209 -00210 <span class="keywordflow">if</span> (!list_empty(&map-><a class="code" href="structmap__root.html#o4">head</a>)) { -00211 <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *ptr = (<span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *)map-><a class="code" href="structmap__root.html#o4">head</a>.next; -00212 <span class="keywordflow">while</span> (ptr && ptr != (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)&map-><a class="code" href="structmap__root.html#o4">head</a>) { +00210 <span class="keywordflow">if</span> (!list_empty(&map->head)) { +00211 <span class="keyword">struct </span>map_node *ptr = (<span class="keyword">struct </span>map_node *)map->head.next; +00212 <span class="keywordflow">while</span> (ptr && ptr != (<span class="keyword">struct</span> map_node *)&map->head) { 00213 map_free_strings(map, ptr); -00214 ptr = (<span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *)ptr-><a class="code" href="structmap__node.html#o0">lnode</a>.next; +00214 ptr = (<span class="keyword">struct </span>map_node *)ptr->lnode.next; 00215 } 00216 } -00217 <a class="code" href="group__alloc.html#ga5">_stp_vfree</a>(map-><a class="code" href="structmap__root.html#o14">membuf</a>); +00217 <a class="code" href="group__alloc.html#ga5">_stp_vfree</a>(map->membuf); 00218 <a class="code" href="group__alloc.html#ga5">_stp_vfree</a>(map); 00219 } 00220 @@ -237,7 +237,7 @@ 00230 <span class="comment"> * @param key2 second key</span> 00231 <span class="comment"> */</span> 00232 -<a name="l00233"></a><a class="code" href="group__maps.html#ga8">00233</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga8">_stp_map_key_long_long</a>(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keywordtype">long</span> key1, <span class="keywordtype">long</span> key2) +<a name="l00233"></a><a class="code" href="group__maps.html#ga8">00233</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga8">_stp_map_key_long_long</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, <span class="keywordtype">long</span> key1, <span class="keywordtype">long</span> key2) 00234 { 00235 <span class="keywordtype">unsigned</span> hv; 00236 <span class="keyword">struct </span>hlist_head *head; @@ -247,28 +247,28 @@ 00240 <span class="keywordflow">return</span>; 00241 00242 hv = hash_long(key1 ^ key2, HASH_TABLE_BITS); -00243 head = &map-><a class="code" href="structmap__root.html#o13">hashes</a>[hv]; +00243 head = &map->hashes[hv]; 00244 00245 dbug (<span class="stringliteral">"hash for %ld,%ld is %d\n"</span>, key1, key2, hv); 00246 00247 hlist_for_each(e, head) { -00248 <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *n = -00249 (<span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *)((long)e - <span class="keyword">sizeof</span>(<span class="keyword">struct </span>hlist_node)); -00250 dbug (<span class="stringliteral">"n =%lx key=%ld,%ld\n"</span>, (<span class="keywordtype">long</span>)n, n-><a class="code" href="structmap__node.html#o2">key1</a>.<a class="code" href="unionkey__data.html#o0">val</a>, n->key2.<a class="code" href="unionkey__data.html#o0">val</a>); +00248 <span class="keyword">struct </span>map_node *n = +00249 (<span class="keyword">struct </span>map_node *)((long)e - <span class="keyword">sizeof</span>(<span class="keyword">struct </span>hlist_node)); +00250 dbug (<span class="stringliteral">"n =%lx key=%ld,%ld\n"</span>, (<span class="keywordtype">long</span>)n, n->key1.val, n->key2.val); 00251 <span class="keywordflow">if</span> (key1 == n->key1.val && key2 == n->key2.val) { -00252 map-><a class="code" href="structmap__root.html#o6">key</a> = n; -00253 dbug (<span class="stringliteral">"saving key %lx\n"</span>, (<span class="keywordtype">long</span>)map-><a class="code" href="structmap__root.html#o6">key</a>); -00254 map-><a class="code" href="structmap__root.html#o7">create</a> = 0; +00252 map->key = n; +00253 dbug (<span class="stringliteral">"saving key %lx\n"</span>, (<span class="keywordtype">long</span>)map->key); +00254 map->create = 0; 00255 <span class="keywordflow">return</span>; 00256 } 00257 } 00258 -00259 map-><a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o0">val</a> = key1; -00260 map-><a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o0">val</a> = key2; -00261 map-><a class="code" href="structmap__root.html#o8">c_key1type</a> = LONG; -00262 map-><a class="code" href="structmap__root.html#o9">c_key2type</a> = LONG; -00263 map-><a class="code" href="structmap__root.html#o10">c_keyhead</a> = head; -00264 map-><a class="code" href="structmap__root.html#o7">create</a> = 1; +00259 map->c_key1.val = key1; +00260 map->c_key2.val = key2; +00261 map->c_key1type = LONG; +00262 map->c_key2type = LONG; +00263 map->c_keyhead = head; +00264 map->create = 1; 00265 } 00266 <span class="comment"></span> 00267 <span class="comment">/** Set the map's key to two strings.</span> @@ -280,7 +280,7 @@ 00273 <span class="comment"> * @param key2 second key</span> 00274 <span class="comment"> */</span> 00275 -<a name="l00276"></a><a class="code" href="group__maps.html#ga9">00276</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga9">_stp_map_key_str_str</a>(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keywordtype">char</span> *key1, <span class="keywordtype">char</span> *key2) +<a name="l00276"></a><a class="code" href="group__maps.html#ga9">00276</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga9">_stp_map_key_str_str</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, <span class="keywordtype">char</span> *key1, <span class="keywordtype">char</span> *key2) 00277 { 00278 <span class="keywordtype">unsigned</span> hv; 00279 <span class="keyword">struct </span>hlist_head *head; @@ -290,34 +290,34 @@ 00283 <span class="keywordflow">return</span>; 00284 00285 <span class="keywordflow">if</span> (key1 == NULL) { -00286 map-><a class="code" href="structmap__root.html#o6">key</a> = NULL; +00286 map->key = NULL; 00287 <span class="keywordflow">return</span>; 00288 } 00289 00290 hv = string_hash(key1, key2); -00291 head = &map-><a class="code" href="structmap__root.html#o13">hashes</a>[hv]; +00291 head = &map->hashes[hv]; 00292 00293 dbug (<span class="stringliteral">"hash for %s,%s is %d\n"</span>, key1, key2, hv); 00294 00295 hlist_for_each(e, head) { -00296 <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *n = -00297 (<span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *)((long)e - <span class="keyword">sizeof</span>(<span class="keyword">struct </span>hlist_node)); -00298 dbug (<span class="stringliteral">"e =%lx key=%s,%s\n"</span>, (<span class="keywordtype">long</span>)e, n-><a class="code" href="structmap__node.html#o2">key1</a>.<a class="code" href="unionkey__data.html#o1">str</a>,n-><a class="code" href="structmap__node.html#o3">key2</a>.<a class="code" href="unionkey__data.html#o1">str</a>); -00299 <span class="keywordflow">if</span> (strcmp(key1, n-><a class="code" href="structmap__node.html#o2">key1</a>.<a class="code" href="unionkey__data.html#o1">str</a>) == 0 -00300 && (key2 == NULL || strcmp(key2, n-><a class="code" href="structmap__node.html#o3">key2</a>.<a class="code" href="unionkey__data.html#o1">str</a>) == 0)) { -00301 map-><a class="code" href="structmap__root.html#o6">key</a> = n; -00302 dbug (<span class="stringliteral">"saving key %lx\n"</span>, (<span class="keywordtype">long</span>)map-><a class="code" href="structmap__root.html#o6">key</a>); -00303 map-><a class="code" href="structmap__root.html#o7">create</a> = 0; +00296 <span class="keyword">struct </span>map_node *n = +00297 (<span class="keyword">struct </span>map_node *)((long)e - <span class="keyword">sizeof</span>(<span class="keyword">struct </span>hlist_node)); +00298 dbug (<span class="stringliteral">"e =%lx key=%s,%s\n"</span>, (<span class="keywordtype">long</span>)e, n->key1.str,n->key2.str); +00299 <span class="keywordflow">if</span> (strcmp(key1, n->key1.str) == 0 +00300 && (key2 == NULL || strcmp(key2, n->key2.str) == 0)) { +00301 map->key = n; +00302 dbug (<span class="stringliteral">"saving key %lx\n"</span>, (<span class="keywordtype">long</span>)map->key); +00303 map->create = 0; 00304 <span class="keywordflow">return</span>; 00305 } 00306 } 00307 -00308 map-><a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o1">str</a> = key1; -00309 map-><a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o1">str</a> = key2; -00310 map-><a class="code" href="structmap__root.html#o8">c_key1type</a> = STR; -00311 map-><a class="code" href="structmap__root.html#o9">c_key2type</a> = STR; -00312 map-><a class="code" href="structmap__root.html#o10">c_keyhead</a> = head; -00313 map-><a class="code" href="structmap__root.html#o7">create</a> = 1; +00308 map->c_key1.str = key1; +00309 map->c_key2.str = key2; +00310 map->c_key1type = STR; +00311 map->c_key2type = STR; +00312 map->c_keyhead = head; +00313 map->create = 1; 00314 } 00315 <span class="comment"></span> 00316 <span class="comment">/** Set the map's key to a string and a long.</span> @@ -329,7 +329,7 @@ 00322 <span class="comment"> * @param key2 second key</span> 00323 <span class="comment"> */</span> 00324 -<a name="l00325"></a><a class="code" href="group__maps.html#ga10">00325</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga10">_stp_map_key_str_long</a>(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keywordtype">char</span> *key1, <span class="keywordtype">long</span> key2) +<a name="l00325"></a><a class="code" href="group__maps.html#ga10">00325</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga10">_stp_map_key_str_long</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, <span class="keywordtype">char</span> *key1, <span class="keywordtype">long</span> key2) 00326 { 00327 <span class="keywordtype">unsigned</span> hv; 00328 <span class="keyword">struct </span>hlist_head *head; @@ -339,33 +339,33 @@ 00332 <span class="keywordflow">return</span>; 00333 00334 <span class="keywordflow">if</span> (key1 == NULL) { -00335 map-><a class="code" href="structmap__root.html#o6">key</a> = NULL; +00335 map->key = NULL; 00336 <span class="keywordflow">return</span>; 00337 } 00338 00339 hv = mixed_hash(key1, key2); -00340 head = &map-><a class="code" href="structmap__root.html#o13">hashes</a>[hv]; +00340 head = &map->hashes[hv]; 00341 00342 dbug (<span class="stringliteral">"hash for %s,%ld is %d\n"</span>, key1, key2, hv); 00343 00344 hlist_for_each(e, head) { -00345 <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *n = -00346 (<span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *)((long)e - <span class="keyword">sizeof</span>(<span class="keyword">struct </span>hlist_node)); -00347 dbug (<span class="stringliteral">"e =%lx key=%s,%ld\n"</span>, (<span class="keywordtype">long</span>)e, n-><a class="code" href="structmap__node.html#o2">key1</a>.<a class="code" href="unionkey__data.html#o1">str</a>,(<span class="keywordtype">long</span>)n-><a class="code" href="structmap__node.html#o3">key2</a>.<a class="code" href="unionkey__data.html#o0">val</a>); -00348 <span class="keywordflow">if</span> (strcmp(key1, n-><a class="code" href="structmap__node.html#o2">key1</a>.<a class="code" href="unionkey__data.html#o1">str</a>) == 0 && key2 == n-><a class="code" href="structmap__node.html#o3">key2</a>.<a class="code" href="unionkey__data.html#o0">val</a>) { -00349 map-><a class="code" href="structmap__root.html#o6">key</a> = n; -00350 dbug (<span class="stringliteral">"saving key %lx\n"</span>, (<span class="keywordtype">long</span>)map-><a class="code" href="structmap__root.html#o6">key</a>); -00351 map-><a class="code" href="structmap__root.html#o7">create</a> = 0; +00345 <span class="keyword">struct </span>map_node *n = +00346 (<span class="keyword">struct </span>map_node *)((long)e - <span class="keyword">sizeof</span>(<span class="keyword">struct </span>hlist_node)); +00347 dbug (<span class="stringliteral">"e =%lx key=%s,%ld\n"</span>, (<span class="keywordtype">long</span>)e, n->key1.str,(<span class="keywordtype">long</span>)n->key2.val); +00348 <span class="keywordflow">if</span> (strcmp(key1, n->key1.str) == 0 && key2 == n->key2.val) { +00349 map->key = n; +00350 dbug (<span class="stringliteral">"saving key %lx\n"</span>, (<span class="keywordtype">long</span>)map->key); +00351 map->create = 0; 00352 <span class="keywordflow">return</span>; 00353 } 00354 } 00355 -00356 map-><a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o1">str</a> = key1; -00357 map-><a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o0">val</a> = key2; -00358 map-><a class="code" href="structmap__root.html#o8">c_key1type</a> = STR; -00359 map-><a class="code" href="structmap__root.html#o9">c_key2type</a> = LONG; -00360 map-><a class="code" href="structmap__root.html#o10">c_keyhead</a> = head; -00361 map-><a class="code" href="structmap__root.html#o7">create</a> = 1; +00356 map->c_key1.str = key1; +00357 map->c_key2.val = key2; +00358 map->c_key1type = STR; +00359 map->c_key2type = LONG; +00360 map->c_keyhead = head; +00361 map->create = 1; 00362 } 00363 <span class="comment"></span> 00364 <span class="comment">/** Set the map's key to a long and a string.</span> @@ -377,7 +377,7 @@ 00370 <span class="comment"> * @param key2 second key</span> 00371 <span class="comment"> */</span> 00372 -<a name="l00373"></a><a class="code" href="group__maps.html#ga11">00373</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga11">_stp_map_key_long_str</a>(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keywordtype">long</span> key1, <span class="keywordtype">char</span> *key2) +<a name="l00373"></a><a class="code" href="group__maps.html#ga11">00373</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga11">_stp_map_key_long_str</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, <span class="keywordtype">long</span> key1, <span class="keywordtype">char</span> *key2) 00374 { 00375 <span class="keywordtype">unsigned</span> hv; 00376 <span class="keyword">struct </span>hlist_head *head; @@ -387,27 +387,27 @@ 00380 <span class="keywordflow">return</span>; 00381 00382 hv = mixed_hash(key2, key1); -00383 head = &map-><a class="code" href="structmap__root.html#o13">hashes</a>[hv]; +00383 head = &map->hashes[hv]; 00384 dbug (<span class="stringliteral">"hash for %ld,%s is %d\n"</span>, key1, key2, hv); 00385 00386 hlist_for_each(e, head) { -00387 <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *n = -00388 (<span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *)((long)e - <span class="keyword">sizeof</span>(<span class="keyword">struct </span>hlist_node)); -00389 dbug (<span class="stringliteral">"e =%lx key=%ld,%s\n"</span>, (<span class="keywordtype">long</span>)e, n-><a class="code" href="structmap__node.html#o2">key1</a>.<a class="code" href="unionkey__data.html#o0">val</a>,n-><a class="code" href="structmap__node.html#o3">key2</a>.<a class="code" href="unionkey__data.html#o1">str</a>); -00390 <span class="keywordflow">if</span> (key1 == n-><a class="code" href="structmap__node.html#o2">key1</a>.<a class="code" href="unionkey__data.html#o0">val</a> && strcmp(key2, n-><a class="code" href="structmap__node.html#o3">key2</a>.<a class="code" href="unionkey__data.html#o1">str</a>) == 0) { -00391 map-><a class="code" href="structmap__root.html#o6">key</a> = n; -00392 dbug (<span class="stringliteral">"saving key %lx\n"</span>, (<span class="keywordtype">long</span>)map-><a class="code" href="structmap__root.html#o6">key</a>); -00393 map-><a class="code" href="structmap__root.html#o7">create</a> = 0; +00387 <span class="keyword">struct </span>map_node *n = +00388 (<span class="keyword">struct </span>map_node *)((long)e - <span class="keyword">sizeof</span>(<span class="keyword">struct </span>hlist_node)); +00389 dbug (<span class="stringliteral">"e =%lx key=%ld,%s\n"</span>, (<span class="keywordtype">long</span>)e, n->key1.val,n->key2.str); +00390 <span class="keywordflow">if</span> (key1 == n->key1.val && strcmp(key2, n->key2.str) == 0) { +00391 map->key = n; +00392 dbug (<span class="stringliteral">"saving key %lx\n"</span>, (<span class="keywordtype">long</span>)map->key); +00393 map->create = 0; 00394 <span class="keywordflow">return</span>; 00395 } 00396 } 00397 -00398 map-><a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o0">val</a> = key1; -00399 map-><a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o1">str</a> = key2; -00400 map-><a class="code" href="structmap__root.html#o8">c_key1type</a> = LONG; -00401 map-><a class="code" href="structmap__root.html#o9">c_key2type</a> = STR; -00402 map-><a class="code" href="structmap__root.html#o10">c_keyhead</a> = head; -00403 map-><a class="code" href="structmap__root.html#o7">create</a> = 1; +00398 map->c_key1.val = key1; +00399 map->c_key2.str = key2; +00400 map->c_key1type = LONG; +00401 map->c_key2type = STR; +00402 map->c_keyhead = head; +00403 map->create = 1; 00404 } 00405 <span class="comment"></span> 00406 <span class="comment">/** Set the map's key to a string.</span> @@ -418,12 +418,12 @@ 00411 <span class="comment"> * @param key</span> 00412 <span class="comment"> */</span> 00413 -<a name="l00414"></a><a class="code" href="group__maps.html#ga12">00414</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga12">_stp_map_key_str</a>(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keywordtype">char</span> *key) +<a name="l00414"></a><a class="code" href="group__maps.html#ga12">00414</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga12">_stp_map_key_str</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, <span class="keywordtype">char</span> *key) 00415 { 00416 <span class="keywordflow">if</span> (map == NULL) 00417 <span class="keywordflow">return</span>; 00418 <a class="code" href="group__maps.html#ga9">_stp_map_key_str_str</a>(map, key, NULL); -00419 map-><a class="code" href="structmap__root.html#o9">c_key2type</a> = NONE; +00419 map->c_key2type = NONE; 00420 } 00421 <span class="comment"></span> 00422 <span class="comment">/** Set the map's key to a long.</span> @@ -434,55 +434,55 @@ 00427 <span class="comment"> * @param key </span> 00428 <span class="comment"> */</span> 00429 -<a name="l00430"></a><a class="code" href="group__maps.html#ga13">00430</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga13">_stp_map_key_long</a>(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keywordtype">long</span> key) +<a name="l00430"></a><a class="code" href="group__maps.html#ga13">00430</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga13">_stp_map_key_long</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, <span class="keywordtype">long</span> key) 00431 { 00432 <span class="keywordflow">if</span> (map == NULL) 00433 <span class="keywordflow">return</span>; 00434 <a class="code" href="group__maps.html#ga8">_stp_map_key_long_long</a>(map, key, 0); -00435 map-><a class="code" href="structmap__root.html#o9">c_key2type</a> = NONE; +00435 map->c_key2type = NONE; 00436 } 00437 00438 <span class="comment">/********************** SET/GET VALUES *********************/</span> 00439 -00440 <span class="keyword">static</span> <span class="keywordtype">void</span> map_copy_keys(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *m) +00440 <span class="keyword">static</span> <span class="keywordtype">void</span> map_copy_keys(<a class="code" href="group__maps.html#ga1">MAP</a> map, <span class="keyword">struct</span> map_node *m) 00441 { -00442 m->key1type = map-><a class="code" href="structmap__root.html#o8">c_key1type</a>; -00443 m->key2type = map-><a class="code" href="structmap__root.html#o9">c_key2type</a>; -00444 <span class="keywordflow">switch</span> (map-><a class="code" href="structmap__root.html#o8">c_key1type</a>) { +00442 m->key1type = map->c_key1type; +00443 m->key2type = map->c_key2type; +00444 <span class="keywordflow">switch</span> (map->c_key1type) { 00445 <span class="keywordflow">case</span> STR: -00446 m->key1.str = <a class="code" href="group__alloc.html#ga1">_stp_alloc</a>(strlen(map-><a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o1">str</a>) + 1); -00447 strcpy(m->key1.str, map-><a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o1">str</a>); +00446 m->key1.str = <a class="code" href="group__alloc.html#ga1">_stp_alloc</a>(strlen(map->c_key1.str) + 1); +00447 strcpy(m->key1.str, map->c_key1.str); 00448 <span class="keywordflow">break</span>; 00449 <span class="keywordflow">case</span> LONG: -00450 m->key1.val = map-><a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o0">val</a>; +00450 m->key1.val = map->c_key1.val; 00451 <span class="keywordflow">break</span>; 00452 <span class="keywordflow">case</span> NONE: 00453 <span class="comment">/* ERROR */</span> 00454 <span class="keywordflow">break</span>; 00455 } -00456 <span class="keywordflow">switch</span> (map-><a class="code" href="structmap__root.html#o9">c_key2type</a>) { +00456 <span class="keywordflow">switch</span> (map->c_key2type) { 00457 <span class="keywordflow">case</span> STR: -00458 m->key2.<a class="code" href="unionkey__data.html#o1">str</a> = <a class="code" href="group__alloc.html#ga1">_stp_alloc</a>(strlen(map-><a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o1">str</a>) + 1); -00459 strcpy(m->key2.str, map-><a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o1">str</a>); +00458 m->key2.str = <a class="code" href="group__alloc.html#ga1">_stp_alloc</a>(strlen(map->c_key2.str) + 1); +00459 strcpy(m->key2.str, map->c_key2.str); 00460 <span class="keywordflow">break</span>; 00461 <span class="keywordflow">case</span> LONG: -00462 m->key2.<a class="code" href="unionkey__data.html#o0">val</a> = map-><a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o0">val</a>; +00462 m->key2.val = map->c_key2.val; 00463 <span class="keywordflow">break</span>; 00464 <span class="keywordflow">case</span> NONE: 00465 <span class="keywordflow">break</span>; 00466 } 00467 00468 <span class="comment">/* add node to new hash list */</span> -00469 hlist_add_head(&m->hnode, map-><a class="code" href="structmap__root.html#o10">c_keyhead</a>); +00469 hlist_add_head(&m->hnode, map->c_keyhead); 00470 -00471 map-><a class="code" href="structmap__root.html#o6">key</a> = m; -00472 map-><a class="code" href="structmap__root.html#o7">create</a> = 0; -00473 map-><a class="code" href="structmap__root.html#o2">num</a>++; +00471 map->key = m; +00472 map->create = 0; +00473 map->num++; 00474 } 00475 -00476 <span class="keyword">static</span> <span class="keywordtype">void</span> __stp_map_set_int64(<a class="code" href="structmap__root.html">MAP</a> map, int64_t val, <span class="keywordtype">int</span> add) +00476 <span class="keyword">static</span> <span class="keywordtype">void</span> __stp_map_set_int64(<a class="code" href="group__maps.html#ga1">MAP</a> map, int64_t val, <span class="keywordtype">int</span> add) 00477 { -00478 <span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *m; +00478 <span class="keyword">struct </span>map_node_int64 *m; 00479 00480 <span class="keywordflow">if</span> (map == NULL) 00481 return; @@ -492,38 +492,38 @@ 00485 return; 00486 00487 if (map->maxnum) { -00488 <span class="keywordflow">if</span> (list_empty(&map-><a class="code" href="structmap__root.html#o5">pool</a>)) { -00489 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o3">no_wrap</a>) { +00488 <span class="keywordflow">if</span> (list_empty(&map->pool)) { +00489 <span class="keywordflow">if</span> (map->no_wrap) { 00490 <span class="comment">/* ERROR. FIXME */</span> 00491 <span class="keywordflow">return</span>; 00492 } -00493 m = (<span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *)map-><a class="code" href="structmap__root.html#o4">head</a>.next; -00494 hlist_del_init(&m-><a class="code" href="structmap__node__int64.html#o0">n</a>.<a class="code" href="structmap__node.html#o1">hnode</a>); -00495 map_free_strings(map, (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)m); +00493 m = (<span class="keyword">struct </span>map_node_int64 *)map->head.next; +00494 hlist_del_init(&m->n.hnode); +00495 map_free_strings(map, (<span class="keyword">struct</span> map_node *)m); 00496 dbug (<span class="stringliteral">"got %lx off head\n"</span>, (<span class="keywordtype">long</span>)m); 00497 } <span class="keywordflow">else</span> { -00498 m = (<span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *)map-><a class="code" href="structmap__root.html#o5">pool</a>.next; +00498 m = (<span class="keyword">struct </span>map_node_int64 *)map->pool.next; 00499 dbug (<span class="stringliteral">"got %lx off pool\n"</span>, (<span class="keywordtype">long</span>)m); 00500 } -00501 list_move_tail(&m-><a class="code" href="structmap__node__int64.html#o0">n</a>.<a class="code" href="structmap__node.html#o0">lnode</a>, &map-><a class="code" href="structmap__root.html#o4">head</a>); +00501 list_move_tail(&m->n.lnode, &map->head); 00502 } <span class="keywordflow">else</span> { -00503 m = (<span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *) -00504 <a class="code" href="group__alloc.html#ga2">_stp_calloc</a>(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> <a class="code" href="structmap__node__int64.html">map_node_int64</a>)); +00503 m = (<span class="keyword">struct </span>map_node_int64 *) +00504 <a class="code" href="group__alloc.html#ga2">_stp_calloc</a>(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> map_node_int64)); 00505 <span class="comment">/* add node to list */</span> -00506 list_add_tail(&m-><a class="code" href="structmap__node__int64.html#o0">n</a>.<a class="code" href="structmap__node.html#o0">lnode</a>, &map-><a class="code" href="structmap__root.html#o4">head</a>); +00506 list_add_tail(&m->n.lnode, &map->head); 00507 } 00508 00509 <span class="comment">/* copy the key(s) */</span> -00510 map_copy_keys(map, &m-><a class="code" href="structmap__node__int64.html#o0">n</a>); +00510 map_copy_keys(map, &m->n); 00511 00512 <span class="comment">/* set the value */</span> -00513 m-><a class="code" href="structmap__node__int64.html#o1">val</a> = val; +00513 m->val = val; 00514 } <span class="keywordflow">else</span> { -00515 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o6">key</a> == NULL) +00515 <span class="keywordflow">if</span> (map->key == NULL) 00516 return; 00517 00518 if (val) { -00519 m = (<span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *)map-><a class="code" href="structmap__root.html#o6">key</a>; +00519 m = (<span class="keyword">struct </span>map_node_int64 *)map->key; 00520 <span class="keywordflow">if</span> (add) 00521 m->val += val; 00522 else @@ -544,345 +544,377 @@ 00537 <span class="comment"> * @param map</span> 00538 <span class="comment"> * @param val new value</span> 00539 <span class="comment"> * @sa _stp_map_add_int64</span> -00540 <span class="comment"> */</span> -<a name="l00541"></a><a class="code" href="group__maps.html#ga16">00541</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga16">_stp_map_set_int64</a>(<a class="code" href="structmap__root.html">MAP</a> map, int64_t val) -00542 { -00543 __stp_map_set_int64 (map, val, 0); -00544 } -00545 -00546 <span class="comment"></span> -00547 <span class="comment">/** Adds an int64 to the current element's value.</span> -00548 <span class="comment"> * This adds an int64 to the current element's value. The map must have been created</span> -00549 <span class="comment"> * to hold int64s using _stp_map_new()</span> -00550 <span class="comment"> *</span> -00551 <span class="comment"> * If the element doesn't exist, it is created. If no current element (key)</span> -00552 <span class="comment"> * is set for the map, this function does nothing.</span> -00553 <span class="comment"> * @param map</span> -00554 <span class="comment"> * @param val value</span> -00555 <span class="comment"> * @sa _stp_map_set_int64</span> -00556 <span class="comment"> */</span> -00557 -<a name="l00558"></a><a class="code" href="group__maps.html#ga17">00558</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga17">_stp_map_add_int64</a>(<a class="code" href="structmap__root.html">MAP</a> map, int64_t val) -00559 { -00560 __stp_map_set_int64 (map, val, 1); -00561 } -00562 <span class="comment"></span> -00563 <span class="comment">/** Gets the current element's value.</span> -00564 <span class="comment"> * @param map</span> -00565 <span class="comment"> * @returns The value. If the current element is not set or doesn't exist, returns 0.</span> -00566 <span class="comment"> */</span> -00567 -<a name="l00568"></a><a class="code" href="group__maps.html#ga18">00568</a> int64_t <a class="code" href="group__maps.html#ga18">_stp_map_get_int64</a>(<a class="code" href="structmap__root.html">MAP</a> map) -00569 { -00570 <span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *m; -00571 <span class="keywordflow">if</span> (map == NULL || map-><a class="code" href="structmap__root.html#o7">create</a> || map-><a class="code" href="structmap__root.html#o6">key</a> == NULL) -00572 <span class="keywordflow">return</span> 0; -00573 dbug (<span class="stringliteral">"%lx\n"</span>, (<span class="keywordtype">long</span>)map-><a class="code" href="structmap__root.html#o6">key</a>); -00574 m = (<span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *)map-><a class="code" href="structmap__root.html#o6">key</a>; -00575 <span class="keywordflow">return</span> m-><a class="code" href="structmap__node__int64.html#o1">val</a>; -00576 } -00577 <span class="comment"></span> -00578 <span class="comment">/** Set the current element's value to a string.</span> -00579 <span class="comment"> * This sets the current element's value to an string. The map must have been created</span> -00580 <span class="comment"> * to hold int64s using <i>_stp_map_new(xxx, STRING)</i></span> -00581 <span class="comment"> *</span> -00582 <span class="comment"> * If the element doesn't exist, it is created. If no current element (key)</span> -00583 <span class="comment"> * is set for the map, this function does nothing.</span> -00584 <span class="comment"> * @param map</span> -00585 <span class="comment"> * @param val new string</span> -00586 <span class="comment"> */</span> -00587 -<a name="l00588"></a><a class="code" href="group__maps.html#ga19">00588</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga19">_stp_map_set_str</a>(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keywordtype">char</span> *val) -00589 { -00590 <span class="keyword">struct </span>map_node_str *m; -00591 -00592 <span class="keywordflow">if</span> (map == NULL) -00593 <span class="keywordflow">return</span>; -00594 -00595 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o7">create</a>) { -00596 <span class="keywordflow">if</span> (val == NULL) -00597 <span class="keywordflow">return</span>; -00598 -00599 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o1">maxnum</a>) { -00600 <span class="keywordflow">if</span> (list_empty(&map-><a class="code" href="structmap__root.html#o5">pool</a>)) { -00601 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o3">no_wrap</a>) { -00602 <span class="comment">/* ERROR. FIXME */</span> -00603 <span class="keywordflow">return</span>; -00604 } -00605 m = (<span class="keyword">struct </span>map_node_str *)map-><a class="code" href="structmap__root.html#o4">head</a>.next; -00606 hlist_del_init(&m-><a class="code" href="structmap__node__str.html#o0">n</a>.<a class="code" href="structmap__node.html#o1">hnode</a>); -00607 map_free_strings(map, (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)m); -00608 dbug (<span class="stringliteral">"got %lx off head\n"</span>, (<span class="keywordtype">long</span>)m); -00609 } <span class="keywordflow">else</span> { -00610 m = (<span class="keyword">struct </span>map_node_str *)map-><a class="code" href="structmap__root.html#o5">pool</a>.next; -00611 dbug (<span class="stringliteral">"got %lx off pool\n"</span>, (<span class="keywordtype">long</span>)m); -00612 } -00613 list_move_tail(&m-><a class="code" href="structmap__node__str.html#o0">n</a>.<a class="code" href="structmap__node.html#o0">lnode</a>, &map-><a class="code" href="structmap__root.html#o4">head</a>); -00614 } <span class="keywordflow">else</span> { -00615 m = (<span class="keyword">struct </span>map_node_str *) -00616 <a class="code" href="group__alloc.html#ga2">_stp_calloc</a>(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> map_node_str)); -00617 <span class="comment">/* add node to list */</span> -00618 list_add_tail(&m-><a class="code" href="structmap__node__str.html#o0">n</a>.<a class="code" href="structmap__node.html#o0">lnode</a>, &map-><a class="code" href="structmap__root.html#o4">head</a>); -00619 } -00620 -00621 <span class="comment">/* copy the key(s) */</span> -00622 map_copy_keys(map, &m-><a class="code" href="structmap__node__str.html#o0">n</a>); -00623 -00624 <span class="comment">/* set the value */</span> -00625 m-><a class="code" href="structmap__node__str.html#o1">str</a> = <a class="code" href="group__alloc.html#ga1">_stp_alloc</a>(strlen(val) + 1); -00626 strcpy(m-><a class="code" href="structmap__node__str.html#o1">str</a>, val); -00627 } <span class="keywordflow">else</span> { -00628 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o6">key</a> == NULL) -00629 <span class="keywordflow">return</span>; -00630 -00631 <span class="keywordflow">if</span> (val) { -00632 m = (<span class="keyword">struct </span>map_node_str *)map-><a class="code" href="structmap__root.html#o6">key</a>; -00633 <span class="keywordflow">if</span> (m-><a class="code" href="structmap__node__str.html#o1">str</a>) -00634 <a class="code" href="group__alloc.html#ga4">_stp_free</a>(m-><a class="code" href="structmap__node__str.html#o1">str</a>); -00635 m-><a class="code" href="structmap__node__str.html#o1">str</a> = <a class="code" href="group__alloc.html#ga1">_stp_alloc</a>(strlen(val) + 1); -00636 strcpy(m-><a class="code" href="structmap__node__str.html#o1">str</a>, val); -00637 } <span class="keywordflow">else</span> { -00638 <span class="comment">/* setting value to 0 is the same as deleting */</span> -00639 <a class="code" href="group__maps.html#ga4">_stp_map_key_del</a>(map); -00640 } -00641 } -00642 } -00643 <span class="comment"></span> -00644 <span class="comment">/** Gets the current element's value.</span> -00645 <span class="comment"> * @param map</span> -00646 <span class="comment"> * @returns A string pointer. If the current element is not set or doesn't exist, returns NULL.</span> -00647 <span class="comment"> */</span> -00648 -<a name="l00649"></a><a class="code" href="group__maps.html#ga20">00649</a> <span class="keywordtype">char</span> *<a class="code" href="group__maps.html#ga20">_stp_map_get_str</a>(<a class="code" href="structmap__root.html">MAP</a> map) -00650 { -00651 <span class="keyword">struct </span>map_node_str *m; -00652 <span class="keywordflow">if</span> (map == NULL || map-><a class="code" href="structmap__root.html#o7">create</a> || map-><a class="code" href="structmap__root.html#o6">key</a> == NULL) -00653 <span class="keywordflow">return</span> NULL; -00654 dbug (<span class="stringliteral">"%lx\n"</span>, (<span class="keywordtype">long</span>)map-><a class="code" href="structmap__root.html#o6">key</a>); -00655 m = (<span class="keyword">struct </span>map_node_str *)map-><a class="code" href="structmap__root.html#o6">key</a>; -00656 <span class="keywordflow">return</span> m-><a class="code" href="structmap__node__str.html#o1">str</a>; -00657 } -00658 <span class="comment"></span> -00659 <span class="comment">/** Set the current element's value to a stat.</span> -00660 <span class="comment"> * This sets the current element's value to an stat struct. The map must have been created</span> -00661 <span class="comment"> * to hold stats using <i>_stp_map_new(xxx, STAT)</i>. This function would only be used</span> -00662 <span class="comment"> * if we wanted to set stats to something other than the normal initial values (count = 0,</span> -00663 <span class="comment"> * sum = 0, etc). It may be deleted if it doesn't turn out to be useful.</span> -00664 <span class="comment"> * @sa _stp_map_stat_add </span> -00665 <span class="comment"> *</span> -00666 <span class="comment"> * If the element doesn't exist, it is created. If no current element (key)</span> -00667 <span class="comment"> * is set for the map, this function does nothing.</span> -00668 <span class="comment"> * @param map</span> -00669 <span class="comment"> * @param stats pointer to stats struct.</span> -00670 <span class="comment"> * @todo Histograms don't work yet.</span> -00671 <span class="comment"> */</span> -00672 -<a name="l00673"></a><a class="code" href="group__maps.html#ga21">00673</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga21">_stp_map_set_stat</a>(<a class="code" href="structmap__root.html">MAP</a> map, <a class="code" href="structstat.html">stat</a> * stats) -00674 { -00675 <span class="keyword">struct </span>map_node_stat *m; -00676 -00677 <span class="keywordflow">if</span> (map == NULL) -00678 <span class="keywordflow">return</span>; -00679 dbug (<span class="stringliteral">"set_stat %lx\n"</span>, (<span class="keywordtype">long</span>)map-><a class="code" href="structmap__root.html#o6">key</a>); -00680 -00681 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o7">create</a>) { -00682 <span class="keywordflow">if</span> (stats == NULL) -00683 <span class="keywordflow">return</span>; -00684 -00685 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o1">maxnum</a>) { -00686 <span class="keywordflow">if</span> (list_empty(&map-><a class="code" href="structmap__root.html#o5">pool</a>)) { -00687 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o3">no_wrap</a>) { -00688 <span class="comment">/* ERROR. FIXME */</span> -00689 <span class="keywordflow">return</span>; -00690 } -00691 m = (<span class="keyword">struct </span>map_node_stat *)map-><a class="code" href="structmap__root.html#o4">head</a>.next; -00692 hlist_del_init(&m-><a class="code" href="structmap__node__stat.html#o0">n</a>.<a class="code" href="structmap__node.html#o1">hnode</a>); -00693 map_free_strings(map, (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)m); -00694 dbug (<span class="stringliteral">"got %lx off head\n"</span>, (<span class="keywordtype">long</span>)m); -00695 } <span class="keywordflow">else</span> { -00696 m = (<span class="keyword">struct </span>map_node_stat *)map-><a class="code" href="structmap__root.html#o5">pool</a>.next; -00697 dbug (<span class="stringliteral">"got %lx off pool\n"</span>, (<span class="keywordtype">long</span>)m); -00698 } -00699 list_move_tail(&m-><a class="code" href="structmap__node__stat.html#o0">n</a>.<a class="code" href="structmap__node.html#o0">lnode</a>, &map-><a class="code" href="structmap__root.html#o4">head</a>); -00700 } <span class="keywordflow">else</span> { -00701 m = (<span class="keyword">struct </span>map_node_stat *) -00702 <a class="code" href="group__alloc.html#ga2">_stp_calloc</a>(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> map_node_stat)); -00703 <span class="comment">/* add node to list */</span> -00704 list_add_tail(&m-><a class="code" href="structmap__node__stat.html#o0">n</a>.<a class="code" href="structmap__node.html#o0">lnode</a>, &map-><a class="code" href="structmap__root.html#o4">head</a>); -00705 } -00706 -00707 <span class="comment">/* copy the key(s) */</span> -00708 map_copy_keys(map, &m-><a class="code" href="structmap__node__stat.html#o0">n</a>); -00709 -00710 <span class="comment">/* set the value */</span> -00711 memcpy(&m-><a class="code" href="structmap__node__stat.html#o1">stats</a>, stats, <span class="keyword">sizeof</span>(<a class="code" href="structstat.html">stat</a>)); -00712 } <span class="keywordflow">else</span> { -00713 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o6">key</a> == NULL) -00714 <span class="keywordflow">return</span>; -00715 -00716 <span class="keywordflow">if</span> (stats) { -00717 m = (<span class="keyword">struct </span>map_node_stat *)map-><a class="code" href="structmap__root.html#o6">key</a>; -00718 memcpy(&m-><a class="code" href="structmap__node__stat.html#o1">stats</a>, stats, <span class="keyword">sizeof</span>(<a class="code" href="structstat.html">stat</a>)); -00719 } <span class="keywordflow">else</span> { -00720 <span class="comment">/* setting value to NULL is the same as deleting */</span> -00721 <a class="code" href="group__maps.html#ga4">_stp_map_key_del</a>(map); -00722 } -00723 } -00724 } -00725 <span class="comment"></span> -00726 <span class="comment">/** Gets the current element's value.</span> -00727 <span class="comment"> * @param map</span> -00728 <span class="comment"> * @returns A pointer to the stats struct. If the current element is not set </span> -00729 <span class="comment"> * or doesn't exist, returns NULL.</span> -00730 <span class="comment"> */</span> -00731 -<a name="l00732"></a><a class="code" href="group__maps.html#ga22">00732</a> <a class="code" href="structstat.html">stat</a> *<a class="code" href="group__maps.html#ga22">_stp_map_get_stat</a>(<a class="code" href="structmap__root.html">MAP</a> map) -00733 { -00734 <span class="keyword">struct </span>map_node_stat *m; -00735 <span class="keywordflow">if</span> (map == NULL || map-><a class="code" href="structmap__root.html#o7">create</a> || map-><a class="code" href="structmap__root.html#o6">key</a> == NULL) -00736 <span class="keywordflow">return</span> NULL; -00737 dbug (<span class="stringliteral">"%lx\n"</span>, (<span class="keywordtype">long</span>)map-><a class="code" href="structmap__root.html#o6">key</a>); -00738 m = (<span class="keyword">struct </span>map_node_stat *)map-><a class="code" href="structmap__root.html#o6">key</a>; -00739 <span class="keywordflow">return</span> &m-><a class="code" href="structmap__node__stat.html#o1">stats</a>; -00740 } -00741 <span class="comment"></span> -00742 <span class="comment">/** Add to the current element's statistics.</span> -00743 <span class="comment"> * Increments the statistics counter by one and the sum by <i>val</i>.</span> -00744 <span class="comment"> * Adjusts minimum, maximum, and histogram.</span> -00745 <span class="comment"> *</span> -00746 <span class="comment"> * If the element doesn't exist, it is created. If no current element (key)</span> -00747 <span class="comment"> * is set for the map, this function does nothing.</span> -00748 <span class="comment"> * @param map</span> -00749 <span class="comment"> * @param val value to add to the statistics</span> -00750 <span class="comment"> * @todo Histograms don't work yet.</span> -00751 <span class="comment"> */</span> -00752 -<a name="l00753"></a><a class="code" href="group__maps.html#ga23">00753</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga23">_stp_map_stat_add</a>(<a class="code" href="structmap__root.html">MAP</a> map, int64_t val) -00754 { -00755 <span class="keyword">struct </span>map_node_stat *m; -00756 <span class="keywordflow">if</span> (map == NULL) -00757 <span class="keywordflow">return</span>; -00758 -00759 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o7">create</a>) { -00760 <a class="code" href="structstat.html">stat</a> st = { 1, val, val, val }; -00761 <span class="comment">/* histogram */</span> -00762 <a class="code" href="group__maps.html#ga21">_stp_map_set_stat</a>(map, &st); -00763 <span class="keywordflow">return</span>; -00764 } -00765 -00766 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o6">key</a> == NULL) -00767 <span class="keywordflow">return</span>; -00768 -00769 dbug (<span class="stringliteral">"add_stat %lx\n"</span>, (<span class="keywordtype">long</span>)map-><a class="code" href="structmap__root.html#o6">key</a>); -00770 m = (<span class="keyword">struct </span>map_node_stat *)map-><a class="code" href="structmap__root.html#o6">key</a>; -00771 m-><a class="code" href="structmap__node__stat.html#o1">stats</a>.<a class="code" href="structstat.html#o0">count</a>++; -00772 m-><a class="code" href="structmap__node__stat.html#o1">stats</a>.<a class="code" href="structstat.html#o1">sum</a> += val; -00773 <span class="keywordflow">if</span> (val > m-><a class="code" href="structmap__node__stat.html#o1">stats</a>.<a class="code" href="structstat.html#o3">max</a>) -00774 m-><a class="code" href="structmap__node__stat.html#o1">stats</a>.<a class="code" href="structstat.html#o3">max</a> = val; -00775 <span class="keywordflow">if</span> (val < m->stats.min) -00776 m-><a class="code" href="structmap__node__stat.html#o1">stats</a>.<a class="code" href="structstat.html#o2">min</a> = val; -00777 <span class="comment">/* histogram */</span> -00778 } -00779 <span class="comment"></span> -00780 <span class="comment">/** @} */</span> -00781 -00782 <span class="comment">/********************** List Functions *********************/</span> -00783 <span class="comment"></span> -00784 <span class="comment">/** @addtogroup lists</span> -00785 <span class="comment"> * Lists are special cases of maps.</span> -00786 <span class="comment"> * @b Example:</span> -00787 <span class="comment"> * @include list.c</span> -00788 <span class="comment"> * @{ */</span> -00789 <span class="comment"></span> -00790 <span class="comment">/** Create a new list.</span> -00791 <span class="comment"> * A list is a map that internally has an incrementing long key for each member.</span> -00792 <span class="comment"> * Lists do not wrap if elements are added to exceed their maximum size.</span> -00793 <span class="comment"> * @param max_entries The maximum number of entries allowed. Currently that number will</span> -00794 <span class="comment"> * be preallocated. If max_entries is 0, there will be no maximum and entries</span> -00795 <span class="comment"> * will be allocated dynamically.</span> -00796 <span class="comment"> * @param type Type of values stored in this list. </span> -00797 <span class="comment"> * @return A MAP on success or NULL on failure.</span> -00798 <span class="comment"> * @sa foreach</span> -00799 <span class="comment"> */</span> -00800 -<a name="l00801"></a><a class="code" href="group__lists.html#ga0">00801</a> <a class="code" href="structmap__root.html">MAP</a> <a class="code" href="group__lists.html#ga0">_stp_list_new</a>(<span class="keywordtype">unsigned</span> max_entries, <span class="keyword">enum</span> valtype type) -00802 { -00803 <a class="code" href="structmap__root.html">MAP</a> map = <a class="code" href="group__maps.html#ga2">_stp_map_new</a> (max_entries, type); -00804 map-><a class="code" href="structmap__root.html#o3">no_wrap</a> = 1; -00805 <span class="keywordflow">return</span> map; -00806 } +00540 <span class="comment"> * @sa _stp_map_set()</span> +00541 <span class="comment"> */</span> +<a name="l00542"></a><a class="code" href="group__maps.html#ga16">00542</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga16">_stp_map_set_int64</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, int64_t val) +00543 { +00544 __stp_map_set_int64 (map, val, 0); +00545 } +00546 +00547 <span class="comment"></span> +00548 <span class="comment">/** Adds an int64 to the current element's value.</span> +00549 <span class="comment"> * This adds an int64 to the current element's value. The map must have been created</span> +00550 <span class="comment"> * to hold int64s using _stp_map_new()</span> +00551 <span class="comment"> *</span> +00552 <span class="comment"> * If the element doesn't exist, it is created. If no current element (key)</span> +00553 <span class="comment"> * is set for the map, this function does nothing.</span> +00554 <span class="comment"> * @param map</span> +00555 <span class="comment"> * @param val value</span> +00556 <span class="comment"> * @sa _stp_map_set_int64</span> +00557 <span class="comment"> */</span> +00558 +<a name="l00559"></a><a class="code" href="group__maps.html#ga17">00559</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga17">_stp_map_add_int64</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, int64_t val) +00560 { +00561 __stp_map_set_int64 (map, val, 1); +00562 } +00563 <span class="comment"></span> +00564 <span class="comment">/** Gets the current element's value.</span> +00565 <span class="comment"> * @param map</span> +00566 <span class="comment"> * @returns The value. If the current element is not set or doesn't exist, returns 0.</span> +00567 <span class="comment"> */</span> +00568 +<a name="l00569"></a><a class="code" href="group__maps.html#ga18">00569</a> int64_t <a class="code" href="group__maps.html#ga18">_stp_map_get_int64</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map) +00570 { +00571 <span class="keyword">struct </span>map_node_int64 *m; +00572 <span class="keywordflow">if</span> (map == NULL || map->create || map->key == NULL) +00573 <span class="keywordflow">return</span> 0; +00574 dbug (<span class="stringliteral">"%lx\n"</span>, (<span class="keywordtype">long</span>)map->key); +00575 m = (<span class="keyword">struct </span>map_node_int64 *)map->key; +00576 <span class="keywordflow">return</span> m->val; +00577 } +00578 <span class="comment"></span> +00579 <span class="comment">/** Set the current element's value to a C string.</span> +00580 <span class="comment"> * This sets the current element's value to an C string. The map must have been created</span> +00581 <span class="comment"> * to hold int64s using <i>_stp_map_new(xxx, STRING)</i></span> +00582 <span class="comment"> *</span> +00583 <span class="comment"> * If the element doesn't exist, it is created. If no current element (key)</span> +00584 <span class="comment"> * is set for the map, this function does nothing.</span> +00585 <span class="comment"> * @param map</span> +00586 <span class="comment"> * @param val new string</span> +00587 <span class="comment"> * @sa _stp_map_set()</span> +00588 <span class="comment"> */</span> +00589 +<a name="l00590"></a><a class="code" href="group__maps.html#ga19">00590</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga19">_stp_map_set_str</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, <span class="keywordtype">char</span> *val) +00591 { +00592 <span class="keyword">struct </span>map_node_str *m; +00593 +00594 <span class="keywordflow">if</span> (map == NULL) +00595 <span class="keywordflow">return</span>; +00596 +00597 <span class="keywordflow">if</span> (map->create) { +00598 <span class="keywordflow">if</span> (val == NULL) +00599 <span class="keywordflow">return</span>; +00600 +00601 <span class="keywordflow">if</span> (map->maxnum) { +00602 <span class="keywordflow">if</span> (list_empty(&map->pool)) { +00603 <span class="keywordflow">if</span> (map->no_wrap) { +00604 <span class="comment">/* ERROR. FIXME */</span> +00605 <span class="keywordflow">return</span>; +00606 } +00607 m = (<span class="keyword">struct </span>map_node_str *)map->head.next; +00608 hlist_del_init(&m->n.hnode); +00609 map_free_strings(map, (<span class="keyword">struct</span> map_node *)m); +00610 dbug (<span class="stringliteral">"got %lx off head\n"</span>, (<span class="keywordtype">long</span>)m); +00611 } <span class="keywordflow">else</span> { +00612 m = (<span class="keyword">struct </span>map_node_str *)map->pool.next; +00613 dbug (<span class="stringliteral">"got %lx off pool\n"</span>, (<span class="keywordtype">long</span>)m); +00614 } +00615 list_move_tail(&m->n.lnode, &map->head); +00616 } <span class="keywordflow">else</span> { +00617 m = (<span class="keyword">struct </span>map_node_str *) +00618 <a class="code" href="group__alloc.html#ga2">_stp_calloc</a>(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> map_node_str)); +00619 <span class="comment">/* add node to list */</span> +00620 list_add_tail(&m->n.lnode, &map->head); +00621 } +00622 +00623 <span class="comment">/* copy the key(s) */</span> +00624 map_copy_keys(map, &m->n); +00625 +00626 <span class="comment">/* set the value */</span> +00627 m->str = <a class="code" href="group__alloc.html#ga1">_stp_alloc</a>(strlen(val) + 1); +00628 strcpy(m->str, val); +00629 } <span class="keywordflow">else</span> { +00630 <span class="keywordflow">if</span> (map->key == NULL) +00631 <span class="keywordflow">return</span>; +00632 +00633 <span class="keywordflow">if</span> (val) { +00634 m = (<span class="keyword">struct </span>map_node_str *)map->key; +00635 <span class="keywordflow">if</span> (m->str) +00636 <a class="code" href="group__alloc.html#ga4">_stp_free</a>(m->str); +00637 m->str = <a class="code" href="group__alloc.html#ga1">_stp_alloc</a>(strlen(val) + 1); +00638 strcpy(m->str, val); +00639 } <span class="keywordflow">else</span> { +00640 <span class="comment">/* setting value to 0 is the same as deleting */</span> +00641 <a class="code" href="group__maps.html#ga4">_stp_map_key_del</a>(map); +00642 } +00643 } +00644 } +00645 <span class="comment"></span> +00646 <span class="comment">/** Set the current element's value to String.</span> +00647 <span class="comment"> * This sets the current element's value to a String. The map must have been created</span> +00648 <span class="comment"> * to hold int64s using <i>_stp_map_new(xxx, STRING)</i></span> +00649 <span class="comment"> *</span> +00650 <span class="comment"> * If the element doesn't exist, it is created. If no current element (key)</span> +00651 <span class="comment"> * is set for the map, this function does nothing.</span> +00652 <span class="comment"> * @param map</span> +00653 <span class="comment"> * @param str String containing new value.</span> +00654 <span class="comment"> * @sa _stp_map_set()</span> +00655 <span class="comment"> */</span> +00656 +<a name="l00657"></a><a class="code" href="group__maps.html#ga20">00657</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga20">_stp_map_set_string</a> (<a class="code" href="group__maps.html#ga1">MAP</a> map, String str) +00658 { +00659 <a class="code" href="group__maps.html#ga19">_stp_map_set_str</a> (map, str->buf); +00660 } +00661 <span class="comment"></span> +00662 <span class="comment">/** Gets the current element's value.</span> +00663 <span class="comment"> * @param map</span> +00664 <span class="comment"> * @returns A string pointer. If the current element is not set or doesn't exist, returns NULL.</span> +00665 <span class="comment"> */</span> +00666 +<a name="l00667"></a><a class="code" href="group__maps.html#ga21">00667</a> <span class="keywordtype">char</span> *<a class="code" href="group__maps.html#ga21">_stp_map_get_str</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map) +00668 { +00669 <span class="keyword">struct </span>map_node_str *m; +00670 <span class="keywordflow">if</span> (map == NULL || map->create || map->key == NULL) +00671 <span class="keywordflow">return</span> NULL; +00672 dbug (<span class="stringliteral">"%lx\n"</span>, (<span class="keywordtype">long</span>)map->key); +00673 m = (<span class="keyword">struct </span>map_node_str *)map->key; +00674 <span class="keywordflow">return</span> m->str; +00675 } +00676 <span class="comment"></span> +00677 <span class="comment">/** Set the current element's value to a stat.</span> +00678 <span class="comment"> * This sets the current element's value to an stat struct. The map must have been created</span> +00679 <span class="comment"> * to hold stats using <i>_stp_map_new(xxx, STAT)</i>. This function would only be used</span> +00680 <span class="comment"> * if we wanted to set stats to something other than the normal initial values (count = 0,</span> +00681 <span class="comment"> * sum = 0, etc). It may be deleted if it doesn't turn out to be useful.</span> +00682 <span class="comment"> * @sa _stp_map_stat_add </span> +00683 <span class="comment"> *</span> +00684 <span class="comment"> * If the element doesn't exist, it is created. If no current element (key)</span> +00685 <span class="comment"> * is set for the map, this function does nothing.</span> +00686 <span class="comment"> * @param map</span> +00687 <span class="comment"> * @param stats pointer to stats struct.</span> +00688 <span class="comment"> * @todo Histograms don't work yet.</span> +00689 <span class="comment"> */</span> +00690 +<a name="l00691"></a><a class="code" href="group__maps.html#ga22">00691</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga22">_stp_map_set_stat</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, stat * stats) +00692 { +00693 <span class="keyword">struct </span>map_node_stat *m; +00694 +00695 <span class="keywordflow">if</span> (map == NULL) +00696 <span class="keywordflow">return</span>; +00697 dbug (<span class="stringliteral">"set_stat %lx\n"</span>, (<span class="keywordtype">long</span>)map->key); +00698 +00699 <span class="keywordflow">if</span> (map->create) { +00700 <span class="keywordflow">if</span> (stats == NULL) +00701 <span class="keywordflow">return</span>; +00702 +00703 <span class="keywordflow">if</span> (map->maxnum) { +00704 <span class="keywordflow">if</span> (list_empty(&map->pool)) { +00705 <span class="keywordflow">if</span> (map->no_wrap) { +00706 <span class="comment">/* ERROR. FIXME */</span> +00707 <span class="keywordflow">return</span>; +00708 } +00709 m = (<span class="keyword">struct </span>map_node_stat *)map->head.next; +00710 hlist_del_init(&m->n.hnode); +00711 map_free_strings(map, (<span class="keyword">struct</span> map_node *)m); +00712 dbug (<span class="stringliteral">"got %lx off head\n"</span>, (<span class="keywordtype">long</span>)m); +00713 } <span class="keywordflow">else</span> { +00714 m = (<span class="keyword">struct </span>map_node_stat *)map->pool.next; +00715 dbug (<span class="stringliteral">"got %lx off pool\n"</span>, (<span class="keywordtype">long</span>)m); +00716 } +00717 list_move_tail(&m->n.lnode, &map->head); +00718 } <span class="keywordflow">else</span> { +00719 m = (<span class="keyword">struct </span>map_node_stat *) +00720 <a class="code" href="group__alloc.html#ga2">_stp_calloc</a>(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> map_node_stat)); +00721 <span class="comment">/* add node to list */</span> +00722 list_add_tail(&m->n.lnode, &map->head); +00723 } +00724 +00725 <span class="comment">/* copy the key(s) */</span> +00726 map_copy_keys(map, &m->n); +00727 +00728 <span class="comment">/* set the value */</span> +00729 memcpy(&m->stats, stats, <span class="keyword">sizeof</span>(stat)); +00730 } <span class="keywordflow">else</span> { +00731 <span class="keywordflow">if</span> (map->key == NULL) +00732 <span class="keywordflow">return</span>; +00733 +00734 <span class="keywordflow">if</span> (stats) { +00735 m = (<span class="keyword">struct </span>map_node_stat *)map->key; +00736 memcpy(&m->stats, stats, <span class="keyword">sizeof</span>(stat)); +00737 } <span class="keywordflow">else</span> { +00738 <span class="comment">/* setting value to NULL is the same as deleting */</span> +00739 <a class="code" href="group__maps.html#ga4">_stp_map_key_del</a>(map); +00740 } +00741 } +00742 } +00743 <span class="comment"></span> +00744 <span class="comment">/** Gets the current element's value.</span> +00745 <span class="comment"> * @param map</span> +00746 <span class="comment"> * @returns A pointer to the stats struct. If the current element is not set </span> +00747 <span class="comment"> * or doesn't exist, returns NULL.</span> +00748 <span class="comment"> */</span> +00749 +<a name="l00750"></a><a class="code" href="group__maps.html#ga23">00750</a> stat *<a class="code" href="group__maps.html#ga23">_stp_map_get_stat</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map) +00751 { +00752 <span class="keyword">struct </span>map_node_stat *m; +00753 <span class="keywordflow">if</span> (map == NULL || map->create || map->key == NULL) +00754 <span class="keywordflow">return</span> NULL; +00755 dbug (<span class="stringliteral">"%lx\n"</span>, (<span class="keywordtype">long</span>)map->key); +00756 m = (<span class="keyword">struct </span>map_node_stat *)map->key; +00757 <span class="keywordflow">return</span> &m->stats; +00758 } +00759 <span class="comment"></span> +00760 <span class="comment">/** Add to the current element's statistics.</span> +00761 <span class="comment"> * Increments the statistics counter by one and the sum by <i>val</i>.</span> +00762 <span class="comment"> * Adjusts minimum, maximum, and histogram.</span> +00763 <span class="comment"> *</span> +00764 <span class="comment"> * If the element doesn't exist, it is created. If no current element (key)</span> +00765 <span class="comment"> * is set for the map, this function does nothing.</span> +00766 <span class="comment"> * @param map</span> +00767 <span class="comment"> * @param val value to add to the statistics</span> +00768 <span class="comment"> * @todo Histograms don't work yet.</span> +00769 <span class="comment"> */</span> +00770 +<a name="l00771"></a><a class="code" href="group__maps.html#ga24">00771</a> <span class="keywordtype">void</span> <a class="code" href="group__maps.html#ga24">_stp_map_stat_add</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, int64_t val) +00772 { +00773 <span class="keyword">struct </span>map_node_stat *m; +00774 <span class="keywordflow">if</span> (map == NULL) +00775 <span class="keywordflow">return</span>; +00776 +00777 <span class="keywordflow">if</span> (map->create) { +00778 stat st = { 1, val, val, val }; +00779 <span class="comment">/* histogram */</span> +00780 <a class="code" href="group__maps.html#ga22">_stp_map_set_stat</a>(map, &st); +00781 <span class="keywordflow">return</span>; +00782 } +00783 +00784 <span class="keywordflow">if</span> (map->key == NULL) +00785 <span class="keywordflow">return</span>; +00786 +00787 dbug (<span class="stringliteral">"add_stat %lx\n"</span>, (<span class="keywordtype">long</span>)map->key); +00788 m = (<span class="keyword">struct </span>map_node_stat *)map->key; +00789 m->stats.count++; +00790 m->stats.sum += val; +00791 <span class="keywordflow">if</span> (val > m->stats.max) +00792 m->stats.max = val; +00793 <span class="keywordflow">if</span> (val < m->stats.min) +00794 m->stats.min = val; +00795 <span class="comment">/* histogram */</span> +00796 } +00797 <span class="comment"></span> +00798 <span class="comment">/** @} */</span> +00799 +00800 <span class="comment">/********************** List Functions *********************/</span> +00801 <span class="comment"></span> +00802 <span class="comment">/** @addtogroup lists</span> +00803 <span class="comment"> * Lists are special cases of maps.</span> +00804 <span class="comment"> * @b Example:</span> +00805 <span class="comment"> * @include list.c</span> +00806 <span class="comment"> * @{ */</span> 00807 <span class="comment"></span> -00808 <span class="comment">/** Clears a list.</span> -00809 <span class="comment"> * All elements in the list are deleted.</span> -00810 <span class="comment"> * @param map </span> -00811 <span class="comment"> */</span> -00812 -<a name="l00813"></a><a class="code" href="group__lists.html#ga1">00813</a> <span class="keywordtype">void</span> <a class="code" href="group__lists.html#ga1">_stp_list_clear</a>(<a class="code" href="structmap__root.html">MAP</a> map) -00814 { -00815 <span class="keywordflow">if</span> (map == NULL) -00816 <span class="keywordflow">return</span>; -00817 -00818 <span class="keywordflow">if</span> (!list_empty(&map-><a class="code" href="structmap__root.html#o4">head</a>)) { -00819 <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *ptr = (<span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *)map-><a class="code" href="structmap__root.html#o4">head</a>.next; -00820 -00821 <span class="keywordflow">while</span> (ptr && ptr != (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)&map-><a class="code" href="structmap__root.html#o4">head</a>) { -00822 <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *next = (<span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *)ptr-><a class="code" href="structmap__node.html#o0">lnode</a>.next; -00823 -00824 <span class="comment">/* remove node from old hash list */</span> -00825 hlist_del_init(&ptr-><a class="code" href="structmap__node.html#o1">hnode</a>); -00826 -00827 <span class="comment">/* remove from entry list */</span> -00828 list_del(&ptr-><a class="code" href="structmap__node.html#o0">lnode</a>); -00829 -00830 <span class="comment">/* remove any allocated string storage */</span> -00831 map_free_strings(map, ptr); -00832 -00833 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o1">maxnum</a>) -00834 list_add(&ptr-><a class="code" href="structmap__node.html#o0">lnode</a>, &map-><a class="code" href="structmap__root.html#o5">pool</a>); -00835 <span class="keywordflow">else</span> -00836 <a class="code" href="group__alloc.html#ga4">_stp_free</a>(ptr); -00837 -00838 map-><a class="code" href="structmap__root.html#o2">num</a>--; -00839 ptr = next; -00840 } -00841 } -00842 -00843 <span class="keywordflow">if</span> (map-><a class="code" href="structmap__root.html#o2">num</a> != 0) { -00844 <a class="code" href="group__io.html#ga0">dlog</a> (<span class="stringliteral">"ERROR: list is supposed to be empty (has %d)\n"</span>, map-><a class="code" href="structmap__root.html#o2">num</a>); -00845 } -00846 } -00847 <span class="comment"></span> -00848 <span class="comment">/** Adds a string to a list.</span> -00849 <span class="comment"> * @param map</span> -00850 <span class="comment"> * @param str</span> -00851 <span class="comment"> */</span> -00852 -<a name="l00853"></a><a class="code" href="group__lists.html#ga2">00853</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group__lists.html#ga2">_stp_list_add_str</a>(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keywordtype">char</span> *str) -00854 { -00855 <a class="code" href="group__maps.html#ga13">_stp_map_key_long</a>(map, map-><a class="code" href="structmap__root.html#o2">num</a>); -00856 <a class="code" href="group__maps.html#ga19">_stp_map_set_str</a>(map, str); -00857 } -00858 <span class="comment"></span> -00859 <span class="comment">/** Adds an int64 to a list.</span> -00860 <span class="comment"> * @param map</span> -00861 <span class="comment"> * @param val</span> -00862 <span class="comment"> */</span> -00863 -<a name="l00864"></a><a class="code" href="group__lists.html#ga3">00864</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group__lists.html#ga3">_stp_list_add_int64</a>(<a class="code" href="structmap__root.html">MAP</a> map, int64_t val) -00865 { -00866 <a class="code" href="group__maps.html#ga13">_stp_map_key_long</a>(map, map-><a class="code" href="structmap__root.html#o2">num</a>); -00867 <a class="code" href="group__maps.html#ga16">_stp_map_set_int64</a>(map, val); -00868 } -00869 <span class="comment"></span> -00870 <span class="comment">/** Get the number of elements in a list.</span> -00871 <span class="comment"> * @param map</span> -00872 <span class="comment"> * @returns The number of elements in a list.</span> -00873 <span class="comment"> */</span> -00874 -<a name="l00875"></a><a class="code" href="group__lists.html#ga4">00875</a> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="group__lists.html#ga4">_stp_list_size</a>(<a class="code" href="structmap__root.html">MAP</a> map) -00876 { -00877 <span class="keywordflow">return</span> map-><a class="code" href="structmap__root.html#o2">num</a>; -00878 }<span class="comment"></span> -00879 <span class="comment">/** @} */</span> -00880 <span class="preprocessor">#endif </span><span class="comment">/* _MAP_C_ */</span> +00808 <span class="comment">/** Create a new list.</span> +00809 <span class="comment"> * A list is a map that internally has an incrementing long key for each member.</span> +00810 <span class="comment"> * Lists do not wrap if elements are added to exceed their maximum size.</span> +00811 <span class="comment"> * @param max_entries The maximum number of entries allowed. Currently that number will</span> +00812 <span class="comment"> * be preallocated. If max_entries is 0, there will be no maximum and entries</span> +00813 <span class="comment"> * will be allocated dynamically.</span> +00814 <span class="comment"> * @param type Type of values stored in this list. </span> +00815 <span class="comment"> * @return A MAP on success or NULL on failure.</span> +00816 <span class="comment"> * @sa foreach</span> +00817 <span class="comment"> */</span> +00818 +<a name="l00819"></a><a class="code" href="group__lists.html#ga0">00819</a> <a class="code" href="group__maps.html#ga1">MAP</a> <a class="code" href="group__lists.html#ga0">_stp_list_new</a>(<span class="keywordtype">unsigned</span> max_entries, <span class="keyword">enum</span> valtype type) +00820 { +00821 <a class="code" href="group__maps.html#ga1">MAP</a> map = <a class="code" href="group__maps.html#ga2">_stp_map_new</a> (max_entries, type); +00822 map->no_wrap = 1; +00823 <span class="keywordflow">return</span> map; +00824 } +00825 <span class="comment"></span> +00826 <span class="comment">/** Clears a list.</span> +00827 <span class="comment"> * All elements in the list are deleted.</span> +00828 <span class="comment"> * @param map </span> +00829 <span class="comment"> */</span> +00830 +<a name="l00831"></a><a class="code" href="group__lists.html#ga1">00831</a> <span class="keywordtype">void</span> <a class="code" href="group__lists.html#ga1">_stp_list_clear</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map) +00832 { +00833 <span class="keywordflow">if</span> (map == NULL) +00834 <span class="keywordflow">return</span>; +00835 +00836 <span class="keywordflow">if</span> (!list_empty(&map->head)) { +00837 <span class="keyword">struct </span>map_node *ptr = (<span class="keyword">struct </span>map_node *)map->head.next; +00838 +00839 <span class="keywordflow">while</span> (ptr && ptr != (<span class="keyword">struct</span> map_node *)&map->head) { +00840 <span class="keyword">struct </span>map_node *next = (<span class="keyword">struct </span>map_node *)ptr->lnode.next; +00841 +00842 <span class="comment">/* remove node from old hash list */</span> +00843 hlist_del_init(&ptr->hnode); +00844 +00845 <span class="comment">/* remove from entry list */</span> +00846 list_del(&ptr->lnode); +00847 +00848 <span class="comment">/* remove any allocated string storage */</span> +00849 map_free_strings(map, ptr); +00850 +00851 <span class="keywordflow">if</span> (map->maxnum) +00852 list_add(&ptr->lnode, &map->pool); +00853 <span class="keywordflow">else</span> +00854 <a class="code" href="group__alloc.html#ga4">_stp_free</a>(ptr); +00855 +00856 map->num--; +00857 ptr = next; +00858 } +00859 } +00860 +00861 <span class="keywordflow">if</span> (map->num != 0) { +00862 <a class="code" href="group__io.html#ga2">_stp_log</a> (<span class="stringliteral">"ERROR: list is supposed to be empty (has %d)\n"</span>, map->num); +00863 } +00864 } +00865 <span class="comment"></span> +00866 <span class="comment">/** Adds a C string to a list.</span> +00867 <span class="comment"> * @param map</span> +00868 <span class="comment"> * @param str</span> +00869 <span class="comment"> * @sa _stp_list_add()</span> +00870 <span class="comment"> */</span> +00871 +<a name="l00872"></a><a class="code" href="group__lists.html#ga2">00872</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group__lists.html#ga2">_stp_list_add_str</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, <span class="keywordtype">char</span> *str) +00873 { +00874 <a class="code" href="group__maps.html#ga13">_stp_map_key_long</a>(map, map->num); +00875 <a class="code" href="group__maps.html#ga19">_stp_map_set_str</a>(map, str); +00876 } +00877 <span class="comment"></span> +00878 <span class="comment">/** Adds a String to a list.</span> +00879 <span class="comment"> * @param map</span> +00880 <span class="comment"> * @param str String to add.</span> +00881 <span class="comment"> * @sa _stp_list_add()</span> +00882 <span class="comment"> */</span> +00883 +<a name="l00884"></a><a class="code" href="group__lists.html#ga3">00884</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group__lists.html#ga3">_stp_list_add_string</a> (<a class="code" href="group__maps.html#ga1">MAP</a> map, String str) +00885 { +00886 <a class="code" href="group__maps.html#ga13">_stp_map_key_long</a>(map, map->num); +00887 <a class="code" href="group__maps.html#ga19">_stp_map_set_str</a>(map, str->buf); +00888 } +00889 <span class="comment"></span> +00890 <span class="comment">/** Adds an int64 to a list.</span> +00891 <span class="comment"> * @param map</span> +00892 <span class="comment"> * @param val</span> +00893 <span class="comment"> * @sa _stp_list_add()</span> +00894 <span class="comment"> */</span> +00895 +<a name="l00896"></a><a class="code" href="group__lists.html#ga4">00896</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group__lists.html#ga4">_stp_list_add_int64</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map, int64_t val) +00897 { +00898 <a class="code" href="group__maps.html#ga13">_stp_map_key_long</a>(map, map->num); +00899 <a class="code" href="group__maps.html#ga16">_stp_map_set_int64</a>(map, val); +00900 } +00901 <span class="comment"></span> +00902 <span class="comment">/** Get the number of elements in a list.</span> +00903 <span class="comment"> * @param map</span> +00904 <span class="comment"> * @returns The number of elements in a list.</span> +00905 <span class="comment"> */</span> +00906 +<a name="l00907"></a><a class="code" href="group__lists.html#ga5">00907</a> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="group__lists.html#ga5">_stp_list_size</a>(<a class="code" href="group__maps.html#ga1">MAP</a> map) +00908 { +00909 <span class="keywordflow">return</span> map->num; +00910 }<span class="comment"></span> +00911 <span class="comment">/** @} */</span> +00912 <span class="preprocessor">#endif </span><span class="comment">/* _MAP_C_ */</span> </pre></div></body></html> |