Map is a formidable candidate, good quality, it took many techniques to match or beat him,
Currently, the key is numeric or alpha over 8 characters (extension in progress ).
The data is automatically allocated, accessible by pointer in return of search or iteration functions.
There is no sorted list as such, but a single tree management.
A factor of 10 in iteration was completed, and slightly better in simple find (Get).
See Basic Code, for code of the basic test, See result screen-shot for result
// *********************************************************************** //
// Basics tests ******************* My_Map VS Map ******************* //
// *********************************************************************** //
int main()
{
unsigned long My_Max{ 500000 }, nbrvalueMax{ 100000000 };
MemArr<unsigned long> Data_Key(My_Max); // list of Random Key
MemArr<unsigned long> Ordered_Key(My_Max); // For control
MemArr<unsigned short> Key_Exist(nbrvalueMax + 1);
RandStr Rnds;
map<unsigned long, BuffData*> Data_Map;
MapData<unsigned long, BuffData> Data_My_Map; // *********************** My_Map Vs C++ Map **************************** //
unsigned long long ValR{ 0 };
long double Tm_tick{ 0 }, Tm_tickDataRec{ 0 }, Tm_tickMap{ 0 };
Tick Clktick{ 3 };
BuffData* LpData;
unsigned long* lpDataKey{ Data_Key.GetPtrA() }, * lpOrdered{ Ordered_Key.GetPtrA() };
unsigned short* lpExist{ Key_Exist.GetPtrA() };
// Fill The list with Random ULONG Keys
//
bool iter{ false };
for (unsigned long j = 0; j < 3; j++) {
Data_Map.clear(); Data_My_Map.FreeA();
Data_Key.ClearMem(); Key_Exist.ClearMem();
unsigned long i = 0;
long first{ -1 };
if (!(j % 10000)) cout << j;
cout << endl << " Random List 10 first : ";
while (i < (My_Max)) {
ValR = Rnds.Random(0, nbrvalueMax);
if (!(*(lpExist + ValR))) {
if (first == -1) first = ValR;
*(lpDataKey + i) = ValR;
*(lpExist + ValR) = 1;
if (i < 10) cout << *(lpDataKey + i) << "|";
i++;
}
}
cout << endl << My_Max << " Randomized Key, betwen 0 and " << nbrvalueMax << endl;
// RAW ordered list for next control ***************** //
ValR = 0; cout << endl;
for (i = 0; i < (nbrvalueMax + 1); i++) {
if (*(lpExist + i)) {
*(lpOrdered + ValR) = i; ValR++;
} // cout << i << "|";
}
// Add list in classical Map
Tm_tick = Clktick.Clk();
for (i = 0; i < My_Max; i++) {
ValR = (*(lpDataKey + i));
Data_Map[ValR] = new BuffData{ 0 };
Data_Map[ValR]->ValR = ValR; // Assigned buff value with key value
}
Tm_tickMap = (Clktick.Clk() - Tm_tick);
cout << "Add in classic Map Ticks = " << Tm_tickMap << endl;
// Add list in classical Data_My_Map
Tm_tick = Clktick.Clk();
for (i = 0; i < My_Max; i++) {
ValR = (*(lpDataKey + i));
LpData = Data_My_Map.Add(ValR);
LpData->ValR = ValR; // Assigned buff value with key value
}
Tm_tickMap = (Clktick.Clk() - Tm_tick);
cout << "Add in My Map Ticks = " << Tm_tickMap << " My Nodes : " << Data_My_Map.CountTadr << endl;
// Classic Map find a randomized single existing Key
unsigned long long CountTest = My_Max, err = 0, Countfound = 0, Usefull = 0;
std::map<unsigned long, BuffData*>::iterator it;
Tm_tick = Clktick.Clk();
for (i = 0; i < CountTest; i++) {
ValR = Rnds.Random(0, (My_Max - 1));
Usefull = *(lpDataKey + ValR);
it = Data_Map.find(Usefull);
if (it != Data_Map.end()) {
Countfound++;
ValR = it->second->ValR; if (ValR != Usefull) err++;
}
else err++;
}
Tm_tickMap = (Clktick.Clk() - Tm_tick);
cout << "Find classic Map Ticks = " << Tm_tickMap << " Nbr Found = " << Countfound << " err = " << err << endl;
// My Map Get (find) a randomized single existing Key **********************************
err = 0; Countfound = 0; Usefull = 0;
Tm_tick = Clktick.Clk();
for (i = 0; i < CountTest; i++) {
ValR = Rnds.Random(0, (My_Max - 1));
Usefull = *(lpDataKey + ValR);
LpData = Data_My_Map.Get(Usefull);
if (LpData) {
Countfound++;
ValR = LpData->ValR; if (ValR != Usefull) err++;
}
else err++;
}
Tm_tickMap = (Clktick.Clk() - Tm_tick);
cout << "Get(find) My Map Ticks = " << Tm_tickMap << " Nbr Found = " << Countfound << " err = " << err << endl;
// Iterate classical the non-sorted Map
err = 0; Countfound = 0; Usefull = 0;
it = Data_Map.begin();
Tm_tick = Clktick.Clk();
for (it; it != Data_Map.end(); it++) {
ValR = it->second->ValR;
//cout << ValR << "|" ;
if (ValR != *(lpOrdered + Usefull)) {
err++; cout << ValR << " != " << *(lpOrdered + Usefull) << " Usefull = " << Usefull << endl;
}
Countfound++; Usefull++;
}
Tm_tickMap = (Clktick.Clk() - Tm_tick);
cout << endl;
cout << "Map Sorted Iteration Ticks = " << Tm_tickMap << " Nbr = " << Countfound << " (" << My_Max << ")" << " err = " << err << endl;
// Iterate My_Map the Sorted iterator **********************************
err = 0; Countfound = 0; Usefull = 0;
Data_My_Map.SetPosOrd(0, 1); // Pre - Positionned sequence ***********
Tm_tick = Clktick.Clk();
while (LpData = Data_My_Map.NextOrd()) {
ValR = LpData->ValR;
//
if (ValR != *(lpOrdered + Usefull)) {
err++; cout << ValR << " != " << *(lpOrdered + Usefull) << " Usefull " << Usefull << endl;
}
Countfound++; Usefull++;
};
Tm_tickMap = (Clktick.Clk() - Tm_tick);
cout << "MY Sorted Map Iteration Ticks = " << Tm_tickMap << " Nbr = " << Countfound << " (" << My_Max << ")" << " err = " << err << endl;
// Iterate My_Map the non-sorted iterator **********************************
err = 0; Countfound = 0; Usefull = 0;
Data_My_Map.SetPos(first); // Pre - Positionned sequence ***********
Tm_tick = Clktick.Clk();
while (LpData = Data_My_Map.Next()) {
ValR = LpData->ValR;
// cout << ValR << "|" << *(lpDataKey + Usefull);
if (ValR != *(lpDataKey + Usefull)) err++;
Countfound++; Usefull++;
};
Tm_tickMap = (Clktick.Clk() - Tm_tick);
cout << "MY _ Map Iteration Ticks = " << Tm_tickMap << " Nbr = " << Countfound << " (" << My_Max << ")" << " err = " << err << endl;
Tm_tick = Clktick.Clk();
err = 0; Countfound = 0; Usefull = 0;
for (auto Rit = Data_Map.crbegin(); Rit != Data_Map.crend(); ++Rit) {
ValR = Rit->second->ValR;
//cout << ValR << "|" ;
if (ValR != *(lpOrdered + My_Max - 1 - Usefull)) {
err++; cout << ValR << " != " << *(lpOrdered + My_Max - 1 - Usefull) << " Usefull = " << Usefull << endl;
}
Countfound++; Usefull++;
}
Countfound++; Usefull++;
Tm_tickMap = (Clktick.Clk() - Tm_tick);
cout << "Reverse classic Map Ticks = " << Tm_tickMap << " Nbr = " << Countfound << " (" << My_Max << ")" << " err = " << err << endl;
// Iterate My_Map the Reverse Sorted iterator **********************************
err = 0; Countfound = 0; Usefull = 0;
Data_My_Map.SetPosOrd(nbrvalueMax, 0); // Pre - Positionned sequence ***********
Tm_tick = Clktick.Clk();
while (LpData = Data_My_Map.PreviousOrd()) {
ValR = LpData->ValR;
//cout << ValR << " " << *(lpOrdered + My_Max - 1 - Usefull) << endl;
if (ValR != *(lpOrdered + My_Max - 1 - Usefull)) err++;
Countfound++; Usefull++;
};
Tm_tickMap = (Clktick.Clk() - Tm_tick);
cout << "MY reverse Sorted Ticks = " << Tm_tickMap << " Nbr = " << Countfound << "(" << My_Max << ")" << " err = " << err << endl;
}