Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
AssociationMap.h
Go to the documentation of this file.
1//! @file AssociationMap.h
2//! CAssociationMap provides a compact way of associating a key to several values
3
4#ifndef CASSOCIATIONMAP_CLASS_H
5#define CASSOCIATIONMAP_CLASS_H
6
7#ifdef _MSC_VER
8#pragma once
9#endif // _MSC_VER
10
11#include "Collection.h"
12
13BEGIN_MOOTOOLS_NAMESPACE
14
15///////////////////////////////////////////////////////////////////////////////////////////////////
16//! @class CAssociationCollector
17//! @brief This collector is to used when you know that the collecting process does not involves duplicate pairs in the CAssociationMap.
18//! @details It is quicker to build than CSingleAssociationCollector which verify that the value has not already been inserted.
19//! Once build the collector can be used to build a CAssociationMap which is a very compact way to store the association data
20///////////////////////////////////////////////////////////////////////////////////////////////////
21
22template<class MAPTYPE, class ASSOCTYPE, class SIZETYPE>
24{
26
27public:
28 typedef struct CollectorEntry
29 {
30 MAPTYPE key;
31 ASSOCTYPE assoc;
33
36
37private:
38 int size;
39 CollectorEntry entry;
40 CollectorMap map; // Number of association for a given element
41 CollectorArray items; // Array of association
42
43#ifdef _DEBUG
44 unsigned int assocSizeof; // Verify out of bounds
45#endif
46
47protected:
48 inline void FreeKeys()
49 {
50 map.Free();
51 }
52
53 inline void FreeEntries()
54 {
55 items.RemoveAll();
56 }
57
58 inline int GetSize()
59 {
60 return size;
61 }
62
63 inline CollectorEntry *GetEntry(int i)
64 {
65 return &items[i];
66 }
67
68 inline int GetKeyCount()
69 {
70 return map.GetCount();
71 }
72
73 inline int FindKey(MAPTYPE& key, unsigned int& count)
74 {
75 return map.Find(key, count);
76 }
77
78 inline void RemoveKey(MAPTYPE& key)
79 {
80 map.Remove(key);
81 }
82
83public:
85 {
86 size = 0;
87
88 if (elementNbr == 0)
89 elementNbr = 128;
90
91 map.InitHashTable(elementNbr);
92
95
97
98#ifdef _DEBUG
99 assocSizeof = (unsigned int)((((longint)1) << (sizeof(SIZETYPE)*8))-1);
100#endif
101 }
102
103 void Add(const MAPTYPE& key, const ASSOCTYPE& assoc)
104 {
105 unsigned int *count = map.Find(key);
106 if (count)
107 {
108 (*count)++;
109 #ifdef _DEBUG
110 XASSERT(*count <= assocSizeof);
111 #endif
112 }
113 else
114 map.Insert(key, 1);
115
116 entry.key = key;
117 entry.assoc = assoc;
118 items.SetAtGrow(size++, entry);
119 }
120
121 void Add(const CollectorEntry& entry) // Faster adding
122 {
123 unsigned int *count = map.Find(entry.key);
124 if (count)
125 {
126 (*count)++;
127#ifdef _DEBUG
128 XASSERT(*count <= assocSizeof);
129#endif
130 }
131 else
132 map.Insert(entry.key, 1);
133
134
135 items.SetAtGrow(size++, entry);
136 }
137};
138
139///////////////////////////////////////////////////////////////////////////////////////////////////
140//! @class CSingleAssociationCollector
141//! @brief CSingleAssociationCollector this collector ensures to collect single pairs in the association map.
142//! @details It requires a HashMethod to be defined:
143//!
144//! @code{.cpp}
145//! template <> class CHashMethods<CSingleAssociationCollector::CollectorEntry>
146//! {
147//! public:
148//! static unsigned int HashValue(const CSingleAssociationCollector::CollectorEntry& info)
149//! static bool HashCompare(const CSingleAssociationCollector::CollectorEntry& info1, const CSingleAssociationCollector::CollectorEntry& info2)
150//! };
151//! @endcode
152//!
153//! Once build the collector can be used to build a CAssociationMap which is a very compact way to store the association data
154///////////////////////////////////////////////////////////////////////////////////////////////////
155
156template<class MAPTYPE, class ASSOCTYPE> struct SingleCollectorEntry
157{
158 MAPTYPE key;
159 ASSOCTYPE assoc;
160};
161
162template<class MAPTYPE, class ASSOCTYPE, class SIZETYPE>
164{
166
167public:
168 typedef SingleCollectorEntry<MAPTYPE, ASSOCTYPE> CollectorEntry; // This typedef is a simple way to provide HashFunctions Ie. CHashMethods<CAssociationMap::Collector::CollectorEntry>
169
170private:
174
175
176 CollectorHashEntry entries; // Number of association for a given element
177 CollectorKeyCount valuesCounts; // Number of single values for each key
178
179protected:
180 inline void FreeKeys()
181 {
182 valuesCounts.Free();
183 }
184
185 inline int GetKeyCount()
186 {
187 return valuesCounts.GetCount();
188 }
189
190 inline int FindKey(const MAPTYPE& key, unsigned int& count)
191 {
192 return valuesCounts.Find(key, count);
193 }
194
195 inline CollectorEntry *GetNextEntry(HashPos& pos)
196 {
197 return entries.GetNextPtr(pos);
198 }
199
200 inline HashPos GetFirstEntry()
201 {
202 return entries.GetFirst();
203 }
204
205 inline void FreeEntries()
206 {
207 entries.Free();
208 }
209
210public:
212 {
213 if (elementNbr == 0)
214 elementNbr = 128;
215
216 entries.InitHashTable(elementNbr);
217 valuesCounts.InitHashTable(elementNbr);
218 }
219
220 void Add(const CollectorEntry& entry) // Faster adding
221 {
222 if (entries.Insert(entry) == false) // Already added
223 return;
224
225 unsigned int *count = valuesCounts.Find(entry.key);
226 if (count)
227 (*count)++; // Contains the different values count
228 else
229 valuesCounts.Insert(entry.key, 1);
230 }
231};
232
233///////////////////////////////////////////////////////////////////////////////////////////////////
234//! @class CAssociationMap
235//! @brief This class handles an association between a key and its associated values.
236//! @details It must be build using an CAssociationCollector class.
237//! In then stores the association in a very compact way compare to CHashAssocMap
238template<class MAPTYPE, class ASSOCTYPE, class SIZETYPE, template<typename T1, typename T2> class COLLTYPE> // COLLTYPE = CSimpleCollection by default
240{
241protected:
244#ifdef _DEBUG
245 bool checkDuplicate;
246#endif
247
248public:
250 typedef SingleCollectorEntry<MAPTYPE, ASSOCTYPE> CollectorEntry; // This typedef is a simple way to provide HashFunctions Ie. CHashMethods<CAssociationMap::Collector::CollectorEntry>
251
253 {
254 #ifdef _DEBUG
255 checkDuplicate = true;
256 #endif
257 }
258
259 // Defines an estimate number of entries and the estimated number of element per entry
260 void SetSize(unsigned int entries, unsigned int elementPerEntries)
261 {
262 map.Clear();
263 map.InitHashTable(entries);
264 assocs.PreAllocate(entries, entries*elementPerEntries);
265 }
266
267 //! Giving a key return an array with the associates data and the number of element in that array.
268 ASSOCTYPE *Lookup(const MAPTYPE& entry, int& size) const
269 {
270 unsigned int index;
271 if (map.Find(entry, index))
272 return assocs.GetEntry(index, size);
273
274 size = 0;
275 return NULL;
276 }
277
278 //! Returns true if a key is found in the association map
279 bool IsFound(const MAPTYPE& entry) const
280 {
281 return (map.IsFound(entry) != 0);
282 }
283
284 //! Remove a key and its association from the map
285 void Remove(const MAPTYPE& entry)
286 {
287 unsigned int index;
288 if (map.Find(entry, index))
289 {
290 assocs.SetEntrySize(index, 0);
291 }
292 }
293
294
295 //! @brief Move a from association key to a destination key and associates the from values to the destination key
296 //! @note Destination association are lost and replaced by from association values
297 bool MoveTo(const MAPTYPE& from, const MAPTYPE& to)
298 {
299 unsigned int index;
300 if (!map.Find(from, index))
301 return false;
302
303 map.Remove(from);
304 map.Insert(to, index);
305
306 return true;
307 }
308
309#ifdef _DEBUG
310 // Look if entry is already associated to assoc
311 bool CheckDuplicates() const
312 {
313 if (!checkDuplicate)
314 return false;
315
316 // Check redundancy
318
319 MAPTYPE entry;
320 HashPos pos = map.GetFirst();
321 unsigned int index;
322 int i, size;
323 int count = 0;
324 while (pos != HashEnd)
325 {
326 map.GetNext(pos, entry, index);
327
328 ASSOCTYPE *assoc = assocs.GetEntry(index, size);
329 if (size == 1)
330 continue;
331 else if (size == 2)
332 {
333 if (CHashMethods<ASSOCTYPE>::HashCompare(assoc[0],assoc[1]))
334 {
335 count++;
336 continue;
337 }
338
339 continue;
340 }
341
342 for (i=0; i<size; i++)
343 {
344 if (duplicateHash.IsFound(assoc[i]))
345 {
346 count++;
347 continue;
348 }
349
350 duplicateHash.Insert(assoc[i]);
351 }
352
353 if (size > 1024)
354 duplicateHash.Free(); // If one key has a lot of values, this could be better to free, because next clear will have to reset the hash for many values
355 else
356 duplicateHash.Clear();
357 }
358
359 if (count > 0)
360 XTRACE(_T("CAssociationMap: WARNING %d duplicated entry has been found in the map.\nCSingleAssociationCollector should be used instead CAssociationCollector.\n"), count);
361
362 return (count > 0);
363 }
364#endif
365
366#if 0
367 bool CleanDuplicates()
368 {
370 bool duplicate = false;
371 MAPTYPE entry;
372 HashPos pos = map.GetFirst();
373 unsigned int index;
374 int i, size;
375 while (pos != HashEnd)
376 {
377 map.GetNext(pos, entry, index);
378
379 ASSOCTYPE *assoc = assocs.GetEntry(index, size);
380 if (size <= 1)
381 continue;
382 else if (size == 2)
383 {
384 if (assoc[0] == assoc[1])
385 {
386 assocs.RemoveElementInEntry(index, 1);
387 duplicate = true;
388 }
389
390 continue;
391 }
392 else if (size == 3)
393 {
394 if (assoc[0] == assoc[1])
395 {
396 assocs.RemoveElementInEntry(index, 1);
397 duplicate = true;
398 }
399 else if (assoc[0] == assoc[2])
400 {
401 assocs.RemoveElementInEntry(index, 2);
402 duplicate = true;
403 }
404 else if (assoc[1] == assoc[2])
405 {
406 assocs.RemoveElementInEntry(index, 2);
407 duplicate = true;
408 }
409
410 continue;
411 }
412
413 // Slower cases
414 // Check redundancy
415 if (duplicateHash == NULL)
417
418 for (i=0; i<size; i++)
419 {
420 if (duplicateHash->IsFound(assoc[i]))
421 {
422 assocs.RemoveElementInEntry(index, i);
423 duplicate = true;
424
425 i--;
426 size--;
427 continue;
428 }
429
430 duplicateHash->Insert(assoc[i]);
431 }
432
433 duplicateHash->Clear();
434 }
435
436 if (duplicateHash)
437 xDelete(duplicateHash);
438
439 return (duplicate);
440 }
441#endif
442
443 //! Associate an element to an entry. This method is slow, and a collector should be prefered.
444 //! Beware: element might have already been associated to entry and the method does not ensure of entry/element unicity
445 //! if unicity is required, and data might have duplicate, CleanDuplicates might be called
446 void AddAssociation(const MAPTYPE& entry, const ASSOCTYPE& element)
447 {
448 unsigned int index;
449 if (!map.Find(entry, index))
450 {
451 index = assocs.AddEntry(FALSE);
452 map.Insert(entry, index);
453 }
454
455 assocs.AddElementInEntry(index, element);
456 }
457
458 //! Remove an association and all its entries. This method is SLOW
459 //! Do not release memory. This can be done calling FreeExtra at the end of the removal process for example
461 {
462 unsigned int refindex;
463 if (!map.Find(refentry, refindex))
464 return false;
465
466 // Implementation note: SetEntrySize(..., 0) lead to have assocs.GetEntriesSize() > map.GetCount(). map.GetSize must be used to get the real size
467 map.Remove(refentry, false);
468 assocs.RemoveEntry(refindex);
469
470 // Update indexes
471 unsigned int *index;
472 HashPos pos = map.GetFirst();
473 while (pos != HashEnd)
474 {
475 map.GetNext(pos, index);
476 if (*index >= refindex)
477 (*index)--;
478 }
479 return true;
480 }
481
482 HashPos GetFirst() const
483 {
484 XASSERT(assocs.GetEntriesSize() == map.GetCount());
485 return map.GetFirst();
486 }
487
488 ASSOCTYPE *GetNext(HashPos& pos, MAPTYPE& entry, int& size) const
489 {
490 XASSERT(pos != HashEnd);
491 unsigned int index;
492 map.GetNext(pos, entry, index);
493 return assocs.GetEntry(index, size);
494 }
495
496 ASSOCTYPE *GetNext(HashPos& pos, MAPTYPE *&entry, int& size) const
497 {
498 XASSERT(pos != HashEnd);
499 unsigned int *index = NULL;
500 map.GetNext(pos, entry, index);
501 return assocs.GetEntry(*index, size);
502 }
503
504 //! return the number of key values in the association map
505 unsigned int GetSize() const
506 {
507 XASSERT(assocs.GetEntriesSize() == map.GetCount());
508 return map.GetCount();
509 }
510
511 bool FreeExtra()
512 {
513 XASSERT(assocs.GetEntriesSize() == map.GetCount());
514 bool compressed = map.Minimize();
515 compressed |= assocs.FreeExtra();
516
517#ifdef _DEBUG
519#endif
520
521 return compressed;
522 }
523
524 void Free()
525 {
526 map.Free();
527 assocs.Free();
528 }
529
531 {
532 *this = refAssociationMap;
533 }
534
536 {
537 map = refAssociationMap.map;
538 assocs.Copy(refAssociationMap.assocs);
539
540 return *this;
541 }
542
543 //! Init the association map from a CAssociationCollector
545 {
546 Free();
547
548 unsigned int keynbr = collector.GetKeyCount();
549 if (!keynbr)
550 return;
551
552 #ifdef _DEBUG
553 checkDuplicate = true; // This collector might generate duplicates
554 #endif
555
556 unsigned int *sizes = xAllocateArray(unsigned int, keynbr);
557 unsigned int count, index = 0;
558
559 // Preallocate the size for each entries
560 // key should be entered in the sizes order (step2)
561 // otherwise preallocation is unuseful
563 int i, size = collector.GetSize();
564 for (i=0; i<size; i++)
565 {
566 entry = collector.GetEntry(i);
567 if (collector.FindKey(entry->key, count))
568 {
569 sizes[index++] = count;
570 collector.RemoveKey(entry->key);
571 }
572 }
573
574 XASSERT(collector.GetKeyCount() == 0 && index == keynbr); // each array key should be in hash table, and each hash table entry should be in array. Otherwise something wrong
575 collector.FreeKeys();
576
577 assocs.SetEntriesSize(keynbr, 0, COL_EMPTY_NEW_ENTRIES|COL_EXACTSIZE_ENTRIES, sizes);
578 xDeallocateArray(sizes);
579
580 map.InitHashTable(keynbr);
581
582 // Step2 : Init the association map.
583 unsigned int entryIndex = 0, entryNbr = 0;
584 for (i=0; i<size; i++)
585 {
586 entry = collector.GetEntry(i);
587 if (!map.Find(entry->key, entryIndex))
588 {
589 entryIndex = entryNbr;
590 map.Insert(entry->key, entryNbr++);
591 }
592
593 assocs.AddElementInEntry(entryIndex, entry->assoc);
594 }
595
596 collector.FreeEntries();
597 MOOTOOLS_PRIVATE_TRACE_IF(FreeExtra(), _T("CAssociationMap::Convert(CAssociationCollector: FreeExtra performs some reallocation. It should not\n"));
598 }
599
600 //! Init the association map from a CSingleAssociationCollector
602 {
603 Free();
604
605 unsigned int keynbr = collector.GetKeyCount();
606 if (!keynbr)
607 return;
608
609 #ifdef _DEBUG
610 checkDuplicate = true; // This collector might generate duplicates
611 #endif
612
613 map.InitHashTable(keynbr);
614
615 unsigned int *sizes = xAllocateArray(unsigned int, keynbr);
616 unsigned int index = 0;
617
618 // Preallocate the size for each entries
619 // key should be entered in the sizes order (step2)
620 // otherwise preallocation is unuseful
621 CollectorEntry *entry;
622 unsigned int entryIndex = 0, entryNbr = 0, count;
623 HashPos pos = collector.GetFirstEntry();
624 while (pos != HashEnd)
625 {
626 entry = collector.GetNextEntry(pos);
627 if (map.Find(entry->key, entryIndex))
628 continue;
629
630 if (collector.FindKey(entry->key, count))
631 {
632 map.Insert(entry->key, entryNbr);
633 sizes[entryNbr++] = count;
634 }
635 }
636
637 XASSERT(entryNbr == keynbr); // each array key should be in hash table, and each hash table entry should be in array. Otherwise something wrong
638 collector.FreeKeys();
639
640 // We have now the exact size
641 assocs.SetEntriesSize(keynbr, 0, COL_EMPTY_NEW_ENTRIES|COL_EXACTSIZE_ENTRIES, sizes);
642
643 xDeallocateArray(sizes);
644
645 // Step2 : Init the association map.
646 pos = collector.GetFirstEntry();
647 while (pos != HashEnd)
648 {
649 entry = collector.GetNextEntry(pos);
650 if (!map.Find(entry->key, entryIndex))
651 {
652 XASSERT(0); // Should not occurs, key have been entered before
653 continue;
654 }
655
656 assocs.AddElementInEntry(entryIndex, entry->assoc);
657 }
658
659 XASSERT(GetSize() == keynbr); // The size should be the same than the one we used
660
661 collector.FreeEntries();
662 MOOTOOLS_PRIVATE_TRACE_IF(FreeExtra(), _T("CAssociationMap::Convert(CSingleAssociationCollector: FreeExtra performs some reallocation. It should not\n"));
663 }
664};
665
666#define GROUPMAP_NOINDEX (-1)
667
668///////////////////////////////////////////////////////////////////////////////////////////////////
669//! @class CGroupMap
670//! @brief This class is useful to gather items together and retrieve the elements gathered.
671//! @details Ie. : for gathering confused points: Group1 [#1 #5 #8 #11] Group2 [#7 #9 #10 #15] Group3 [#16 #17 #18 #20]
672//! Then, giving any element of a group you can retrieve the other elements\n
673//! **Important:** an element can belong to one group only
674template<class MAPTYPE, class SIZETYPE, template<class T1, class T2> class COLLTYPE> // COLLTYPE = CSimpleCollection by default
676{
677private:
680
681public:
682 CGroupMap()
683 {
684 }
685
686 void Free()
687 {
688 indexToGroup.Free();
689 groupAssoc.Free();
690 }
691
692 void FreeExtra()
693 {
694 indexToGroup.Minimize();
695 groupAssoc.FreeExtra();
696 }
697
698 void PreAllocate(unsigned int estimatedGroupNbr, unsigned int estimatedTotalElementNumber)
699 {
700 indexToGroup.InitHashTable(estimatedGroupNbr);
701 groupAssoc.PreAllocate(estimatedGroupNbr, estimatedTotalElementNumber);
702 }
703
704 unsigned int AddGroup(unsigned int newGroupCount = 1) // Return first new group entry index
705 {
706 unsigned int firstgroup = groupAssoc.GetEntriesSize();
707 groupAssoc.SetEntriesSize(firstgroup+newGroupCount, 0, COL_EMPTY_NEW_ENTRIES|COL_KEEP_ENTRIES);
708 return firstgroup;
709 }
710
711 bool RemoveGroup(unsigned int group)
712 {
713 if (group >= groupAssoc.GetEntriesSize())
714 return false;
715
716 int i, size;
717 MAPTYPE *assoc = groupAssoc.GetEntry(group, size);
718 for (i=0; i<size; i++)
719 indexToGroup.Remove(assoc[i]);
720
721 groupAssoc.SetEntrySize(group, 0); // We must keep the same number of entry, otherwise indexToGroup contains bad group indexes
722
723 return true;
724 }
725
726 bool MergeGroup(unsigned int dstgroup, unsigned int srcgroup)
727 {
728 if (dstgroup >= groupAssoc.GetEntriesSize())
729 return false;
730
731 if (srcgroup >= groupAssoc.GetEntriesSize())
732 return false;
733
734 int i, srcsize, dstsize, tmp;
735 groupAssoc.GetEntry(srcgroup, srcsize);
736 groupAssoc.GetEntry(dstgroup, dstsize);
737
738 groupAssoc.SetEntrySize(dstgroup, dstsize+srcsize); // preallocate size before getting entry access, but it could resize the array and make the value being invalid
739
740 MAPTYPE *srcassoc = groupAssoc.GetEntry(srcgroup, srcsize);
741 MAPTYPE *dstassoc = groupAssoc.GetEntry(dstgroup, tmp);
742 for (i=0; i<srcsize; i++)
743 {
744 indexToGroup.Insert(srcassoc[i], dstgroup); // Replace previous value
746 }
747
748 groupAssoc.SetEntrySize(srcgroup, 0); // We must keep the same number of entry, otherwise indexToGroup contains bad group indexes
749
750 return true;
751 }
752
753 unsigned int AddElementInGroup(unsigned int group, MAPTYPE element)
754 {
755 indexToGroup.Insert(element, group);
756 XASSERT(group < groupAssoc.GetEntriesSize());
757 return groupAssoc.AddElementInEntry(group, element);
758 }
759
760 bool RemoveElementByIndexPos(MAPTYPE element, int indexpos) // faster the RemoveElement, if we know indexpos
761 {
762 unsigned int group = GetGroupIndex(element);
763 if (group == GROUPMAP_NOINDEX)
764 return false;
765
766 indexToGroup.Remove(element);
767
768#ifdef _DEBUG
769 int size;
770 MAPTYPE *assoc = groupAssoc.GetEntry(group, size);
771 XASSERT(indexpos < size && assoc[indexpos] == element);
772#endif
773
774 groupAssoc.RemoveElementInEntry(group, indexpos);
775 return true;
776 }
777
778 bool RemoveElement(MAPTYPE element)
779 {
780 unsigned int group = GetGroupIndex(element);
781 if (group == GROUPMAP_NOINDEX)
782 return false;
783
784 indexToGroup.Remove(element);
785
786 int i, size;
787 MAPTYPE *assoc = groupAssoc.GetEntry(group, size);
788 for (i = 0; i<size; i++)
789 {
790 if (assoc[i] == element)
791 {
792 groupAssoc.RemoveElementInEntry(group, i);
793 return true;
794 }
795 }
796
797 XASSERT(0); // Should have been found
798 return false;
799 }
800
801 unsigned int GetGroupCount() const
802 {
803 return groupAssoc.GetEntriesSize();
804 }
805
806 unsigned int GetGroupIndex(MAPTYPE element) const
807 {
808 unsigned int group = GROUPMAP_NOINDEX;
809 indexToGroup.Find(element, group);
810 return group;
811 }
812
813 const MAPTYPE *GetGroup(unsigned int groupIndex, int& size) const
814 {
815 if (groupIndex >= groupAssoc.GetEntriesSize())
816 {
817 size = 0;
818 return NULL;
819 }
820
821 return groupAssoc.GetEntry(groupIndex, size);
822 }
823
824 unsigned int GetGroupSize(unsigned int groupIndex) const
825 {
826 if (groupIndex >= groupAssoc.GetEntriesSize())
827 return 0;
828
829 int size;
830 groupAssoc.GetEntry(groupIndex, size);
831 return size;
832 }
833
834 const CGroupMap& operator=(const CGroupMap &copyFrom)
835 {
836 if (this != &copyFrom)
837 {
838 this->indexToGroup = copyFrom.indexToGroup;
839 this->groupAssoc.Copy(copyFrom.groupAssoc);
840 }
841
842 return *this;
843 }
844};
845
846END_MOOTOOLS_NAMESPACE
847
848#endif // CASSOCIATIONMAP_CLASS_H
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
This collector is to used when you know that the collecting process does not involves duplicate pairs...
Definition AssociationMap.h:24
This class handles an association between a key and its associated values.
Definition AssociationMap.h:240
ASSOCTYPE * Lookup(const MAPTYPE &entry, int &size) const
Giving a key return an array with the associates data and the number of element in that array.
Definition AssociationMap.h:268
void Convert(CSingleAssociationCollector< MAPTYPE, ASSOCTYPE, SIZETYPE > &collector)
Init the association map from a CSingleAssociationCollector.
Definition AssociationMap.h:601
bool MoveTo(const MAPTYPE &from, const MAPTYPE &to)
Move a from association key to a destination key and associates the from values to the destination ke...
Definition AssociationMap.h:297
bool RemoveAssociation(const MAPTYPE &refentry)
Definition AssociationMap.h:460
bool IsFound(const MAPTYPE &entry) const
Returns true if a key is found in the association map.
Definition AssociationMap.h:279
void AddAssociation(const MAPTYPE &entry, const ASSOCTYPE &element)
Definition AssociationMap.h:446
void Convert(CAssociationCollector< MAPTYPE, ASSOCTYPE, SIZETYPE > &collector)
Init the association map from a CAssociationCollector.
Definition AssociationMap.h:544
unsigned int GetSize() const
return the number of key values in the association map
Definition AssociationMap.h:505
void Remove(const MAPTYPE &entry)
Remove a key and its association from the map.
Definition AssociationMap.h:285
This class is useful to gather items together and retrieve the elements gathered.
Definition AssociationMap.h:676
Definition Hash.h:146
CSingleAssociationCollector this collector ensures to collect single pairs in the association map.
Definition AssociationMap.h:164
@ GROW_DEFAULT
A default grow mode which increase the array size by 1024 bytes each times its needed....
Definition XTemplate.h:40
@ GROW_DOUBLE_SIZE
Double size the array for fast element growing (required when the final element number is not known,...
Definition XTemplate.h:42
void SetSize(int newCount, int newGrowCount=GROW_KEEP_MODE)
The buffer always grows unless FreeExtra / RemoveAll(false) is called.
Definition XTemplate.h:249
void RemoveAll(bool keepBuffer=false)
Remove all data and set size to 0.
Definition XTemplate.h:119
Definition AssociationMap.h:29
Definition AssociationMap.h:157