summaryrefslogtreecommitdiffstats
path: root/runtime/docs/html/map_8c-source.html
blob: 03aa6f476b97f66bb83bf4df4442e72b0ddcfd54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>SystemTap: SystemTap Runtime Library</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<div class="qindex"><a class="qindex" href="index.html">Intro</a> | <a class="qindex" href="globals_func.html">Functions</a> | <a class="qindex" href="globals_defs.html">Defines</a> | <a class="qindex" href="globals_enum.html">Enumerations</a> | <a class="qindex" href="globals_eval.html">Enumeration Values</a></div>

<!-- Generated by Doxygen 1.4.1 -->
<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="comment">/* -*- linux-c -*- */</span>
00002 
00003 <span class="keyword">static</span> <span class="keywordtype">int</span> map_sizes[] = {
00004         <span class="keyword">sizeof</span>(<span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a>),
00005         sizeof(struct map_node_stat),
00006         sizeof(struct map_node_str),
00007         0
00008 };
00009 
00010 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> string_hash(<span class="keyword">const</span> <span class="keywordtype">char</span> *key1, <span class="keyword">const</span> <span class="keywordtype">char</span> *key2)
00011 {
00012         <span class="keywordtype">int</span> hash = 0, count = 0;
00013         <span class="keywordtype">char</span> *v1 = (<span class="keywordtype">char</span> *)key1;
00014         <span class="keywordtype">char</span> *v2 = (<span class="keywordtype">char</span> *)key2;
00015         <span class="keywordflow">while</span> (*v1 &amp;&amp; count++ &lt; 5) {
00016                 hash += *v1++;
00017         }
00018         <span class="keywordflow">while</span> (v2 &amp;&amp; *v2 &amp;&amp; count++ &lt; 5) {
00019                 hash += *v2++;
00020         }
00021         <span class="keywordflow">return</span> hash_long((<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)hash, HASH_TABLE_BITS);
00022 }
00023 
00024 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> mixed_hash(<span class="keyword">const</span> <span class="keywordtype">char</span> *key1, <span class="keywordtype">long</span> key2)
00025 {
00026         <span class="keywordtype">int</span> hash = 0, count = 0;
00027         <span class="keywordtype">char</span> *v = (<span class="keywordtype">char</span> *)key1;
00028         <span class="keywordflow">while</span> (v &amp;&amp; *v &amp;&amp; count++ &lt; 5)
00029                 hash += *v++;
00030         return hash_long((<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)(hash ^ key2), HASH_TABLE_BITS);
00031 }
00032 
<a name="l00043"></a><a class="code" href="map_8c.html#a3">00043</a> <a class="code" href="structmap__root.html">MAP</a> _stp_map_new(<span class="keywordtype">unsigned</span> max_entries, enum valtype type)
00044 {
00045         size_t size;
00046         <a class="code" href="structmap__root.html">MAP</a> m = (<a class="code" href="structmap__root.html">MAP</a>) <a class="code" href="alloc_8h.html#a5">_stp_valloc</a>(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> <a class="code" href="structmap__root.html">map_root</a>));
00047         <span class="keywordflow">if</span> (m == NULL)
00048                 <span class="keywordflow">return</span> NULL;
00049 
00050         INIT_LIST_HEAD(&amp;m-&gt;<a class="code" href="structmap__root.html#o4">head</a>);
00051 
00052         m-&gt;<a class="code" href="structmap__root.html#o1">maxnum</a> = max_entries;
00053         m-&gt;<a class="code" href="structmap__root.html#o0">type</a> = type;
00054         <span class="keywordflow">if</span> (type &gt;= <a class="code" href="map_8h.html#a19a17">END</a>) {
00055                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"map_new: unknown type %d\n"</span>, type);
00056                 <span class="keywordflow">return</span> NULL;
00057         }
00058 
00059         <span class="keywordflow">if</span> (max_entries) {
00060                 <span class="keywordtype">void</span> *tmp;
00061                 <span class="keywordtype">int</span> i;
00062                 <span class="keyword">struct </span>list_head *e;
00063 
00064                 INIT_LIST_HEAD(&amp;m-&gt;<a class="code" href="structmap__root.html#o5">pool</a>);
00065                 size = map_sizes[type];
00066                 tmp = <a class="code" href="alloc_8h.html#a5">_stp_valloc</a>(max_entries * size);
00067 
00068                 <span class="keywordflow">for</span> (i = max_entries - 1; i &gt;= 0; i--) {
00069                         e = i * size + tmp;
00070                         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"e=%lx\n"</span>, (<span class="keywordtype">long</span>)e);
00071                         list_add(e, &amp;m-&gt;<a class="code" href="structmap__root.html#o5">pool</a>);
00072                 }
00073                 m-&gt;<a class="code" href="structmap__root.html#o14">membuf</a> = tmp;
00074         }
00075         <span class="keywordflow">return</span> m;
00076 }
00077 
00078 <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)
00079 {
00080         <span class="keyword">struct </span>map_node_str *m = (<span class="keyword">struct </span>map_node_str *)n;
00081         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"n = %lx\n"</span>, (<span class="keywordtype">long</span>)n);
00082         <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o0">type</a> == STRING) {
00083                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"val STRING %lx\n"</span>, (<span class="keywordtype">long</span>)m-&gt;<a class="code" href="structmap__node__str.html#o1">str</a>);
00084                 <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structmap__node__str.html#o1">str</a>)
00085                         _stp_free(m-&gt;str);
00086         }
00087         if (m-&gt;n.key1type == STR) {
00088                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"key1 STR %lx\n"</span>, (<span class="keywordtype">long</span>)<a class="code" href="map_8h.html#a0">key1str</a>(m));
00089                 <span class="keywordflow">if</span> (<a class="code" href="map_8h.html#a0">key1str</a>(m))
00090                         _stp_free(key1str(m));
00091         }
00092         if (m-&gt;n.key2type == STR) {
00093                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"key2 STR %lx\n"</span>, (<span class="keywordtype">long</span>)<a class="code" href="map_8h.html#a1">key2str</a>(m));
00094                 <span class="keywordflow">if</span> (<a class="code" href="map_8h.html#a1">key2str</a>(m))
00095                         _stp_free(key2str(m));
00096         }
00097 }
00098 
<a name="l00104"></a><a class="code" href="map_8c.html#a5">00104</a> <span class="keywordtype">void</span> _stp_map_key_del(<a class="code" href="structmap__root.html">MAP</a> map)
00105 {
00106         <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *m;
00107 
00108         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"create=%d key=%lx\n"</span>, map-&gt;create, (<span class="keywordtype">long</span>)map-&gt;key);
00109         <span class="keywordflow">if</span> (map == NULL)
00110                 <span class="keywordflow">return</span>;
00111 
00112         <span class="keywordflow">if</span> (map-&gt;create) {
00113                 map-&gt;create = 0;
00114                 map-&gt;key = NULL;
00115                 <span class="keywordflow">return</span>;
00116         }
00117 
00118         <span class="keywordflow">if</span> (map-&gt;key == NULL)
00119                 <span class="keywordflow">return</span>;
00120 
00121         m = (<span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *)map-&gt;key;
00122 
00123         <span class="comment">/* remove node from old hash list */</span>
00124         hlist_del_init(&amp;m-&gt;<a class="code" href="structmap__node.html#o1">hnode</a>);
00125 
00126         <span class="comment">/* remove from entry list */</span>
00127         list_del(&amp;m-&gt;<a class="code" href="structmap__node.html#o0">lnode</a>);
00128 
00129         <span class="comment">/* remove any allocated string storage */</span>
00130         map_free_strings(map, (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)map-&gt;key);
00131 
00132         <span class="keywordflow">if</span> (map-&gt;maxnum)
00133                 list_add(&amp;m-&gt;<a class="code" href="structmap__node.html#o0">lnode</a>, &amp;map-&gt;pool);
00134         <span class="keywordflow">else</span>
00135                 <a class="code" href="alloc_8h.html#a6">_stp_free</a>(m);
00136 
00137         map-&gt;key = NULL;
00138         map-&gt;num--;
00139 }
00140 
<a name="l00149"></a><a class="code" href="map_8c.html#a6">00149</a> <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *<a class="code" href="map_8c.html#a6">_stp_map_start</a>(<a class="code" href="structmap__root.html">MAP</a> map)
00150 {
00151         <span class="keywordflow">if</span> (map == NULL)
00152                 <span class="keywordflow">return</span> NULL;
00153 
00154         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"%lx\n"</span>, (<span class="keywordtype">long</span>)map-&gt;<a class="code" href="structmap__root.html#o4">head</a>.next);
00155 
00156         <span class="keywordflow">if</span> (list_empty(&amp;map-&gt;<a class="code" href="structmap__root.html#o4">head</a>))
00157                 <span class="keywordflow">return</span> NULL;
00158 
00159         <span class="keywordflow">return</span> (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)map-&gt;<a class="code" href="structmap__root.html#o4">head</a>.next;
00160 }
00161 
<a name="l00172"></a><a class="code" href="map_8c.html#a7">00172</a> <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *<a class="code" href="map_8c.html#a7">_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)
00173 {
00174         <span class="keywordflow">if</span> (map == NULL)
00175                 <span class="keywordflow">return</span> NULL;
00176 
00177         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"%lx next=%lx  prev=%lx  map-&gt;head.next=%lx\n"</span>, (<span class="keywordtype">long</span>)m, (<span class="keywordtype">long</span>)m-&gt;lnode.next, (<span class="keywordtype">long</span>)m-&gt;lnode.prev, (<span class="keywordtype">long</span>)map-&gt;<a class="code" href="structmap__root.html#o4">head</a>.next);
00178 
00179         <span class="keywordflow">if</span> (m-&gt;lnode.next == &amp;map-&gt;<a class="code" href="structmap__root.html#o4">head</a>)
00180                 <span class="keywordflow">return</span> NULL;
00181 
00182         <span class="keywordflow">return</span> (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)m-&gt;<a class="code" href="structmap__node.html#o0">lnode</a>.next;
00183 }
00184 
<a name="l00190"></a><a class="code" href="map_8c.html#a8">00190</a> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a8">_stp_map_del</a>(<a class="code" href="structmap__root.html">MAP</a> map)
00191 {
00192         <span class="keywordflow">if</span> (map == NULL)
00193                 <span class="keywordflow">return</span>;
00194 
00195         <span class="keywordflow">if</span> (!list_empty(&amp;map-&gt;<a class="code" href="structmap__root.html#o4">head</a>)) {
00196                 <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-&gt;<a class="code" href="structmap__root.html#o4">head</a>.next;
00197                 <span class="keywordflow">while</span> (ptr &amp;&amp; ptr != (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)&amp;map-&gt;<a class="code" href="structmap__root.html#o4">head</a>) {
00198                         map_free_strings(map, ptr);
00199                         ptr = (<span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *)ptr-&gt;<a class="code" href="structmap__node.html#o0">lnode</a>.next;
00200                 }
00201         }
00202         <a class="code" href="alloc_8h.html#a7">_stp_vfree</a>(map-&gt;<a class="code" href="structmap__root.html#o14">membuf</a>);
00203         <a class="code" href="alloc_8h.html#a7">_stp_vfree</a>(map);
00204 }
00205 
00206 <span class="comment">/**********************  KEY FUNCTIONS *********************/</span>
00207 
00208 
<a name="l00218"></a><a class="code" href="map_8c.html#a9">00218</a> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a9">_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)
00219 {
00220         <span class="keywordtype">unsigned</span> hv;
00221         <span class="keyword">struct </span>hlist_head *head;
00222         <span class="keyword">struct </span>hlist_node *e;
00223 
00224         <span class="keywordflow">if</span> (map == NULL)
00225                 <span class="keywordflow">return</span>;
00226 
00227         hv = hash_long(key1 ^ key2, HASH_TABLE_BITS);
00228         head = &amp;map-&gt;<a class="code" href="structmap__root.html#o13">hashes</a>[hv];
00229 
00230         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"hash for %ld,%ld is %d\n"</span>, key1, key2, hv);
00231 
00232         hlist_for_each(e, head) {
00233                 <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *n =
00234                         (<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));
00235                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"n =%lx  key=%ld,%ld\n"</span>, (<span class="keywordtype">long</span>)n, n-&gt;<a class="code" href="structmap__node.html#o2">key1</a>.<a class="code" href="unionkey__data.html#o0">val</a>, n-&gt;key2.<a class="code" href="unionkey__data.html#o0">val</a>);
00236                 <span class="keywordflow">if</span> (key1 == n-&gt;key1.val &amp;&amp; key2 == n-&gt;key2.val) {
00237                         map-&gt;<a class="code" href="structmap__root.html#o6">key</a> = n;
00238                         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"saving key %lx\n"</span>, (<span class="keywordtype">long</span>)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>);
00239                         map-&gt;<a class="code" href="structmap__root.html#o7">create</a> = 0;
00240                         <span class="keywordflow">return</span>;
00241                 }
00242         }
00243 
00244         map-&gt;<a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o0">val</a> = key1;
00245         map-&gt;<a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o0">val</a> = key2;
00246         map-&gt;<a class="code" href="structmap__root.html#o8">c_key1type</a> = <a class="code" href="map_8h.html#a18a12">LONG</a>;
00247         map-&gt;<a class="code" href="structmap__root.html#o9">c_key2type</a> = <a class="code" href="map_8h.html#a18a12">LONG</a>;
00248         map-&gt;<a class="code" href="structmap__root.html#o10">c_keyhead</a> = head;
00249         map-&gt;<a class="code" href="structmap__root.html#o7">create</a> = 1;
00250 }
00251 
<a name="l00261"></a><a class="code" href="map_8c.html#a10">00261</a> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a10">_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)
00262 {
00263         <span class="keywordtype">unsigned</span> hv;
00264         <span class="keyword">struct </span>hlist_head *head;
00265         <span class="keyword">struct </span>hlist_node *e;
00266 
00267         <span class="keywordflow">if</span> (map == NULL)
00268                 <span class="keywordflow">return</span>;
00269 
00270         <span class="keywordflow">if</span> (key1 == NULL) {
00271                 map-&gt;<a class="code" href="structmap__root.html#o6">key</a> = NULL;
00272                 <span class="keywordflow">return</span>;
00273         }
00274 
00275         hv = string_hash(key1, key2);
00276         head = &amp;map-&gt;<a class="code" href="structmap__root.html#o13">hashes</a>[hv];
00277 
00278         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"hash for %s,%s is %d\n"</span>, key1, key2, hv);
00279 
00280         hlist_for_each(e, head) {
00281                 <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *n =
00282                         (<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));
00283                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"e =%lx  key=%s,%s\n"</span>, (<span class="keywordtype">long</span>)e, n-&gt;<a class="code" href="structmap__node.html#o2">key1</a>.<a class="code" href="unionkey__data.html#o1">str</a>,n-&gt;<a class="code" href="structmap__node.html#o3">key2</a>.<a class="code" href="unionkey__data.html#o1">str</a>);
00284                 <span class="keywordflow">if</span> (strcmp(key1, n-&gt;<a class="code" href="structmap__node.html#o2">key1</a>.<a class="code" href="unionkey__data.html#o1">str</a>) == 0
00285                     &amp;&amp; (key2 == NULL || strcmp(key2, n-&gt;<a class="code" href="structmap__node.html#o3">key2</a>.<a class="code" href="unionkey__data.html#o1">str</a>) == 0)) {
00286                         map-&gt;<a class="code" href="structmap__root.html#o6">key</a> = n;
00287                         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"saving key %lx\n"</span>, (<span class="keywordtype">long</span>)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>);
00288                         map-&gt;<a class="code" href="structmap__root.html#o7">create</a> = 0;
00289                         <span class="keywordflow">return</span>;
00290                 }
00291         }
00292 
00293         map-&gt;<a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o1">str</a> = key1;
00294         map-&gt;<a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o1">str</a> = key2;
00295         map-&gt;<a class="code" href="structmap__root.html#o8">c_key1type</a> = <a class="code" href="map_8h.html#a18a13">STR</a>;
00296         map-&gt;<a class="code" href="structmap__root.html#o9">c_key2type</a> = <a class="code" href="map_8h.html#a18a13">STR</a>;
00297         map-&gt;<a class="code" href="structmap__root.html#o10">c_keyhead</a> = head;
00298         map-&gt;<a class="code" href="structmap__root.html#o7">create</a> = 1;
00299 }
00300 
<a name="l00310"></a><a class="code" href="map_8c.html#a11">00310</a> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a11">_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)
00311 {
00312         <span class="keywordtype">unsigned</span> hv;
00313         <span class="keyword">struct </span>hlist_head *head;
00314         <span class="keyword">struct </span>hlist_node *e;
00315 
00316         <span class="keywordflow">if</span> (map == NULL)
00317                 <span class="keywordflow">return</span>;
00318 
00319         <span class="keywordflow">if</span> (key1 == NULL) {
00320                 map-&gt;<a class="code" href="structmap__root.html#o6">key</a> = NULL;
00321                 <span class="keywordflow">return</span>;
00322         }
00323 
00324         hv = mixed_hash(key1, key2);
00325         head = &amp;map-&gt;<a class="code" href="structmap__root.html#o13">hashes</a>[hv];
00326 
00327         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"hash for %s,%ld is %d\n"</span>, key1, key2, hv);
00328 
00329         hlist_for_each(e, head) {
00330                 <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *n =
00331                         (<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));
00332                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"e =%lx  key=%s,%ld\n"</span>, (<span class="keywordtype">long</span>)e, n-&gt;<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-&gt;<a class="code" href="structmap__node.html#o3">key2</a>.<a class="code" href="unionkey__data.html#o0">val</a>);
00333                 <span class="keywordflow">if</span> (strcmp(key1, n-&gt;<a class="code" href="structmap__node.html#o2">key1</a>.<a class="code" href="unionkey__data.html#o1">str</a>) == 0 &amp;&amp; key2 == n-&gt;<a class="code" href="structmap__node.html#o3">key2</a>.<a class="code" href="unionkey__data.html#o0">val</a>) {
00334                         map-&gt;<a class="code" href="structmap__root.html#o6">key</a> = n;
00335                         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"saving key %lx\n"</span>, (<span class="keywordtype">long</span>)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>);
00336                         map-&gt;<a class="code" href="structmap__root.html#o7">create</a> = 0;
00337                         <span class="keywordflow">return</span>;
00338                 }
00339         }
00340 
00341         map-&gt;<a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o1">str</a> = key1;
00342         map-&gt;<a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o0">val</a> = key2;
00343         map-&gt;<a class="code" href="structmap__root.html#o8">c_key1type</a> = <a class="code" href="map_8h.html#a18a13">STR</a>;
00344         map-&gt;<a class="code" href="structmap__root.html#o9">c_key2type</a> = <a class="code" href="map_8h.html#a18a12">LONG</a>;
00345         map-&gt;<a class="code" href="structmap__root.html#o10">c_keyhead</a> = head;
00346         map-&gt;<a class="code" href="structmap__root.html#o7">create</a> = 1;
00347 }
00348 
<a name="l00358"></a><a class="code" href="map_8c.html#a12">00358</a> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a12">_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)
00359 {
00360         <span class="keywordtype">unsigned</span> hv;
00361         <span class="keyword">struct </span>hlist_head *head;
00362         <span class="keyword">struct </span>hlist_node *e;
00363 
00364         <span class="keywordflow">if</span> (map == NULL)
00365                 <span class="keywordflow">return</span>;
00366 
00367         hv = mixed_hash(key2, key1);
00368         head = &amp;map-&gt;<a class="code" href="structmap__root.html#o13">hashes</a>[hv];
00369         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"hash for %ld,%s is %d\n"</span>, key1, key2, hv);
00370 
00371         hlist_for_each(e, head) {
00372                 <span class="keyword">struct </span><a class="code" href="structmap__node.html">map_node</a> *n =
00373                         (<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));
00374                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"e =%lx  key=%ld,%s\n"</span>, (<span class="keywordtype">long</span>)e, n-&gt;<a class="code" href="structmap__node.html#o2">key1</a>.<a class="code" href="unionkey__data.html#o0">val</a>,n-&gt;<a class="code" href="structmap__node.html#o3">key2</a>.<a class="code" href="unionkey__data.html#o1">str</a>);
00375                 <span class="keywordflow">if</span> (key1 == n-&gt;<a class="code" href="structmap__node.html#o2">key1</a>.<a class="code" href="unionkey__data.html#o0">val</a> &amp;&amp; strcmp(key2, n-&gt;<a class="code" href="structmap__node.html#o3">key2</a>.<a class="code" href="unionkey__data.html#o1">str</a>) == 0) {
00376                         map-&gt;<a class="code" href="structmap__root.html#o6">key</a> = n;
00377                         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"saving key %lx\n"</span>, (<span class="keywordtype">long</span>)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>);
00378                         map-&gt;<a class="code" href="structmap__root.html#o7">create</a> = 0;
00379                         <span class="keywordflow">return</span>;
00380                 }
00381         }
00382 
00383         map-&gt;<a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o0">val</a> = key1;
00384         map-&gt;<a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o1">str</a> = key2;
00385         map-&gt;<a class="code" href="structmap__root.html#o8">c_key1type</a> = <a class="code" href="map_8h.html#a18a12">LONG</a>;
00386         map-&gt;<a class="code" href="structmap__root.html#o9">c_key2type</a> = <a class="code" href="map_8h.html#a18a13">STR</a>;
00387         map-&gt;<a class="code" href="structmap__root.html#o10">c_keyhead</a> = head;
00388         map-&gt;<a class="code" href="structmap__root.html#o7">create</a> = 1;
00389 }
00390 
<a name="l00399"></a><a class="code" href="map_8c.html#a13">00399</a> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a13">_stp_map_key_str</a>(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keywordtype">char</span> *key)
00400 {
00401         <span class="keywordflow">if</span> (map == NULL)
00402                 <span class="keywordflow">return</span>;
00403         <a class="code" href="map_8c.html#a10">_stp_map_key_str_str</a>(map, key, NULL);
00404         map-&gt;<a class="code" href="structmap__root.html#o9">c_key2type</a> = <a class="code" href="map_8h.html#a18a11">NONE</a>;
00405 }
00406 
<a name="l00415"></a><a class="code" href="map_8c.html#a14">00415</a> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a14">_stp_map_key_long</a>(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keywordtype">long</span> key)
00416 {
00417         <span class="keywordflow">if</span> (map == NULL)
00418                 <span class="keywordflow">return</span>;
00419         <a class="code" href="map_8c.html#a9">_stp_map_key_long_long</a>(map, key, 0);
00420         map-&gt;<a class="code" href="structmap__root.html#o9">c_key2type</a> = <a class="code" href="map_8h.html#a18a11">NONE</a>;
00421 }
00422 
00423 <span class="comment">/**********************  SET/GET VALUES *********************/</span>
00424 
00425 <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)
00426 {
00427         m-&gt;key1type = map-&gt;<a class="code" href="structmap__root.html#o8">c_key1type</a>;
00428         m-&gt;key2type = map-&gt;<a class="code" href="structmap__root.html#o9">c_key2type</a>;
00429         <span class="keywordflow">switch</span> (map-&gt;<a class="code" href="structmap__root.html#o8">c_key1type</a>) {
00430         <span class="keywordflow">case</span> <a class="code" href="map_8h.html#a18a13">STR</a>:
00431                 m-&gt;key1.str = <a class="code" href="alloc_8h.html#a3">_stp_alloc</a>(strlen(map-&gt;<a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o1">str</a>) + 1);
00432                 strcpy(m-&gt;key1.str, map-&gt;<a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o1">str</a>);
00433                 <span class="keywordflow">break</span>;
00434         <span class="keywordflow">case</span> <a class="code" href="map_8h.html#a18a12">LONG</a>:
00435                 m-&gt;key1.val = map-&gt;<a class="code" href="structmap__root.html#o11">c_key1</a>.<a class="code" href="unionkey__data.html#o0">val</a>;
00436                 <span class="keywordflow">break</span>;
00437         <span class="keywordflow">case</span> <a class="code" href="map_8h.html#a18a11">NONE</a>:
00438                 <span class="comment">/* ERROR */</span>
00439                 <span class="keywordflow">break</span>;
00440         }
00441         <span class="keywordflow">switch</span> (map-&gt;<a class="code" href="structmap__root.html#o9">c_key2type</a>) {
00442         <span class="keywordflow">case</span> <a class="code" href="map_8h.html#a18a13">STR</a>:
00443                 m-&gt;key2.<a class="code" href="unionkey__data.html#o1">str</a> = <a class="code" href="alloc_8h.html#a3">_stp_alloc</a>(strlen(map-&gt;<a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o1">str</a>) + 1);
00444                 strcpy(m-&gt;key2.str, map-&gt;<a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o1">str</a>);
00445                 <span class="keywordflow">break</span>;
00446         <span class="keywordflow">case</span> <a class="code" href="map_8h.html#a18a12">LONG</a>:
00447                 m-&gt;key2.<a class="code" href="unionkey__data.html#o0">val</a> = map-&gt;<a class="code" href="structmap__root.html#o12">c_key2</a>.<a class="code" href="unionkey__data.html#o0">val</a>;
00448                 <span class="keywordflow">break</span>;
00449         <span class="keywordflow">case</span> <a class="code" href="map_8h.html#a18a11">NONE</a>:
00450                 <span class="keywordflow">break</span>;
00451         }
00452 
00453         <span class="comment">/* add node to new hash list */</span>
00454         hlist_add_head(&amp;m-&gt;hnode, map-&gt;<a class="code" href="structmap__root.html#o10">c_keyhead</a>);
00455         
00456         map-&gt;<a class="code" href="structmap__root.html#o6">key</a> = m;
00457         map-&gt;<a class="code" href="structmap__root.html#o7">create</a> = 0;
00458         map-&gt;<a class="code" href="structmap__root.html#o2">num</a>++;
00459 }
00460 
00461 <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)
00462 {
00463         <span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *m;
00464 
00465         <span class="keywordflow">if</span> (map == NULL)
00466                 return;
00467 
00468         if (map-&gt;create) {
00469                 <span class="keywordflow">if</span> (val == 0)
00470                         return;
00471 
00472                 if (map-&gt;maxnum) {
00473                         <span class="keywordflow">if</span> (list_empty(&amp;map-&gt;<a class="code" href="structmap__root.html#o5">pool</a>)) {
00474                                 <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o3">no_wrap</a>) {
00475                                         <span class="comment">/* ERROR. FIXME */</span>
00476                                         <span class="keywordflow">return</span>;
00477                                 }
00478                                 m = (<span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *)map-&gt;<a class="code" href="structmap__root.html#o4">head</a>.next;
00479                                 hlist_del_init(&amp;m-&gt;<a class="code" href="structmap__node__int64.html#o0">n</a>.<a class="code" href="structmap__node.html#o1">hnode</a>);
00480                                 map_free_strings(map, (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)m);
00481                                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"got %lx off head\n"</span>, (<span class="keywordtype">long</span>)m);
00482                         } <span class="keywordflow">else</span> {
00483                                 m = (<span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *)map-&gt;<a class="code" href="structmap__root.html#o5">pool</a>.next;
00484                                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"got %lx off pool\n"</span>, (<span class="keywordtype">long</span>)m);
00485                         }
00486                         list_move_tail(&amp;m-&gt;<a class="code" href="structmap__node__int64.html#o0">n</a>.<a class="code" href="structmap__node.html#o0">lnode</a>, &amp;map-&gt;<a class="code" href="structmap__root.html#o4">head</a>);
00487                 } <span class="keywordflow">else</span> {
00488                         m = (<span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *)
00489                             <a class="code" href="alloc_8h.html#a4">_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>));
00490                         <span class="comment">/* add node to list */</span>
00491                         list_add_tail(&amp;m-&gt;<a class="code" href="structmap__node__int64.html#o0">n</a>.<a class="code" href="structmap__node.html#o0">lnode</a>, &amp;map-&gt;<a class="code" href="structmap__root.html#o4">head</a>);
00492                 }
00493 
00494                 <span class="comment">/* copy the key(s) */</span>
00495                 map_copy_keys(map, &amp;m-&gt;<a class="code" href="structmap__node__int64.html#o0">n</a>);
00496 
00497                 <span class="comment">/* set the value */</span>
00498                 m-&gt;<a class="code" href="structmap__node__int64.html#o1">val</a> = val;
00499         } <span class="keywordflow">else</span> {
00500                 <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o6">key</a> == NULL)
00501                         return;
00502 
00503                 if (val) {
00504                         m = (<span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>;
00505                         <span class="keywordflow">if</span> (add)
00506                                 m-&gt;val += val;
00507                         else
00508                                 m-&gt;val = val;
00509                 } else if (!add) {
00510                         <span class="comment">/* setting value to 0 is the same as deleting */</span>
00511                         <a class="code" href="map_8c.html#a5">_stp_map_key_del</a>(map);
00512                 }
00513         }
00514 }
00515 
<a name="l00525"></a><a class="code" href="map_8c.html#a17">00525</a> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a17">_stp_map_set_int64</a>(<a class="code" href="structmap__root.html">MAP</a> map, int64_t val)
00526 {
00527         __stp_map_set_int64 (map, val, 0);
00528 }
00529 
00530 
<a name="l00541"></a><a class="code" href="map_8c.html#a18">00541</a> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a18">_stp_map_add_int64</a>(<a class="code" href="structmap__root.html">MAP</a> map, int64_t val)
00542 {
00543         __stp_map_set_int64 (map, val, 1);
00544 }
00545 
<a name="l00551"></a><a class="code" href="map_8c.html#a19">00551</a> int64_t <a class="code" href="map_8c.html#a19">_stp_map_get_int64</a>(<a class="code" href="structmap__root.html">MAP</a> map)
00552 {
00553         <span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *m;
00554         <span class="keywordflow">if</span> (map == NULL || map-&gt;<a class="code" href="structmap__root.html#o7">create</a> || map-&gt;<a class="code" href="structmap__root.html#o6">key</a> == NULL)
00555                 <span class="keywordflow">return</span> 0;
00556         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"%lx\n"</span>, (<span class="keywordtype">long</span>)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>);
00557         m = (<span class="keyword">struct </span><a class="code" href="structmap__node__int64.html">map_node_int64</a> *)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>;
00558         <span class="keywordflow">return</span> m-&gt;<a class="code" href="structmap__node__int64.html#o1">val</a>;
00559 }
00560 
<a name="l00571"></a><a class="code" href="map_8c.html#a20">00571</a> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a20">_stp_map_set_str</a>(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keywordtype">char</span> *val)
00572 {
00573         <span class="keyword">struct </span>map_node_str *m;
00574 
00575         <span class="keywordflow">if</span> (map == NULL)
00576                 <span class="keywordflow">return</span>;
00577 
00578         <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o7">create</a>) {
00579                 <span class="keywordflow">if</span> (val == NULL)
00580                         <span class="keywordflow">return</span>;
00581 
00582                 <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o1">maxnum</a>) {
00583                         <span class="keywordflow">if</span> (list_empty(&amp;map-&gt;<a class="code" href="structmap__root.html#o5">pool</a>)) {
00584                                 <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o3">no_wrap</a>) {
00585                                         <span class="comment">/* ERROR. FIXME */</span>
00586                                         <span class="keywordflow">return</span>;
00587                                 }
00588                                 m = (<span class="keyword">struct </span>map_node_str *)map-&gt;<a class="code" href="structmap__root.html#o4">head</a>.next;
00589                                 hlist_del_init(&amp;m-&gt;<a class="code" href="structmap__node__str.html#o0">n</a>.<a class="code" href="structmap__node.html#o1">hnode</a>);
00590                                 map_free_strings(map, (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)m);
00591                                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"got %lx off head\n"</span>, (<span class="keywordtype">long</span>)m);
00592                         } <span class="keywordflow">else</span> {
00593                                 m = (<span class="keyword">struct </span>map_node_str *)map-&gt;<a class="code" href="structmap__root.html#o5">pool</a>.next;
00594                                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"got %lx off pool\n"</span>, (<span class="keywordtype">long</span>)m);
00595                         }
00596                         list_move_tail(&amp;m-&gt;<a class="code" href="structmap__node__str.html#o0">n</a>.<a class="code" href="structmap__node.html#o0">lnode</a>, &amp;map-&gt;<a class="code" href="structmap__root.html#o4">head</a>);
00597                 } <span class="keywordflow">else</span> {
00598                         m = (<span class="keyword">struct </span>map_node_str *)
00599                             <a class="code" href="alloc_8h.html#a4">_stp_calloc</a>(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> map_node_str));
00600                         <span class="comment">/* add node to list */</span>
00601                         list_add_tail(&amp;m-&gt;<a class="code" href="structmap__node__str.html#o0">n</a>.<a class="code" href="structmap__node.html#o0">lnode</a>, &amp;map-&gt;<a class="code" href="structmap__root.html#o4">head</a>);
00602                 }
00603 
00604                 <span class="comment">/* copy the key(s) */</span>
00605                 map_copy_keys(map, &amp;m-&gt;<a class="code" href="structmap__node__str.html#o0">n</a>);
00606 
00607                 <span class="comment">/* set the value */</span>
00608                 m-&gt;<a class="code" href="structmap__node__str.html#o1">str</a> = <a class="code" href="alloc_8h.html#a3">_stp_alloc</a>(strlen(val) + 1);
00609                 strcpy(m-&gt;<a class="code" href="structmap__node__str.html#o1">str</a>, val);
00610         } <span class="keywordflow">else</span> {
00611                 <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o6">key</a> == NULL)
00612                         <span class="keywordflow">return</span>;
00613 
00614                 <span class="keywordflow">if</span> (val) {
00615                         m = (<span class="keyword">struct </span>map_node_str *)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>;
00616                         <span class="keywordflow">if</span> (m-&gt;<a class="code" href="structmap__node__str.html#o1">str</a>)
00617                                 <a class="code" href="alloc_8h.html#a6">_stp_free</a>(m-&gt;<a class="code" href="structmap__node__str.html#o1">str</a>);
00618                         m-&gt;<a class="code" href="structmap__node__str.html#o1">str</a> = <a class="code" href="alloc_8h.html#a3">_stp_alloc</a>(strlen(val) + 1);
00619                         strcpy(m-&gt;<a class="code" href="structmap__node__str.html#o1">str</a>, val);
00620                 } <span class="keywordflow">else</span> {
00621                         <span class="comment">/* setting value to 0 is the same as deleting */</span>
00622                         <a class="code" href="map_8c.html#a5">_stp_map_key_del</a>(map);
00623                 }
00624         }
00625 }
00626 
<a name="l00632"></a><a class="code" href="map_8c.html#a21">00632</a> <span class="keywordtype">char</span> *<a class="code" href="map_8c.html#a21">_stp_map_get_str</a>(<a class="code" href="structmap__root.html">MAP</a> map)
00633 {
00634         <span class="keyword">struct </span>map_node_str *m;
00635         <span class="keywordflow">if</span> (map == NULL || map-&gt;<a class="code" href="structmap__root.html#o7">create</a> || map-&gt;<a class="code" href="structmap__root.html#o6">key</a> == NULL)
00636                 <span class="keywordflow">return</span> NULL;
00637         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"%lx\n"</span>, (<span class="keywordtype">long</span>)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>);
00638         m = (<span class="keyword">struct </span>map_node_str *)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>;
00639         <span class="keywordflow">return</span> m-&gt;<a class="code" href="structmap__node__str.html#o1">str</a>;
00640 }
00641 
<a name="l00656"></a><a class="code" href="map_8c.html#a22">00656</a> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a22">_stp_map_set_stat</a>(<a class="code" href="structmap__root.html">MAP</a> map, <a class="code" href="structstat.html">stat</a> * stats)
00657 {
00658         <span class="keyword">struct </span>map_node_stat *m;
00659 
00660         <span class="keywordflow">if</span> (map == NULL)
00661                 <span class="keywordflow">return</span>;
00662         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"set_stat %lx\n"</span>, (<span class="keywordtype">long</span>)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>);
00663 
00664         <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o7">create</a>) {
00665                 <span class="keywordflow">if</span> (stats == NULL)
00666                         <span class="keywordflow">return</span>;
00667 
00668                 <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o1">maxnum</a>) {
00669                         <span class="keywordflow">if</span> (list_empty(&amp;map-&gt;<a class="code" href="structmap__root.html#o5">pool</a>)) {
00670                                 <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o3">no_wrap</a>) {
00671                                         <span class="comment">/* ERROR. FIXME */</span>
00672                                         <span class="keywordflow">return</span>;
00673                                 }
00674                                 m = (<span class="keyword">struct </span>map_node_stat *)map-&gt;<a class="code" href="structmap__root.html#o4">head</a>.next;
00675                                 hlist_del_init(&amp;m-&gt;<a class="code" href="structmap__node__stat.html#o0">n</a>.<a class="code" href="structmap__node.html#o1">hnode</a>);
00676                                 map_free_strings(map, (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)m);
00677                                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"got %lx off head\n"</span>, (<span class="keywordtype">long</span>)m);
00678                         } <span class="keywordflow">else</span> {
00679                                 m = (<span class="keyword">struct </span>map_node_stat *)map-&gt;<a class="code" href="structmap__root.html#o5">pool</a>.next;
00680                                 <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"got %lx off pool\n"</span>, (<span class="keywordtype">long</span>)m);
00681                         }
00682                         list_move_tail(&amp;m-&gt;<a class="code" href="structmap__node__stat.html#o0">n</a>.<a class="code" href="structmap__node.html#o0">lnode</a>, &amp;map-&gt;<a class="code" href="structmap__root.html#o4">head</a>);
00683                 } <span class="keywordflow">else</span> {
00684                         m = (<span class="keyword">struct </span>map_node_stat *)
00685                             <a class="code" href="alloc_8h.html#a4">_stp_calloc</a>(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> map_node_stat));
00686                         <span class="comment">/* add node to list */</span>
00687                         list_add_tail(&amp;m-&gt;<a class="code" href="structmap__node__stat.html#o0">n</a>.<a class="code" href="structmap__node.html#o0">lnode</a>, &amp;map-&gt;<a class="code" href="structmap__root.html#o4">head</a>);
00688                 }
00689 
00690                 <span class="comment">/* copy the key(s) */</span>
00691                 map_copy_keys(map, &amp;m-&gt;<a class="code" href="structmap__node__stat.html#o0">n</a>);
00692 
00693                 <span class="comment">/* set the value */</span>
00694                 memcpy(&amp;m-&gt;<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>));
00695         } <span class="keywordflow">else</span> {
00696                 <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o6">key</a> == NULL)
00697                         <span class="keywordflow">return</span>;
00698 
00699                 <span class="keywordflow">if</span> (stats) {
00700                         m = (<span class="keyword">struct </span>map_node_stat *)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>;
00701                         memcpy(&amp;m-&gt;<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>));
00702                 } <span class="keywordflow">else</span> {
00703                         <span class="comment">/* setting value to NULL is the same as deleting */</span>
00704                         <a class="code" href="map_8c.html#a5">_stp_map_key_del</a>(map);
00705                 }
00706         }
00707 }
00708 
<a name="l00715"></a><a class="code" href="map_8c.html#a23">00715</a> <a class="code" href="structstat.html">stat</a> *<a class="code" href="map_8c.html#a23">_stp_map_get_stat</a>(<a class="code" href="structmap__root.html">MAP</a> map)
00716 {
00717         <span class="keyword">struct </span>map_node_stat *m;
00718         <span class="keywordflow">if</span> (map == NULL || map-&gt;<a class="code" href="structmap__root.html#o7">create</a> || map-&gt;<a class="code" href="structmap__root.html#o6">key</a> == NULL)
00719                 <span class="keywordflow">return</span> NULL;
00720         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"%lx\n"</span>, (<span class="keywordtype">long</span>)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>);
00721         m = (<span class="keyword">struct </span>map_node_stat *)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>;
00722         <span class="keywordflow">return</span> &amp;m-&gt;<a class="code" href="structmap__node__stat.html#o1">stats</a>;
00723 }
00724 
<a name="l00736"></a><a class="code" href="map_8c.html#a24">00736</a> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a24">_stp_map_stat_add</a>(<a class="code" href="structmap__root.html">MAP</a> map, int64_t val)
00737 {
00738         <span class="keyword">struct </span>map_node_stat *m;
00739         <span class="keywordflow">if</span> (map == NULL)
00740                 <span class="keywordflow">return</span>;
00741 
00742         <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o7">create</a>) {
00743                 <a class="code" href="structstat.html">stat</a> st = { 1, val, val, val };
00744                 <span class="comment">/* histogram */</span>
00745                 <a class="code" href="map_8c.html#a22">_stp_map_set_stat</a>(map, &amp;st);
00746                 <span class="keywordflow">return</span>;
00747         }
00748 
00749         <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o6">key</a> == NULL)
00750                 <span class="keywordflow">return</span>;
00751 
00752         <a class="code" href="runtime_8h.html#a0">dbug</a> (<span class="stringliteral">"add_stat %lx\n"</span>, (<span class="keywordtype">long</span>)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>);
00753         m = (<span class="keyword">struct </span>map_node_stat *)map-&gt;<a class="code" href="structmap__root.html#o6">key</a>;
00754         m-&gt;<a class="code" href="structmap__node__stat.html#o1">stats</a>.<a class="code" href="structstat.html#o0">count</a>++;
00755         m-&gt;<a class="code" href="structmap__node__stat.html#o1">stats</a>.<a class="code" href="structstat.html#o1">sum</a> += val;
00756         <span class="keywordflow">if</span> (val &gt; m-&gt;<a class="code" href="structmap__node__stat.html#o1">stats</a>.<a class="code" href="structstat.html#o3">max</a>)
00757                 m-&gt;<a class="code" href="structmap__node__stat.html#o1">stats</a>.<a class="code" href="structstat.html#o3">max</a> = val;
00758         <span class="keywordflow">if</span> (val &lt; m-&gt;stats.min)
00759                 m-&gt;<a class="code" href="structmap__node__stat.html#o1">stats</a>.<a class="code" href="structstat.html#o2">min</a> = val;
00760         <span class="comment">/* histogram */</span>
00761 }
00762 
00763 <span class="comment">/**********************  List Functions *********************/</span>
00764 
<a name="l00776"></a><a class="code" href="map_8c.html#a25">00776</a> <a class="code" href="structmap__root.html">MAP</a> <a class="code" href="map_8c.html#a25">_stp_list_new</a>(<span class="keywordtype">unsigned</span> max_entries, <span class="keyword">enum</span> valtype type)
00777 {
00778   <a class="code" href="structmap__root.html">MAP</a> map = <a class="code" href="map_8c.html#a3">_stp_map_new</a> (max_entries, type);
00779   map-&gt;<a class="code" href="structmap__root.html#o3">no_wrap</a> = 1;
00780   <span class="keywordflow">return</span> map;
00781 }
00782 
<a name="l00788"></a><a class="code" href="map_8c.html#a26">00788</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a26">_stp_list_clear</a>(<a class="code" href="structmap__root.html">MAP</a> map)
00789 {
00790         <span class="keywordflow">if</span> (map == NULL)
00791                 <span class="keywordflow">return</span>;
00792 
00793         <span class="keywordflow">if</span> (!list_empty(&amp;map-&gt;<a class="code" href="structmap__root.html#o4">head</a>)) {
00794                 <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-&gt;<a class="code" href="structmap__root.html#o4">head</a>.next;
00795 
00796                 <span class="keywordflow">while</span> (ptr &amp;&amp; ptr != (<span class="keyword">struct</span> <a class="code" href="structmap__node.html">map_node</a> *)&amp;map-&gt;<a class="code" href="structmap__root.html#o4">head</a>) {
00797                         <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-&gt;<a class="code" href="structmap__node.html#o0">lnode</a>.next;
00798 
00799                         <span class="comment">/* remove node from old hash list */</span>
00800                         hlist_del_init(&amp;ptr-&gt;<a class="code" href="structmap__node.html#o1">hnode</a>);
00801 
00802                         <span class="comment">/* remove from entry list */</span>
00803                         list_del(&amp;ptr-&gt;<a class="code" href="structmap__node.html#o0">lnode</a>);
00804                         
00805                         <span class="comment">/* remove any allocated string storage */</span>
00806                         map_free_strings(map, ptr);
00807                         
00808                         <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o1">maxnum</a>)
00809                                 list_add(&amp;ptr-&gt;<a class="code" href="structmap__node.html#o0">lnode</a>, &amp;map-&gt;<a class="code" href="structmap__root.html#o5">pool</a>);
00810                         <span class="keywordflow">else</span>
00811                                 <a class="code" href="alloc_8h.html#a6">_stp_free</a>(ptr);
00812 
00813                         map-&gt;<a class="code" href="structmap__root.html#o2">num</a>--;
00814                         ptr = next;
00815                 }
00816         }
00817 
00818         <span class="keywordflow">if</span> (map-&gt;<a class="code" href="structmap__root.html#o2">num</a> != 0) {
00819                 <a class="code" href="io_8c.html#a4">dlog</a> (<span class="stringliteral">"ERROR: list is supposed to be empty (has %d)\n"</span>, map-&gt;<a class="code" href="structmap__root.html#o2">num</a>);
00820         }
00821 }
00822 
<a name="l00828"></a><a class="code" href="map_8c.html#a27">00828</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a27">_stp_list_add_str</a>(<a class="code" href="structmap__root.html">MAP</a> map, <span class="keywordtype">char</span> *str)
00829 {
00830         <a class="code" href="map_8c.html#a14">_stp_map_key_long</a>(map, map-&gt;<a class="code" href="structmap__root.html#o2">num</a>);
00831         <a class="code" href="map_8c.html#a20">_stp_map_set_str</a>(map, str);
00832 }
00833 
<a name="l00839"></a><a class="code" href="map_8c.html#a28">00839</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="map_8c.html#a28">_stp_list_add_int64</a>(<a class="code" href="structmap__root.html">MAP</a> map, int64_t val)
00840 {
00841         <a class="code" href="map_8c.html#a14">_stp_map_key_long</a>(map, map-&gt;<a class="code" href="structmap__root.html#o2">num</a>);
00842         <a class="code" href="map_8c.html#a17">_stp_map_set_int64</a>(map, val);
00843 }
00844 
<a name="l00850"></a><a class="code" href="map_8c.html#a29">00850</a> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="map_8c.html#a29">_stp_list_size</a>(<a class="code" href="structmap__root.html">MAP</a> map)
00851 {
00852         <span class="keywordflow">return</span> map-&gt;<a class="code" href="structmap__root.html#o2">num</a>;
00853 }
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Mar 21 13:29:45 2005 for SystemTap by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.1 </small></address>
</body>
</html>