acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
map.h
1
#pragma once
2
3
4
#include "set.h"
5
#include "acme/prototype/comparison/equals.h"
6
7
8
template
<
typename
PAIR, enum_allocate t_eallocate >
9
class
pair_map_base
:
10
public
::node_set_base < ::make_pair < PAIR >, t_eallocate >
11
{
12
public
:
13
//
14
//
15
using
BASE_PAIR_MAP = ::node_set_base < ::make_pair < PAIR >, t_eallocate >;
16
//
17
//
18
// using HASH_TABLE = typename BASE_PAIR_MAP::HASH_TABLE;
19
// using KEY = typename ::make_pair < PAIR >::KEY;
20
// using PAYLOAD = typename ::make_pair < PAIR >::PAYLOAD;
21
// using ARG_KEY = typename ::make_pair < PAIR >::ARG_KEY;
22
// using ARG_PAYLOAD = typename ::make_pair < PAIR >::ARG_PAYLOAD;
23
//
24
//
25
// using BASE_NODE = typename BASE_PAIR_MAP::BASE_NODE;
26
// using ITEM = typename BASE_PAIR_MAP::ITEM;
27
//
28
using
iterator =
typename
BASE_PAIR_MAP::iterator;
29
// using const_iterator = typename BASE_PAIR_MAP::const_iterator;
30
//
31
// using item_iterator = ::element1_list_iterator < BASE_NODE * >;
32
// using payload_iterator = ::element2_list_iterator < BASE_NODE * >;
33
// using const_item_iterator = typename item_iterator::const_iterator;
34
// using const_payload_iterator = typename payload_iterator::const_iterator;
35
36
37
//using iterator_struct = BASE_SET::iterator_struct;
38
//using const_iterator_struct = BASE_SET::const_iterator_struct;
39
//using key_iterator = BASE_SET::key_iterator;
40
//using iterator = BASE_SET::iterator;
41
//using const_iterator = BASE_SET::const_iterator;
42
//sing make_iterator = BASE_SET::make_iterator;
43
44
//__declare_iterator_struct_ok(pair_map_base, iterator, m_pnode, ::is_set(this->m_pnode));
45
46
47
//using BASE_PAIR_MAP = ::node_set_base < ::make_pair < PAIR > >;
48
49
using
BASE_PAIR_MAP::BASE_PAIR_MAP;
50
using
BASE_PAIR_MAP::operator =;
51
52
53
void
pair_map_base_ok()
const
54
{
55
56
BASE_PAIR_MAP::container_ok();
57
58
}
59
60
61
void
container_ok()
const
62
{
63
64
pair_map_base_ok();
65
66
}
67
68
69
template
<
typename
STRING >
70
iterator case_insensitive_find_key_containing(
const
STRING & str)
const
71
{
72
73
auto
iterator = this->begin();
74
75
while
(iterator)
76
{
77
78
if
(iterator->element1().case_insensitive_contains(str))
79
{
80
81
return
iterator;
82
83
}
84
85
++iterator;
86
87
}
88
89
return
nullptr
;
90
91
}
92
93
94
95
// void assert_container_ok() const;
96
//
97
//
98
// pair_map_base();
99
// pair_map_base(const PAIR * iterator, ::collection::count c);
100
// pair_map_base(const ::std::initializer_list < PAIR > & list_base);
101
// pair_map_base(const pair_map_base & m);
102
// ~pair_map_base();
103
//
104
// void construct();
105
//
106
//
107
// ::collection::count get_count() const;
108
// ::collection::count get_size() const;
109
// ::collection::count size() const;
110
// ::collection::count count() const;
111
// bool is_empty() const;
112
// bool empty() const;
113
//
114
//
115
//
116
// //find
117
// //bool find(ARG_KEY key, PAYLOAD& rValue) const;
118
// //const_iterator find(ARG_KEY key) const;
119
// //iterator find(ARG_KEY key);
120
//
121
//
122
// //PAYLOAD * defer_get(ARG_KEY key);
123
//
124
//
125
// //inline typename pair_map_base < PAIR >::iterator get_item(ARG_KEY key);
126
//
127
//
128
// template < typename TITEM >
129
// auto pop(const TITEM & key)
130
// {
131
//
132
// auto value = operator[](key);
133
//
134
// this->erase_item(key);
135
//
136
// return value;
137
//
138
// }
139
//
140
// //Operations
141
// //find and add if not there
142
// inline PAYLOAD & operator[](ARG_KEY key);
143
// inline const PAYLOAD & operator[](ARG_KEY key) const;
144
//
145
// template < typename PAYLOAD2 >
146
// iterator find_payload(const PAYLOAD2 & payload) const;
147
//
148
// //add a allocateø< >(key, value) node
149
// iterator set_at(ARG_KEY key, ARG_PAYLOAD newValue)
150
// {
151
//
152
// auto p = this->get_node(key);
153
//
154
// p->payload() = newValue;
155
//
156
// return p;
157
//
158
// }
159
//
160
//
161
// //add a allocateø< >(key, value) node
162
// void set_pair(const PAIR & pair)
163
// {
164
//
165
// set_at((ARG_KEY) pair.element1(), (ARG_PAYLOAD) pair.element2());
166
//
167
// }
168
//
169
//
170
// //bool unhash(iterator iterator);
171
//
172
// //removing existing (key, ?) node
173
// //inline bool erase_item(ARG_KEY key) { auto p = this->find_item(key); return p ? this->erase(p) : false; }
174
//
175
// template < typename PAYLOAD2 >
176
// inline bool erase_payload(const PAYLOAD2 payload) { auto p = find_payload(payload); return p ? erase(p) : false; }
177
//
178
//
179
//
180
// inline auto items() { return ::range<item_iterator>(*(item_iterator *)&this->begin(), *(item_iterator *)&this->end()); }
181
// inline auto payloads() { return ::range<payload_iterator>(*(payload_iterator *)&this->begin(), *(payload_iterator *)&this->end()); }
182
// inline auto items() const { return ::range<const_item_iterator>((item_iterator)this->begin(), (item_iterator)this->end()); }
183
// inline auto payloads() const { return ::range<const_payload_iterator>((payload_iterator )this->begin(), (payload_iterator)this->end()); }
184
// ::collection::count key_count(ARG_KEY key) const;
185
// bool has_key(ARG_KEY key) const;
186
// bool contains_key(ARG_KEY key) const;
187
//
188
// //iterating all (key, value) pairs
189
// // POSITION get_start_position() const;
190
//
191
// //inline const iterator get_start() const;
192
// //inline iterator get_start();
193
//
194
// //void get_next(iterator & rNextPosition, ITEM& rKey, PAYLOAD& rValue) const;
195
//
196
// //const iterator get_next(const iteratorpnodeRet) const;
197
// //iterator get_next(const iteratorpnodeRet);
198
//
199
// //advanced features for derived classes
200
// ::u32 GetHashTableSize() const
201
// {
202
//
203
// return this->m_hashtable.GetHashTableSize();
204
//
205
// }
206
//
207
//
208
// void InitHashTable(::u32 hashSize,bool bAllocNow = true);
209
//
210
//
211
// PAYLOAD get(ARG_KEY key, ARG_PAYLOAD valueDefault);
212
//
213
//
214
//
215
// void set(pair_map_base & pair_map_base)
216
// {
217
//
218
// for(auto & pair : pair_map_base)
219
// {
220
//
221
// set_at(pair.element1(), pair.element2());
222
//
223
// }
224
//
225
// }
226
//
227
//
228
// //inline iterator find_item(ARG_KEY key) const { return find_node(key); }
229
//
230
// //using BASE_SET::find_item;
231
// //inline const_iterator find_item(ARG_KEY key) const { return ((pair_map_base *) this)->find_item(key); }
232
//
233
//
234
// //BASE_NODE * new_node(ARG_KEY key, ::u32 nHashBucket, ::u32 nHashValue);
235
// //inline void hash(BASE_NODE *, ::u32 nHashBucket, ::u32 nHashValue);
236
// //void attach(iterator iterator, ::u32 nHashBucket, ::u32 nHashValue);
237
// //bool erase(iterator iterator);
238
// //void detach(iterator iterator);
239
// //void hash(::u32& nHashBucket, ::u32& nHashValue, ARG_KEY) const;
240
// //inline iterator node_at(ARG_KEY, ::u32 & nHashBucket, ::u32 & nHashValue) const;
241
// //inline const_iterator node_at(ARG_KEY, ::u32& nHashBucket, ::u32& nHashValue) const;
242
//
243
// // void transfer(iterator iterator, pair_map_base * iterator_map = nullptr);
244
// // void transfer(pair_map_base* iterator_map, ARG_KEY key);
245
//
246
// //// void assert_ok() const override;
247
// //// void dump(dump_context & dumpcontext) const override;
248
//
249
//
250
// template < class ARRAY >
251
// bool erase_key_array(ARRAY a)
252
// {
253
//
254
// bool bRemoved = false;
255
//
256
// for(::collection::index i = 0; i < a.get_count(); i++)
257
// {
258
//
259
// bRemoved |= erase_key(a[i]);
260
//
261
// }
262
//
263
// return bRemoved;
264
//
265
// }
266
//
267
//
268
// template < class ARRAY >
269
// ::collection::count erase_node_array(ARRAY a)
270
// {
271
//
272
// ::collection::count countRemoved = 0;
273
//
274
// for(::collection::index i = 0; i < a.get_count(); i++)
275
// {
276
//
277
// if(erase_node(a[i]))
278
// {
279
//
280
// countRemoved++;
281
//
282
// }
283
//
284
// }
285
//
286
// return countRemoved;
287
//
288
// }
289
//
290
// //virtual void on_after_read() override {}
291
//
292
//
293
// //PAIR & element_at(::collection::index iIndex)
294
// //{
295
// // return this->elements().element_at(iIndex);
296
// //}
297
//
298
// template < typename PRED >
299
// typename pair_map_base < PAIR >::iterator predicate_find(PRED pred)
300
// {
301
//
302
// auto p = this->begin();
303
//
304
// while (::is_ok(p))
305
// {
306
//
307
// if (pred(p))
308
// {
309
//
310
// return p;
311
//
312
// }
313
//
314
// p++;
315
//
316
// }
317
//
318
// return nullptr;
319
//
320
// }
321
//
322
// pair_map_base & operator = (const pair_map_base & m);
323
//
324
//
325
// template < typename TYPE >
326
// ::pointer<TYPE>get_typed_ptr(::collection::index i = 0)
327
// {
328
//
329
// ::pointer<TYPE>p;
330
//
331
// for(auto & node : *this)
332
// {
333
//
334
// p = (*node).element2();
335
//
336
// if(p)
337
// {
338
//
339
// if(i <= 0)
340
// {
341
//
342
// return p;
343
//
344
// }
345
//
346
// i--;
347
//
348
// }
349
//
350
// }
351
//
352
// return nullptr;
353
//
354
// }
355
356
357
};
358
359
//
360
// template < typename PAIR >
361
// inline ::collection::count pair_map_base < PAIR >::get_count() const
362
// {
363
// return this->m_count;
364
// }
365
//
366
// template < typename PAIR >
367
// inline ::collection::count pair_map_base < PAIR >::get_size() const
368
// {
369
// return this->m_count;
370
// }
371
//
372
// template < typename PAIR >
373
// inline ::collection::count pair_map_base < PAIR >::count() const
374
// {
375
// return this->m_count;
376
// }
377
//
378
// template < typename PAIR >
379
// inline ::collection::count pair_map_base < PAIR >::size() const
380
// {
381
// return this->m_count;
382
// }
383
//
384
// template < typename PAIR >
385
// pair_map_base < PAIR > & pair_map_base < PAIR >::operator = (const pair_map_base & m)
386
// {
387
// if(this != &m)
388
// {
389
//
390
// this->erase_all();
391
//
392
// for(auto & node : m)
393
// {
394
//
395
// set_at((ARG_KEY) node.element1(), (ARG_PAYLOAD) node.element2());
396
//
397
// }
398
//
399
// }
400
// return *this;
401
// }
402
//
403
//
404
// template < typename PAIR >
405
// inline bool pair_map_base < PAIR >::is_empty() const
406
// {
407
//
408
// return this->m_count == 0;
409
//
410
// }
411
//
412
//
413
// template < typename PAIR >
414
// inline bool pair_map_base < PAIR >::empty() const
415
// {
416
//
417
// return this->m_count == 0;
418
//
419
// }
420
421
422
//template < typename PAIR >
423
//typename pair_map_base < PAIR >::iterator pair_map_base < PAIR >::set_at(ARG_KEY key,ARG_PAYLOAD newValue)
424
425
426
//template < typename PAIR >
427
//inline typename pair_map_base < PAIR >::iterator pair_map_base < PAIR >::get_start() const
428
//{
429
// return (this->m_count == 0) ? nullptr : BEFORE_START_POSITION;
430
//}
431
432
//
433
//
434
// /////////////////////////////////////////////////////////////////////////////
435
// // pair_map_base < PAIR > out-of-line functions
436
// template < typename PAIR >
437
// void pair_map_base < PAIR >::construct()
438
// {
439
//
440
// this->m_count = 0;
441
//
442
// this->m_begin = nullptr;
443
//
444
// this->m_end = nullptr;
445
//
446
// }
447
//
448
//
449
// template < typename PAIR >
450
// pair_map_base < PAIR >::pair_map_base()
451
// {
452
//
453
// construct();
454
//
455
// }
456
//
457
//
458
// template < typename PAIR >
459
// pair_map_base < PAIR >::pair_map_base(const ::std::initializer_list < PAIR > & list_base)
460
// {
461
//
462
// construct();
463
//
464
// for(auto & pair : list_base)
465
// {
466
//
467
// set_at((ARG_KEY) pair.element1(), (ARG_PAYLOAD) pair.element2());
468
//
469
// }
470
//
471
// }
472
//
473
// template < typename PAIR >
474
// pair_map_base < PAIR >::pair_map_base(const PAIR * iterator, ::collection::count c)
475
// {
476
// construct();
477
// for(::collection::index i = 0; i < c; i++)
478
// {
479
// set_at((ARG_KEY) iterator[i].element1(), (ARG_PAYLOAD) iterator[i].element2());
480
// }
481
// }
482
//
483
//
484
// template < typename PAIR >
485
// pair_map_base < PAIR >::pair_map_base(const pair_map_base & m)
486
// {
487
//
488
// construct();
489
//
490
// for(auto & pair : m)
491
// {
492
//
493
// set_at((ARG_KEY) pair.element1(), (ARG_PAYLOAD) pair.element2());
494
//
495
// }
496
//
497
// }
498
499
//template < typename PAIR >
500
//inline void pair_map_base < PAIR >::clear()
501
//{
502
// erase_all();
503
//}
504
//
505
//template < typename PAIR >
506
//inline void pair_map_base < PAIR >::Empty()
507
//{
508
// clear();
509
//}
510
//
511
// template < typename PAIR >
512
// pair_map_base < PAIR >::~pair_map_base()
513
// {
514
// this->erase_all();
515
// ASSERT(this->m_count == 0);
516
// }
517
//
518
519
// template < typename PAIR >
520
// void pair_map_base < PAIR >::attach(iterator p, ::u32 nHashBucket, ::u32 nHashValue)
521
// {
522
//
523
// hash(p, nHashBucket, nHashValue);
524
//
525
// if (this->m_begin)
526
// {
527
//
528
// this->m_begin.back() = p.get();
529
//
530
// }
531
//
532
// p.next() = this->begin().get();
533
//
534
// this->begin() = p;
535
//
536
// this->begin().back() = nullptr;
537
//
538
// this->m_count++;
539
//
540
// ASSERT(this->m_count > 0); // make sure we don't overflow
541
//
542
// }
543
//
544
545
546
//
547
// template < typename PAIR >
548
// inline void pair_map_base < PAIR >::hash(iterator p, ::u32 nHashBucket, ::u32 nHashValue)
549
// {
550
//
551
// // not precise (memleak? a watch dog can restart from the last check point... continuable tasks need...) but self-healing(self-recoverable/not-fatal)...
552
// if (::is_null(this->m_hashtable.m_ppHash))
553
// {
554
//
555
// InitHashTable(this->m_hashtable.GetHashTableSize());
556
//
557
// }
558
//
559
// if (::is_set(this->m_hashtable.m_ppHash[nHashBucket]))
560
// {
561
//
562
// this->m_hashtable.m_ppHash[nHashBucket]->m_pbackHash = &p.m_p->m_nextHash;
563
//
564
// }
565
//
566
// p.m_p->m_nextHash = this->m_hashtable.m_ppHash[nHashBucket];
567
//
568
// this->m_hashtable.m_ppHash[nHashBucket] = p.m_p;
569
//
570
// p.m_p->m_pbackHash = &this->m_hashtable.m_ppHash[nHashBucket];
571
//
572
// }
573
//
574
//
575
// template < typename PAIR >
576
// typename pair_map_base < PAIR >::iterator
577
// pair_map_base < PAIR >::new_node(ARG_KEY key, ::u32 nHashBucket, ::u32 nHashValue)
578
// {
579
//
580
// //if(this->m_pnodeFree == nullptr)
581
// //{
582
// // // add another block
583
// // //plex * newBlock = plex::create(m_pplex, m_nBlockSize, sizeof(pair_map_base::node));
584
// // //// chain them into free list_base
585
// // //pair_map_base::iterator iterator = (pair_map_base::iterator) newBlock->data();
586
// // //// free in reverse order to make it easier to debug
587
// // //::collection::index i = m_nBlockSize - 1;
588
// // //for (iterator = &iterator[i]; i >= 0; i--, iterator--)
589
// // //{
590
// // // iterator->m_next = this->m_pnodeFree;
591
// // // this->m_pnodeFree = iterator;
592
//
593
// // //}
594
// // this->m_pnodeFree = ___new node();
595
//
596
// //}
597
//
598
// //ENSURE(this->m_pnodeFree != nullptr); // we must have something
599
//
600
// auto p = øraw_new BASE_NODE (key);
601
//
602
// attach(p, nHashBucket, nHashValue);
603
//
604
// return p;
605
//
606
// }
607
//
608
//
609
// template < typename PAIR >
610
// bool pair_map_base < PAIR >::erase(iterator iterator)
611
// {
612
//
613
// detach(iterator);
614
//
615
// delete iterator.get();
616
//
617
// return true;
618
//
619
// }
620
//
621
//
622
// template < typename PAIR >
623
// void pair_map_base < PAIR >::detach(iterator iterator)
624
// {
625
//
626
// this->unhash(iterator);
627
//
628
// auto next = iterator->m_next;
629
//
630
// if (::is_set(iterator->m_next))
631
// {
632
//
633
// iterator->m_next->m_back = iterator->m_back;
634
//
635
// }
636
//
637
// if (::is_set(iterator->m_back))
638
// {
639
//
640
// iterator->m_back->m_next = iterator->m_next;
641
//
642
// }
643
//
644
// if (this->m_begin == iterator)
645
// {
646
//
647
// this->m_begin = next;
648
//
649
// if (::is_set(this->m_begin))
650
// {
651
//
652
// this->m_begin->m_back = nullptr;
653
//
654
// }
655
//
656
// }
657
//
658
// //delete iterator;
659
//
660
// //iterator->m_next = this->m_pnodeFree;
661
//
662
// //this->m_pnodeFree = iterator;
663
//
664
// this->m_count--;
665
//
666
// ASSERT(this->m_count >= 0); // make sure we don't underflow
667
//
668
// // if no more elements, cleanup completely
669
// if (this->m_count == 0)
670
// {
671
//
672
// this->erase_all();
673
//
674
// }
675
//
676
// }
677
//
678
// template < typename PAIR >
679
// void pair_map_base < PAIR >::hash(::u32& nHashBucket, ::u32& nHashValue, ARG_KEY key) const
680
// {
681
//
682
// nHashValue = ::as_hash32(key).m_u;
683
//
684
// nHashBucket = nHashValue % this->m_hashtable.GetHashTableSize();
685
//
686
// }
687
//
688
// //template < typename PAIR >
689
// //inline typename pair_map_base < PAIR >::const_iterator
690
// //pair_map_base < PAIR >::node_at(ARG_KEY key, ::u32 & nHashBucket, ::u32 & nHashValue) const
691
// //{
692
// //
693
// // return (const_iterator &) ((pair_map_base *)this)->node_at(key, nHashBucket, nHashValue);
694
// //
695
// //}
696
//
697
//
698
// template < typename PAIR >
699
// inline typename pair_map_base < PAIR >::iterator
700
// pair_map_base < PAIR >::node_at(ARG_KEY key, ::u32& nHashBucket, ::u32& nHashValue) const
701
// {
702
//
703
// hash(nHashBucket, nHashValue, key);
704
//
705
// if (get_count() <= 0)
706
// {
707
//
708
// return nullptr;
709
//
710
// }
711
//
712
// for(auto p = this->m_hashtable.m_ppHash[nHashBucket]; p; p = p->m_nextHash)
713
// {
714
//
715
// if (EqualElements<ARG_KEY>(p->key(), key))
716
// {
717
//
718
// return p;
719
//
720
// }
721
//
722
// }
723
//
724
// return nullptr;
725
//
726
// }
727
//
728
// template < typename PAIR >
729
// void pair_map_base < PAIR >::transfer(pair_map_base* iterator_map, ARG_KEY key)
730
// {
731
//
732
// ::u32 uHashBucket;
733
//
734
// ::u32 uHashValue;
735
//
736
// auto iterator = iterator_map->node_at(key, uHashBucket, uHashValue);
737
//
738
// iterator_map->detach(iterator);
739
//
740
// attach(iterator, uHashBucket, uHashValue);
741
//
742
// }
743
//
744
//
745
//
746
// template < typename PAIR >
747
// void pair_map_base < PAIR >::transfer(iterator iterator, pair_map_base * iterator_map)
748
// {
749
//
750
// if (iterator_map == this)
751
// {
752
//
753
// return;
754
//
755
// }
756
//
757
// if (::is_set(iterator_map))
758
// {
759
//
760
// iterator_map->detach(iterator);
761
//
762
// }
763
//
764
// ::u32 nHashBucket;
765
//
766
// ::u32 nHashValue;
767
//
768
// hash(nHashBucket, nHashValue, iterator->element1());
769
//
770
// attach(iterator, nHashBucket, nHashValue);
771
//
772
// }
773
//
774
//
775
// template < typename PAIR >
776
// bool pair_map_base < PAIR >::find(ARG_KEY key, PAYLOAD& rValue) const
777
// {
778
//
779
// auto pnode = this->find_node(key);
780
//
781
// if (!pnode)
782
// {
783
//
784
// return false; // not in pair_map_base
785
//
786
// }
787
//
788
// rValue = pnode->element2();
789
//
790
// return true;
791
//
792
// }
793
// template < typename PAIR >
794
// template < typename PAYLOAD2 >
795
// inline typename pair_map_base < PAIR >::iterator pair_map_base < PAIR >::find_payload(const PAYLOAD2 & payload) const
796
// {
797
//
798
// auto p = this->begin();
799
//
800
// while(p != this->end())
801
// {
802
//
803
// if(p->payload() == payload)
804
// {
805
//
806
// return p;
807
//
808
// }
809
//
810
// }
811
//
812
// return nullptr;
813
//
814
// }
815
816
817
// template < typename PAIR >
818
// inline typename pair_map_base < PAIR >::iterator pair_map_base < PAIR >::get_item(ARG_KEY key)
819
// {
820
//
821
// ::u32 nHashBucket,nHashValue;
822
//
823
// iterator p;
824
//
825
// if(!(p = node_at(key,nHashBucket,nHashValue)))
826
// {
827
//
828
// p = this->new_node(key, nHashBucket, nHashValue);
829
//
830
// }
831
//
832
// return p;
833
//
834
// }
835
836
//
837
// template < typename PAIR >
838
// inline typename pair_map_base < PAIR >::PAYLOAD & pair_map_base < PAIR >::operator[](ARG_KEY key)
839
// {
840
//
841
// return this->get_node(key)->element2();
842
//
843
// }
844
//
845
//
846
// template < typename PAIR >
847
// inline const typename pair_map_base < PAIR >::PAYLOAD & pair_map_base < PAIR >::operator[](ARG_KEY key) const
848
// {
849
//
850
// auto pnode = this->find_node(key);
851
//
852
// if(!pnode)
853
// {
854
//
855
// throw_exception(error_wrong_state);
856
//
857
// }
858
//
859
// return (const PAYLOAD &) pnode->payload();
860
//
861
// }
862
//
863
//
864
// template < typename PAIR >
865
// inline ::collection::count pair_map_base < PAIR >::key_count(ARG_KEY key) const
866
// {
867
//
868
// return this->find(key) ? 1 : 0;
869
//
870
// }
871
//
872
//
873
// template < typename PAIR >
874
// bool pair_map_base < PAIR >::has_key(ARG_KEY key) const
875
// {
876
//
877
// return this->find(key) ? 1 : 0;
878
//
879
// }
880
//
881
//
882
// template < typename PAIR >
883
// bool pair_map_base < PAIR >::contains_key(ARG_KEY key) const
884
// {
885
//
886
// return this->find(key) ? 1 : 0;
887
//
888
// }
889
//
890
891
//template < typename PAIR >
892
//void pair_map_base < PAIR >::get_next(iterator & iterator,
893
// ITEM& rKey, PAYLOAD& rValue) const
894
//{
895
//
896
// rKey = iterator->element1();
897
//
898
// rValue = iterator->element2();
899
//
900
// iterator = iterator->m_next;
901
//
902
//}
903
//
904
//
905
//template < typename PAIR >
906
//inline const typename pair_map_base < PAIR >::iterator
907
//pair_map_base < PAIR >::get_next(const iterator iterator) const
908
//{
909
//
910
// return iterator->m_next;
911
//
912
//}
913
914
//
915
//template < typename PAIR >
916
//inline typename pair_map_base < PAIR >::iterator
917
//pair_map_base < PAIR >::get_next(const iterator iterator)
918
//{
919
//
920
// return iterator->m_next;
921
//
922
//}
923
//
924
//
925
// template < typename PAIR >
926
// typename pair_map_base < PAIR >::PAYLOAD pair_map_base < PAIR > ::
927
// get(ARG_KEY argkey, ARG_PAYLOAD valueDefault)
928
// {
929
//
930
// auto p = find(argkey);
931
//
932
// if(!p)
933
// {
934
//
935
// return valueDefault;
936
//
937
// }
938
//
939
// return p->payload();
940
//
941
// }
942
943
944
//template < typename PAIR >
945
//void pair_map_base < PAIR >::assert_ok() const
946
//{
947
//
948
// ::matter::assert_ok();
949
//
950
// ASSERT(GetHashTableSize() > 0);
951
//
952
// ASSERT(this->m_count == 0 || this->m_hashtable.m_ppHash != nullptr);
953
// // non-empty pair_map_base should have hash table
954
//
955
//}
956
//
957
958
959
template
<
class
PAYLOAD >
960
using
f64_map_base = map_base < ::f64, PAYLOAD >;
961
962
template
<
class
PAYLOAD >
963
using
f64_map = map_particle < f64_map_base < PAYLOAD > >;
964
965
using
f64_to_f64_base = f64_map_base < ::f64 >;
966
967
968
template
<
class
PAYLOAD >
969
using
dword_map = map_base < ::u32, PAYLOAD >;
970
971
972
template
<
class
PAYLOAD >
973
using
uptr_map = map_base < uptr, PAYLOAD >;
974
975
976
template
<
typename
ITEM_TYPE,
typename
PAYLOAD_TYPE >
977
class
key_payload
978
{
979
public
:
980
981
982
using
ITEM = ITEM_TYPE;
983
using
PAYLOAD = PAYLOAD_TYPE;
984
using
TYPE1 = ITEM;
985
using
TYPE2 = PAYLOAD;
986
using
ARG_TYPE1 = argument_of < TYPE1 >;
987
using
ARG_TYPE2 = argument_of < TYPE2 >;
988
989
990
// Contract
991
// ITEM & element1();
992
// PAYLOAD & element2();
993
// ARG_KEY element1() const;
994
// const PAYLOAD & element2() const;
995
996
};
997
998
999
//template < typename PAIR >
1000
//using pair_pair_map = pair_map_base < typename PAIR::TYPE1, typename PAIR::TYPE2 >;
1001
1002
1003
#define __declare_key_value(xkeyvaluetype, xkeytype, xkey, xvaluetype, xvalue) \
1004
struct xkeyvaluetype : public ::key_payload < xkeytype, xvaluetype > \
1005
{ \
1006
\
1007
PAIR_DEFAULT_IMPL(xkeyvaluetype, ITEM, PAYLOAD, const ITEM &, const PAYLOAD &, xkey, xvalue); \
1008
}
1009
1010
1011
#ifdef CPP17
1012
#define __declare_pair_tuple_size(pair) \
1013
template<> ALIENATED_ANDROID_ANARCHY ::std::tuple_size< pair > : ::std::integral_constant<size_t, 2> {} }
1014
#endif
1015
1016
1017
#define __declare_pair_map(xpair_maptype, xkeyvaluetype, xkeytype, xkey, xvaluetype, xvalue) \
1018
__declare_key_value(xkeyvaluetype, xkeytype, xkey, xvaluetype, xvalue); \
1019
using xpair_maptype = pair_pair_map < xkeyvaluetype >
1020
1021
1022
#ifdef CPP17
1023
#define __declare_pair_map_key_value(xpair_maptype, xkeyvaluetype, xkeytype, xkey, xvaluetype, xvalue) \
1024
__declare_pair_map(xkeyvaluetype, xkeytype, xkey, xvaluetype, xvalue); \
1025
__declare_pair_tuple_size(xpair_maptype)
1026
#else
1027
1028
#define __declare_pair_map_key_value(xpair_maptype, xkeyvaluetype, xkeytype, xkey, xvaluetype, xvalue) \
1029
__declare_pair_map(xkeyvaluetype, xkeytype, xkey, xvaluetype, xvalue);
1030
1031
#endif
1032
1033
//
1034
//
1035
// template < typename PAIR >
1036
// void pair_map_base < PAIR >::InitHashTable(
1037
// ::u32 nHashSize, bool bAllocNow)
1038
// //
1039
// // Used to force allocation of a hash table or to override the default
1040
// // hash table i32_size of (which is fairly small)
1041
// {
1042
//
1043
// //ASSERT_OK(this);
1044
// ASSERT(this->m_count == 0);
1045
// ASSERT(nHashSize > 0);
1046
//
1047
// this->m_hashtable.InitHashTable(nHashSize,bAllocNow);
1048
//
1049
// }
1050
//
1051
1052
//template < typename PAIR >
1053
//void pair_map_base < PAIR >::dump(dump_context& dumpcontext) const
1054
//{
1055
//
1056
// ::matter::dump(dumpcontext);
1057
//
1058
// //dumpcontext << "with " << this->m_count << " elements";
1059
// //if (dumpcontext.GetDepth() > 0)
1060
// //{
1061
// // // Dump in format "[key] -> value"
1062
//
1063
// // const iterator iterator = get_start();
1064
// // while (iterator != nullptr)
1065
// // {
1066
// // iterator = get_next(iterator);
1067
// // dumpcontext << "\n\t[";
1068
// // dump_elements<ITEM>(dumpcontext, &iterator->element1(), 1);
1069
// // dumpcontext << "] = ";
1070
// // dump_elements<PAYLOAD>(dumpcontext, &iterator->element2(), 1);
1071
// // }
1072
// //}
1073
//
1074
// //dumpcontext << "\n";
1075
//}
1076
//
1077
//
1078
1079
1080
template
<
typename
MAP_BASE>
1081
class
map_particle
:
1082
virtual
public
::particle,
1083
public
MAP_BASE
1084
{
1085
public
:
1086
1087
1088
using
BASE_MAP = MAP_BASE;
1089
1090
1091
using
BASE_MAP::BASE_MAP;
1092
using
BASE_MAP::operator =;
1093
1094
1095
};
1096
1097
1098
key_payload
Definition
map.h:978
map_particle
Definition
map.h:1084
pair_map_base
Definition
map.h:11
prototype
collection
map.h
Generated by
1.17.0