-
Notifications
You must be signed in to change notification settings - Fork 311
/
Copy pathcstl_multimap.c
628 lines (530 loc) · 19.3 KB
/
cstl_multimap.c
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
/*
* The implementation of multimap.
* Copyright (C) 2008 - 2013 Wangbo
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author e-mail: activesys.wb@gmail.com
* activesys@sina.com.cn
*/
/** include section **/
#include <cstl/cstl_def.h>
#include <cstl/cstl_alloc.h>
#include <cstl/cstl_types.h>
#include <cstl/citerator.h>
#include <cstl/cstring.h>
#include <cstl/cmap.h>
#include "cstl_multimap_aux.h"
/** local constant declaration and local macro section **/
/** local data type declaration and local struct, union, enum section **/
/** local function prototype section **/
/** exported global variable definition section **/
/** local global variable definition section **/
/** exported function implementation section **/
/**
* Initialize multimap container.
*/
void multimap_init(multimap_t* pmmap_map)
{
assert(pmmap_map != NULL);
assert(_pair_is_created(&pmmap_map->_pair_temp));
/* initialize the pair */
pair_init(&pmmap_map->_pair_temp);
/* initialize the tree */
#ifdef CSTL_MULTIMAP_AVL_TREE
_avl_tree_init(&pmmap_map->_t_tree, _multimap_value_compare);
#else
_rb_tree_init(&pmmap_map->_t_tree, _multimap_value_compare);
#endif
}
/**
* Initialize multimap container with user define compare function.
*/
void multimap_init_ex(multimap_t* pmmap_map, bfun_t bfun_keycompare)
{
assert(pmmap_map != NULL);
assert(_pair_is_created(&pmmap_map->_pair_temp));
pair_init(&pmmap_map->_pair_temp);
pmmap_map->_bfun_keycompare = bfun_keycompare;
pmmap_map->_pair_temp._bfun_mapkeycompare = bfun_keycompare;
#ifdef CSTL_MULTIMAP_AVL_TREE
_avl_tree_init(&pmmap_map->_t_tree, _multimap_value_compare);
#else
_rb_tree_init(&pmmap_map->_t_tree, _multimap_value_compare);
#endif
}
/**
* Destroy multimap.
*/
void multimap_destroy(multimap_t* pmmap_map)
{
_multimap_destroy_auxiliary(pmmap_map);
free(pmmap_map);
}
/**
* Initialize multimap container with multimap.
*/
void multimap_init_copy(multimap_t* pmmap_dest, const multimap_t* cpmmap_src)
{
assert(pmmap_dest != NULL);
assert(cpmmap_src != NULL);
assert(_pair_is_created(&pmmap_dest->_pair_temp));
assert(_pair_is_inited(&cpmmap_src->_pair_temp));
/* initialize dest multimap with src multimap attribute */
multimap_init(pmmap_dest);
pmmap_dest->_bfun_keycompare = cpmmap_src->_bfun_keycompare;
pmmap_dest->_bfun_valuecompare = cpmmap_src->_bfun_valuecompare;
pmmap_dest->_pair_temp._bfun_mapkeycompare = cpmmap_src->_pair_temp._bfun_mapkeycompare;
pmmap_dest->_pair_temp._bfun_mapvaluecompare = cpmmap_src->_pair_temp._bfun_mapvaluecompare;
assert(_multimap_same_pair_type_ex(&pmmap_dest->_pair_temp, &cpmmap_src->_pair_temp));
/* insert all element from src to dest */
if (!multimap_empty(cpmmap_src)) {
multimap_insert_range(pmmap_dest, multimap_begin(cpmmap_src), multimap_end(cpmmap_src));
}
}
/**
* Initialize multimap container with specific range.
*/
void multimap_init_copy_range(multimap_t* pmmap_dest, iterator_t it_begin, iterator_t it_end)
{
assert(pmmap_dest != NULL);
assert(_pair_is_created(&pmmap_dest->_pair_temp));
assert(iterator_equal(it_begin, it_end) || _iterator_before(it_begin, it_end));
multimap_init(pmmap_dest);
multimap_insert_range(pmmap_dest, it_begin, it_end);
}
/**
* Initialize multimap container with specific array.
*/
void multimap_init_copy_array(multimap_t* pmmap_dest, const void* cpv_array, size_t t_count)
{
assert(pmmap_dest != NULL);
assert(_pair_is_created(&pmmap_dest->_pair_temp));
assert(cpv_array != NULL);
multimap_init(pmmap_dest);
multimap_insert_array(pmmap_dest, cpv_array, t_count);
}
/**
* Initialize multimap container with specific range and compare function.
*/
void multimap_init_copy_range_ex(
multimap_t* pmmap_dest, iterator_t it_begin, iterator_t it_end, bfun_t bfun_keycompare)
{
assert(pmmap_dest != NULL);
assert(_pair_is_created(&pmmap_dest->_pair_temp));
assert(iterator_equal(it_begin, it_end) || _iterator_before(it_begin, it_end));
multimap_init_ex(pmmap_dest, bfun_keycompare);
multimap_insert_range(pmmap_dest, it_begin, it_end);
}
/**
* Initialize multimap container with specific array and compare function.
*/
void multimap_init_copy_array_ex(
multimap_t* pmmap_dest, const void* cpv_array, size_t t_count, bfun_t bfun_keycompare)
{
assert(pmmap_dest != NULL);
assert(_pair_is_created(&pmmap_dest->_pair_temp));
assert(cpv_array != NULL);
multimap_init_ex(pmmap_dest, bfun_keycompare);
multimap_insert_array(pmmap_dest, cpv_array, t_count);
}
/**
* Assign multimap container.
*/
void multimap_assign(multimap_t* pmmap_dest, const multimap_t* cpmmap_src)
{
assert(pmmap_dest != NULL);
assert(cpmmap_src != NULL);
assert(_pair_is_inited(&pmmap_dest->_pair_temp));
assert(_pair_is_inited(&cpmmap_src->_pair_temp));
assert(_multimap_same_pair_type_ex(&pmmap_dest->_pair_temp, &cpmmap_src->_pair_temp));
multimap_clear(pmmap_dest);
/* insert all element from src to dest */
if (!multimap_empty(cpmmap_src)) {
multimap_insert_range(pmmap_dest, multimap_begin(cpmmap_src), multimap_end(cpmmap_src));
}
}
/**
* Swap the datas of first multimap and second multimap.
*/
void multimap_swap(multimap_t* pmmap_first, multimap_t* pmmap_second)
{
assert(pmmap_first != NULL);
assert(pmmap_second != NULL);
assert(_pair_is_inited(&pmmap_first->_pair_temp));
assert(_pair_is_inited(&pmmap_second->_pair_temp));
assert(_multimap_same_pair_type_ex(&pmmap_first->_pair_temp, &pmmap_second->_pair_temp));
#ifdef CSTL_MULTIMAP_AVL_TREE
_avl_tree_swap(&pmmap_first->_t_tree, &pmmap_second->_t_tree);
#else
_rb_tree_swap(&pmmap_first->_t_tree, &pmmap_second->_t_tree);
#endif
}
/**
* Test if an multimap is empty.
*/
bool_t multimap_empty(const multimap_t* cpmmap_map)
{
assert(cpmmap_map != NULL);
assert(_pair_is_inited(&cpmmap_map->_pair_temp));
#ifdef CSTL_MULTIMAP_AVL_TREE
return _avl_tree_empty(&cpmmap_map->_t_tree);
#else
return _rb_tree_empty(&cpmmap_map->_t_tree);
#endif
}
/**
* Get the number of elements int the multimap.
*/
size_t multimap_size(const multimap_t* cpmmap_map)
{
assert(cpmmap_map != NULL);
assert(_pair_is_inited(&cpmmap_map->_pair_temp));
#ifdef CSTL_MULTIMAP_AVL_TREE
return _avl_tree_size(&cpmmap_map->_t_tree);
#else
return _rb_tree_size(&cpmmap_map->_t_tree);
#endif
}
/**
* Get the maximum number of elements int the multimap.
*/
size_t multimap_max_size(const multimap_t* cpmmap_map)
{
assert(cpmmap_map != NULL);
assert(_pair_is_inited(&cpmmap_map->_pair_temp));
#ifdef CSTL_MULTIMAP_AVL_TREE
return _avl_tree_max_size(&cpmmap_map->_t_tree);
#else
return _rb_tree_max_size(&cpmmap_map->_t_tree);
#endif
}
/**
* Return the compare function of key.
*/
bfun_t multimap_key_comp(const multimap_t* cpmmap_map)
{
assert(cpmmap_map != NULL);
assert(_pair_is_inited(&cpmmap_map->_pair_temp));
if (cpmmap_map->_bfun_keycompare != NULL) {
return cpmmap_map->_bfun_keycompare;
} else {
return _GET_MULTIMAP_FIRST_TYPE_LESS_FUNCTION(cpmmap_map);
}
}
/**
* Return the compare function of value.
*/
bfun_t multimap_value_comp(const multimap_t* cpmmap_map)
{
#ifdef NDEBUG
void* pv_avoidwarning = (void*)cpmmap_map;
pv_avoidwarning = NULL;
#endif
assert(cpmmap_map != NULL);
assert(_pair_is_inited(&cpmmap_map->_pair_temp));
return _multimap_value_compare;
}
/**
* Erases all the elements of an multimap.
*/
void multimap_clear(multimap_t* pmmap_map)
{
assert(pmmap_map != NULL);
assert(_pair_is_inited(&pmmap_map->_pair_temp));
#ifdef CSTL_MULTIMAP_AVL_TREE
_avl_tree_clear(&pmmap_map->_t_tree);
#else
_rb_tree_clear(&pmmap_map->_t_tree);
#endif
}
/**
* Tests if the two multimap are equal.
*/
bool_t multimap_equal(const multimap_t* cpmmap_first, const multimap_t* cpmmap_second)
{
assert(cpmmap_first != NULL);
assert(cpmmap_second != NULL);
assert(_pair_is_inited(&cpmmap_first->_pair_temp));
assert(_pair_is_inited(&cpmmap_second->_pair_temp));
if (cpmmap_first->_bfun_keycompare != cpmmap_second->_bfun_keycompare) {
return false;
}
#ifdef CSTL_MULTIMAP_AVL_TREE
return _avl_tree_equal(&cpmmap_first->_t_tree, &cpmmap_second->_t_tree);
#else
return _rb_tree_equal(&cpmmap_first->_t_tree, &cpmmap_second->_t_tree);
#endif
}
/**
* Tests if the two multimap are not equal.
*/
bool_t multimap_not_equal(const multimap_t* cpmmap_first, const multimap_t* cpmmap_second)
{
assert(cpmmap_first != NULL);
assert(cpmmap_second != NULL);
assert(_pair_is_inited(&cpmmap_first->_pair_temp));
assert(_pair_is_inited(&cpmmap_second->_pair_temp));
if (cpmmap_first->_bfun_keycompare != cpmmap_second->_bfun_keycompare) {
return true;
}
#ifdef CSTL_MULTIMAP_AVL_TREE
return _avl_tree_not_equal(&cpmmap_first->_t_tree, &cpmmap_second->_t_tree);
#else
return _rb_tree_not_equal(&cpmmap_first->_t_tree, &cpmmap_second->_t_tree);
#endif
}
/**
* Tests if the first multimap is less than the second multimap.
*/
bool_t multimap_less(const multimap_t* cpmmap_first, const multimap_t* cpmmap_second)
{
assert(cpmmap_first != NULL);
assert(cpmmap_second != NULL);
assert(_pair_is_inited(&cpmmap_first->_pair_temp));
assert(_pair_is_inited(&cpmmap_second->_pair_temp));
assert(_multimap_same_pair_type_ex(&cpmmap_first->_pair_temp, &cpmmap_second->_pair_temp));
#ifdef CSTL_MULTIMAP_AVL_TREE
return _avl_tree_less(&cpmmap_first->_t_tree, &cpmmap_second->_t_tree);
#else
return _rb_tree_less(&cpmmap_first->_t_tree, &cpmmap_second->_t_tree);
#endif
}
/**
* Tests if the first multimap is less than or equal to the second multimap.
*/
bool_t multimap_less_equal(const multimap_t* cpmmap_first, const multimap_t* cpmmap_second)
{
assert(cpmmap_first != NULL);
assert(cpmmap_second != NULL);
assert(_pair_is_inited(&cpmmap_first->_pair_temp));
assert(_pair_is_inited(&cpmmap_second->_pair_temp));
assert(_multimap_same_pair_type_ex(&cpmmap_first->_pair_temp, &cpmmap_second->_pair_temp));
#ifdef CSTL_MULTIMAP_AVL_TREE
return _avl_tree_less_equal(&cpmmap_first->_t_tree, &cpmmap_second->_t_tree);
#else
return _rb_tree_less_equal(&cpmmap_first->_t_tree, &cpmmap_second->_t_tree);
#endif
}
/**
* Tests if the first multimap is greater than the second multimap.
*/
bool_t multimap_greater(const multimap_t* cpmmap_first, const multimap_t* cpmmap_second)
{
assert(cpmmap_first != NULL);
assert(cpmmap_second != NULL);
assert(_pair_is_inited(&cpmmap_first->_pair_temp));
assert(_pair_is_inited(&cpmmap_second->_pair_temp));
assert(_multimap_same_pair_type_ex(&cpmmap_first->_pair_temp, &cpmmap_second->_pair_temp));
#ifdef CSTL_MULTIMAP_AVL_TREE
return _avl_tree_greater(&cpmmap_first->_t_tree, &cpmmap_second->_t_tree);
#else
return _rb_tree_greater(&cpmmap_first->_t_tree, &cpmmap_second->_t_tree);
#endif
}
/**
* Tests if the first multimap is greater than or equal to the second multimap.
*/
bool_t multimap_greater_equal(const multimap_t* cpmmap_first, const multimap_t* cpmmap_second)
{
assert(cpmmap_first != NULL);
assert(cpmmap_second != NULL);
assert(_pair_is_inited(&cpmmap_first->_pair_temp));
assert(_pair_is_inited(&cpmmap_second->_pair_temp));
assert(_multimap_same_pair_type_ex(&cpmmap_first->_pair_temp, &cpmmap_second->_pair_temp));
#ifdef CSTL_MULTIMAP_AVL_TREE
return _avl_tree_greater_equal(&cpmmap_first->_t_tree, &cpmmap_second->_t_tree);
#else
return _rb_tree_greater_equal(&cpmmap_first->_t_tree, &cpmmap_second->_t_tree);
#endif
}
/**
* Return an iterator that addresses the first element in the multimap.
*/
multimap_iterator_t multimap_begin(const multimap_t* cpmmap_map)
{
multimap_iterator_t it_iter;
assert(cpmmap_map != NULL);
assert(_pair_is_inited(&cpmmap_map->_pair_temp));
#ifdef CSTL_MULTIMAP_AVL_TREE
it_iter = _avl_tree_begin(&cpmmap_map->_t_tree);
#else
it_iter = _rb_tree_begin(&cpmmap_map->_t_tree);
#endif
_ITERATOR_CONTAINER(it_iter) = (multimap_t*)cpmmap_map;
_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_iter) = _MULTIMAP_CONTAINER;
_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR;
return it_iter;
}
/**
* Return an iterator that addresses the location succeeding the last element in the multimap.
*/
multimap_iterator_t multimap_end(const multimap_t* cpmmap_map)
{
multimap_iterator_t it_iter;
assert(cpmmap_map != NULL);
assert(_pair_is_inited(&cpmmap_map->_pair_temp));
#ifdef CSTL_MULTIMAP_AVL_TREE
it_iter = _avl_tree_end(&cpmmap_map->_t_tree);
#else
it_iter = _rb_tree_end(&cpmmap_map->_t_tree);
#endif
_ITERATOR_CONTAINER(it_iter) = (multimap_t*)cpmmap_map;
_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_iter) = _MULTIMAP_CONTAINER;
_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR;
return it_iter;
}
multimap_reverse_iterator_t multimap_rbegin(const multimap_t* cpmmap_map)
{
multimap_reverse_iterator_t it_iter;
assert(cpmmap_map != NULL);
assert(_pair_is_inited(&cpmmap_map->_pair_temp));
#ifdef CSTL_MULTIMAP_AVL_TREE
it_iter = _avl_tree_rbegin(&cpmmap_map->_t_tree);
#else
it_iter = _rb_tree_rbegin(&cpmmap_map->_t_tree);
#endif
_ITERATOR_CONTAINER(it_iter) = (multimap_t*)cpmmap_map;
_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_iter) = _MULTIMAP_CONTAINER;
_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR;
return it_iter;
}
multimap_reverse_iterator_t multimap_rend(const multimap_t* cpmmap_map)
{
multimap_reverse_iterator_t it_iter;
assert(cpmmap_map != NULL);
assert(_pair_is_inited(&cpmmap_map->_pair_temp));
#ifdef CSTL_MULTIMAP_AVL_TREE
it_iter = _avl_tree_rend(&cpmmap_map->_t_tree);
#else
it_iter = _rb_tree_rend(&cpmmap_map->_t_tree);
#endif
_ITERATOR_CONTAINER(it_iter) = (multimap_t*)cpmmap_map;
_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_iter) = _MULTIMAP_CONTAINER;
_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR;
return it_iter;
}
/**
* Inserts an unique element into a multimap.
*/
multimap_iterator_t multimap_insert(multimap_t* pmmap_map, const pair_t* cppair_pair)
{
multimap_iterator_t it_iter;
assert(pmmap_map != NULL);
assert(cppair_pair != NULL);
assert(_pair_is_inited(&pmmap_map->_pair_temp));
assert(_pair_is_inited(cppair_pair));
((pair_t*)cppair_pair)->_bfun_mapkeycompare = pmmap_map->_bfun_keycompare;
((pair_t*)cppair_pair)->_bfun_mapvaluecompare = pmmap_map->_bfun_valuecompare;
assert(_multimap_same_pair_type_ex(&pmmap_map->_pair_temp, cppair_pair));
#ifdef CSTL_MULTIMAP_AVL_TREE
it_iter = _avl_tree_insert_equal(&pmmap_map->_t_tree, cppair_pair);
#else
it_iter = _rb_tree_insert_equal(&pmmap_map->_t_tree, cppair_pair);
#endif
_ITERATOR_CONTAINER(it_iter) = pmmap_map;
_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_iter) = _MULTIMAP_CONTAINER;
_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR;
return it_iter;
}
/**
* Inserts an unique element into a multimap with hint position.
*/
multimap_iterator_t multimap_insert_hint(multimap_t* pmmap_map, multimap_iterator_t it_hint, const pair_t* cppair_pair)
{
assert(pmmap_map != NULL);
assert(cppair_pair != NULL);
assert(_pair_is_inited(&pmmap_map->_pair_temp));
assert(_pair_is_inited(cppair_pair));
assert(_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_hint) == _MULTIMAP_CONTAINER);
assert(_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_hint) == _BIDIRECTIONAL_ITERATOR);
assert(_MULTIMAP_ITERATOR_CONTAINER(it_hint) == pmmap_map);
((pair_t*)cppair_pair)->_bfun_mapkeycompare = pmmap_map->_bfun_keycompare;
((pair_t*)cppair_pair)->_bfun_mapvaluecompare = pmmap_map->_bfun_valuecompare;
assert(_multimap_same_pair_type_ex(&pmmap_map->_pair_temp, cppair_pair));
#ifdef CSTL_MULTIMAP_AVL_TREE
it_hint = _avl_tree_insert_equal(&pmmap_map->_t_tree, cppair_pair);
#else
it_hint = _rb_tree_insert_equal(&pmmap_map->_t_tree, cppair_pair);
#endif
_ITERATOR_CONTAINER(it_hint) = pmmap_map;
_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_hint) = _MULTIMAP_CONTAINER;
_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_hint) = _BIDIRECTIONAL_ITERATOR;
return it_hint;
}
/**
* Inserts an range of unique element into a multimap.
*/
void multimap_insert_range(multimap_t* pmmap_map, iterator_t it_begin, iterator_t it_end)
{
iterator_t it_iter;
assert(pmmap_map != NULL);
assert(_pair_is_inited(&pmmap_map->_pair_temp));
assert(iterator_equal(it_begin, it_end) || _iterator_before(it_begin, it_end));
for (it_iter = it_begin; !iterator_equal(it_iter, it_end); it_iter = iterator_next(it_iter)) {
assert(_multimap_same_pair_type(&pmmap_map->_pair_temp, (pair_t*)iterator_get_pointer(it_iter)));
multimap_insert(pmmap_map, (pair_t*)iterator_get_pointer(it_iter));
}
}
/**
* Inserts an array of element into a multimap.
*/
void multimap_insert_array(multimap_t* pmmap_map, const void* cpv_array, size_t t_count)
{
size_t i = 0;
assert(pmmap_map != NULL);
assert(_pair_is_inited(&pmmap_map->_pair_temp));
assert(cpv_array != NULL);
for (i = 0; i < t_count; ++i) {
assert(_multimap_same_pair_type(&pmmap_map->_pair_temp, ((pair_t**)cpv_array)[i]));
multimap_insert(pmmap_map, ((pair_t**)cpv_array)[i]);
}
}
/*
* Erase an element in an multimap from specificed position.
*/
void multimap_erase_pos(multimap_t* pmmap_map, multimap_iterator_t it_pos)
{
assert(pmmap_map != NULL);
assert(_pair_is_inited(&pmmap_map->_pair_temp));
assert(_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_pos) == _MULTIMAP_CONTAINER);
assert(_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_pos) == _BIDIRECTIONAL_ITERATOR);
assert(_MULTIMAP_ITERATOR_CONTAINER(it_pos) == pmmap_map);
#ifdef CSTL_MULTIMAP_AVL_TREE
_avl_tree_erase_pos(&pmmap_map->_t_tree, it_pos);
#else
_rb_tree_erase_pos(&pmmap_map->_t_tree, it_pos);
#endif
}
/*
* Erase a range of element in an multimap.
*/
void multimap_erase_range(multimap_t* pmmap_map, multimap_iterator_t it_begin, multimap_iterator_t it_end)
{
assert(pmmap_map != NULL);
assert(_pair_is_inited(&pmmap_map->_pair_temp));
assert(_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_begin) == _MULTIMAP_CONTAINER);
assert(_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_begin) == _BIDIRECTIONAL_ITERATOR);
assert(_MULTIMAP_ITERATOR_CONTAINER_TYPE(it_end) == _MULTIMAP_CONTAINER);
assert(_MULTIMAP_ITERATOR_ITERATOR_TYPE(it_end) == _BIDIRECTIONAL_ITERATOR);
assert(_MULTIMAP_ITERATOR_CONTAINER(it_begin) == pmmap_map && _MULTIMAP_ITERATOR_CONTAINER(it_end) == pmmap_map);
#ifdef CSTL_MULTIMAP_AVL_TREE
_avl_tree_erase_range(&pmmap_map->_t_tree, it_begin, it_end);
#else
_rb_tree_erase_range(&pmmap_map->_t_tree, it_begin, it_end);
#endif
}
/** local function implementation section **/
/** eof **/