Commit d988097f authored by József Gyürüsi's avatar József Gyürüsi
Browse files

[CR #1837502] use stask and vector to manage hashmap of hashmaps



Change-Id: I0def018786032ac00e5c90e2f317a505a4c34974
Signed-off-by: József Gyürüsi's avatarJózsef Gyürüsi <jozsef.gyurusi@ericsson.com>
parent 921d7025
......@@ -28,6 +28,8 @@
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <stack>
#ifdef EPTF_DEBUG
#include "EPTF_CLL_Common_Definitions.hh"
......@@ -199,12 +201,12 @@ private:
int v_sizeOfHashMaps;
int v_numberOfHashMaps;
NamesHashMapType v_HashNames;
HashMapTypePtr* v_HashMap;
std::vector<HashMapTypePtr> v_HashMap;
std::stack<int> freeSlotsIn_v_HashMap;
public:
HashMapTypeCT(){
v_sizeOfHashMaps = 0;
v_numberOfHashMaps = 0;
v_HashMap = NULL;
}
~HashMapTypeCT(){
NamesHashMapType::iterator Hashmap_Iter;
......@@ -231,7 +233,7 @@ public:
v_numberOfHashMaps--;
Hashmap_Iter = v_HashNames.begin();
}
v_HashMap = NULL;
v_HashMap.clear();
v_sizeOfHashMaps = 0;
v_numberOfHashMaps = 0;
}
......@@ -269,31 +271,18 @@ public:
v_numberOfHashMaps++;
if(v_numberOfHashMaps<v_sizeOfHashMaps)
{
for(int i=0; i<v_sizeOfHashMaps; i++) {
if (v_HashMap[i]== NULL)
{
v_HashMap[i]=new HashMapType<T,H,F>;
v_HashMap[i]->initDebug(pl_name);
v_HashNames[pl_name] = i;
return i;
}
}
int i = freeSlotsIn_v_HashMap.top();
freeSlotsIn_v_HashMap.pop();
v_HashMap[i]=new HashMapType<T,H,F>;
v_HashMap[i]->initDebug(pl_name);
v_HashNames[pl_name] = i;
return i;
}
else
{
v_HashNames[pl_name] = v_sizeOfHashMaps;
// create a new array for hashMaps with new size (size+1)
HashMapTypePtr* v_HashMap_new;
v_HashMap_new = new HashMapTypePtr[v_sizeOfHashMaps+1];
for(int i=0; i<v_sizeOfHashMaps; i++) {
v_HashMap_new[i] = v_HashMap[i];
}
v_HashMap_new[v_sizeOfHashMaps] = new HashMapType<T,H,F>;
v_HashMap_new[v_sizeOfHashMaps]->initDebug(pl_name);
if (v_HashMap!=NULL) delete[] v_HashMap;
v_HashMap = v_HashMap_new;
v_HashMap.push_back(new HashMapType<T,H,F>);
v_HashMap[v_sizeOfHashMaps]->initDebug(pl_name);
return v_sizeOfHashMaps++;
}
//never reaches
......@@ -356,6 +345,7 @@ public:
v_HashMap[Hashmap_Iter->second]->clear();
delete v_HashMap[Hashmap_Iter->second];
v_HashMap[Hashmap_Iter->second] = NULL;
freeSlotsIn_v_HashMap.push(Hashmap_Iter->second);
}
v_HashNames.erase(Hashmap_Iter);
v_numberOfHashMaps--;
......@@ -385,6 +375,7 @@ public:
v_HashMap[pl_id]->clear();
delete v_HashMap[pl_id];
v_HashMap[pl_id] = NULL;
freeSlotsIn_v_HashMap.push(pl_id);
}
v_numberOfHashMaps--;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment