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 #ifndef UCX_MAP_H
37 #define UCX_MAP_H
38
39 #include "common.h"
40 #include "collection.h"
41 #include "string.h"
42 #include "hash_key.h"
43
44 #ifndef UCX_LIST_H
45
46 typedef struct cx_list_s CxList;
47 #endif
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53
54 typedef struct cx_map_s CxMap;
55
56
57 typedef struct cx_map_entry_s CxMapEntry;
58
59
60 typedef struct cx_map_iterator_s CxMapIterator;
61
62
63 typedef struct cx_map_class_s cx_map_class;
64
65
66 struct cx_map_s {
67
68
69
70 CX_COLLECTION_BASE;
71
72 cx_map_class *cl;
73 };
74
75
76
77
78 struct cx_map_entry_s {
79
80
81
82 const CxHashKey *key;
83
84
85
86 void *value;
87 };
88
89
90
91
92 enum cx_map_iterator_type {
93
94
95
96 CX_MAP_ITERATOR_PAIRS,
97
98
99
100 CX_MAP_ITERATOR_KEYS,
101
102
103
104 CX_MAP_ITERATOR_VALUES
105 };
106
107
108
109
110 struct cx_map_iterator_s {
111
112
113
114 CX_ITERATOR_BASE;
115
116
117
118
119 CxMap *map;
120
121
122
123
124
125
126 void *elem;
127
128
129
130
131
132
133
134 CxMapEntry entry;
135
136
137
138
139
140
141 size_t slot;
142
143
144
145
146
147 size_t index;
148
149
150
151
152 size_t elem_size;
153
154
155
156
157
158
159
160 size_t elem_count;
161
162
163
164
165 enum cx_map_iterator_type type;
166 };
167
168
169
170
171 struct cx_map_class_s {
172
173
174
175 void (*deallocate)(
struct cx_map_s *map);
176
177
178
179
180 void (*clear)(
struct cx_map_s *map);
181
182
183
184
185
186
187
188 void *(*put)(CxMap *map, CxHashKey key,
void *value);
189
190
191
192
193 void *(*get)(
const CxMap *map, CxHashKey key);
194
195
196
197
198
199
200
201
202
203
204
205 int (*remove)(CxMap *map, CxHashKey key,
void *targetbuf);
206
207
208
209
210 CxMapIterator (*iterator)(
const CxMap *map,
enum cx_map_iterator_type type);
211 };
212
213
214
215
216
217
218
219
220
221 CX_EXPORT extern CxMap *
const cxEmptyMap;
222
223
224
225
226
227
228
229
230 CX_EXPORT void cxMapFree(CxMap *map);
231
232
233
234
235
236
237
238
239
240 cx_attr_nonnull
241 CX_EXPORT void cxMapClear(CxMap *map);
242
243
244
245
246
247
248
249 cx_attr_nonnull
250 CX_EXPORT size_t cxMapSize(
const CxMap *map);
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265 cx_attr_nodiscard
266 CX_EXPORT CxMapIterator cxMapIteratorValues(
const CxMap *map);
267
268
269
270
271
272
273
274
275
276
277
278
279
280 cx_attr_nodiscard
281 CX_EXPORT CxMapIterator cxMapIteratorKeys(
const CxMap *map);
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297 cx_attr_nodiscard
298 CX_EXPORT CxMapIterator cxMapIterator(
const CxMap *map);
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320 cx_attr_nonnull
321 CX_EXPORT int cx_map_put(CxMap *map, CxHashKey key,
void *value);
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343 #define cxMapPut(map, key, value) cx_map_put(map,
CX_HASH_KEY(key), value)
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364 cx_attr_nonnull
365 CX_EXPORT void *cx_map_emplace(CxMap *map, CxHashKey key);
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386 #define cxMapEmplace(map, key) cx_map_emplace(map,
CX_HASH_KEY(key))
387
388
389
390
391
392
393
394
395
396
397
398
399
400 cx_attr_nonnull cx_attr_nodiscard
401 CX_EXPORT void *cx_map_get(
const CxMap *map, CxHashKey key);
402
403
404
405
406
407
408
409
410
411
412
413
414
415 #define cxMapGet(map, key) cx_map_get(map,
CX_HASH_KEY(key))
416
417
418
419
420
421
422
423
424
425
426 #define cxMapContains(map, key) (cxMapGet(map, key) !=
NULL)
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443 cx_attr_nonnull_arg(
1)
444 CX_EXPORT int cx_map_remove(CxMap *map, CxHashKey key,
void *targetbuf);
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459 #define cxMapRemove(map, key) cx_map_remove(map,
CX_HASH_KEY(key),
NULL)
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481 #define cxMapRemoveAndGet(map, key, targetbuf) cx_map_remove(map,
CX_HASH_KEY(key), targetbuf)
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 cx_attr_nonnull_arg(
1,
2,
3)
507 CX_EXPORT int cxMapClone(CxMap *dst,
const CxMap *src,
508 cx_clone_func clone_func,
const CxAllocator *clone_allocator,
void *data);
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523 cx_attr_nonnull_arg(
1,
2,
3,
4)
524 CX_EXPORT int cxMapDifference(CxMap *dst,
const CxMap *minuend,
const CxMap *subtrahend,
525 cx_clone_func clone_func,
const CxAllocator *clone_allocator,
void *data);
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544 cx_attr_nonnull_arg(
1,
2,
3,
4)
545 CX_EXPORT int cxMapListDifference(CxMap *dst,
const CxMap *src,
const CxList *keys,
546 cx_clone_func clone_func,
const CxAllocator *clone_allocator,
void *data);
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561 cx_attr_nonnull_arg(
1,
2,
3,
4)
562 CX_EXPORT int cxMapIntersection(CxMap *dst,
const CxMap *src,
const CxMap *other,
563 cx_clone_func clone_func,
const CxAllocator *clone_allocator,
void *data);
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582 cx_attr_nonnull_arg(
1,
2,
3,
4)
583 CX_EXPORT int cxMapListIntersection(CxMap *dst,
const CxMap *src,
const CxList *keys,
584 cx_clone_func clone_func,
const CxAllocator *clone_allocator,
void *data);
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602 cx_attr_nonnull_arg(
1,
2,
3)
603 CX_EXPORT int cxMapUnion(CxMap *dst,
const CxMap *src,
604 cx_clone_func clone_func,
const CxAllocator *clone_allocator,
void *data);
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 cx_attr_nonnull
630 CX_EXPORT int cxMapCloneSimple(CxMap *dst,
const CxMap *src);
631
632
633
634
635
636
637
638
639
640
641
642
643
644 cx_attr_nonnull
645 CX_EXPORT int cxMapDifferenceSimple(CxMap *dst,
const CxMap *minuend,
const CxMap *subtrahend);
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665 cx_attr_nonnull
666 CX_EXPORT int cxMapListDifferenceSimple(CxMap *dst,
const CxMap *src,
const CxList *keys);
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681 cx_attr_nonnull
682 CX_EXPORT int cxMapIntersectionSimple(CxMap *dst,
const CxMap *src,
const CxMap *other);
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701 cx_attr_nonnull
702 CX_EXPORT int cxMapListIntersectionSimple(CxMap *dst,
const CxMap *src,
const CxList *keys);
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720 cx_attr_nonnull
721 CX_EXPORT int cxMapUnionSimple(CxMap *dst,
const CxMap *src);
722
723 #ifdef __cplusplus
724 }
725 #endif
726
727 #endif
728