BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | Properties | List of all members
BrawlLib.Internal.Remapper Class Reference

Public Member Functions

void Remap< T > (IList< T > source, Comparison< T > comp)
 

Properties

int[] ImplementationTable [get]
 
int[] RemapTable [get]
 
int ImplementationLength [get]
 

Member Function Documentation

◆ Remap< T >()

void BrawlLib.Internal.Remapper.Remap< T > ( IList< T >  source,
Comparison< T >  comp 
)
inline
18 {
19 _source = source;
20 int count = source.Count;
21 int tmp;
22 Hashtable cache = new Hashtable();
23
24 _remapTable = new int[count];
25 _impTable = new int[count];
26
27 //Build remap table by assigning first appearance
28 int impIndex = 0;
29 for (int i = 0; i < count; i++)
30 {
31 T t = source[i];
32 if (cache.ContainsKey(t))
33 {
34 _remapTable[i] = (int) cache[t];
35 }
36 else
37 {
38 _impTable[impIndex] = i;
39 cache[t] = _remapTable[i] = impIndex++;
40 }
41 }
42
43 int impCount = impIndex;
44
45 if (comp != null)
46 {
47 //Create new remap table, which is a sorted index list into the imp table
48 int[] sorted = new int[impCount];
49 impIndex = 0;
50 for (int i = 0; i < impCount; i++)
51 {
52 //Get implementation index/object
53 int ind = _impTable[i];
54 T t = source[ind];
55
56 sorted[impIndex] = i; //Set last, just in case we don't find a match
57
58 //Iterate entries in sorted list, comparing them
59 for (int y = 0; y < impIndex; y++)
60 {
61 tmp = sorted[y]; //Pull old value, will use it later
62 if (comp(t, source[_impTable[tmp]]) < 0)
63 {
64 sorted[y] = i;
65
66 //Rotate right
67 for (int z = y; z++ < impIndex;)
68 {
69 ind = sorted[z];
70 sorted[z] = tmp;
71 tmp = ind;
72 }
73
74 break;
75 }
76 }
77
78 impIndex++;
79 }
80
81 //Swap sorted list, creating a new remap table in the process
82 for (int i = 0; i < impCount; i++)
83 {
84 tmp = sorted[i]; //Get index
85 sorted[i] = _impTable[tmp]; //Set sorted entry to imp index
86 _impTable[tmp] = i; //Set imp entry to remap index
87 }
88
89 //Re-index remap
90 for (int i = 0; i < count; i++)
91 {
92 _remapTable[i] = _impTable[_remapTable[i]];
93 }
94
95 //Swap tables
96 _impTable = sorted;
97 }
98 else
99 {
100 Array.Resize(ref _impTable, impCount);
101 }
102 }

Property Documentation

◆ ImplementationLength

int BrawlLib.Internal.Remapper.ImplementationLength
get

◆ ImplementationTable

int [] BrawlLib.Internal.Remapper.ImplementationTable
get

◆ RemapTable

int [] BrawlLib.Internal.Remapper.RemapTable
get

The documentation for this class was generated from the following file: