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 @@ ...@@ -28,6 +28,8 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <stdio.h> #include <stdio.h>
#include <vector>
#include <stack>
#ifdef EPTF_DEBUG #ifdef EPTF_DEBUG
#include "EPTF_CLL_Common_Definitions.hh" #include "EPTF_CLL_Common_Definitions.hh"
...@@ -199,12 +201,12 @@ private: ...@@ -199,12 +201,12 @@ private:
int v_sizeOfHashMaps; int v_sizeOfHashMaps;
int v_numberOfHashMaps; int v_numberOfHashMaps;
NamesHashMapType v_HashNames; NamesHashMapType v_HashNames;
HashMapTypePtr* v_HashMap; std::vector<HashMapTypePtr> v_HashMap;
std::stack<int> freeSlotsIn_v_HashMap;
public: public:
HashMapTypeCT(){ HashMapTypeCT(){
v_sizeOfHashMaps = 0; v_sizeOfHashMaps = 0;
v_numberOfHashMaps = 0; v_numberOfHashMaps = 0;
v_HashMap = NULL;
} }
~HashMapTypeCT(){ ~HashMapTypeCT(){
NamesHashMapType::iterator Hashmap_Iter; NamesHashMapType::iterator Hashmap_Iter;
...@@ -231,7 +233,7 @@ public: ...@@ -231,7 +233,7 @@ public:
v_numberOfHashMaps--; v_numberOfHashMaps--;
Hashmap_Iter = v_HashNames.begin(); Hashmap_Iter = v_HashNames.begin();
} }
v_HashMap = NULL; v_HashMap.clear();
v_sizeOfHashMaps = 0; v_sizeOfHashMaps = 0;
v_numberOfHashMaps = 0; v_numberOfHashMaps = 0;
} }
...@@ -269,31 +271,18 @@ public: ...@@ -269,31 +271,18 @@ public:
v_numberOfHashMaps++; v_numberOfHashMaps++;
if(v_numberOfHashMaps<v_sizeOfHashMaps) if(v_numberOfHashMaps<v_sizeOfHashMaps)
{ {
for(int i=0; i<v_sizeOfHashMaps; i++) { int i = freeSlotsIn_v_HashMap.top();
if (v_HashMap[i]== NULL) freeSlotsIn_v_HashMap.pop();
{ v_HashMap[i]=new HashMapType<T,H,F>;
v_HashMap[i]=new HashMapType<T,H,F>; v_HashMap[i]->initDebug(pl_name);
v_HashMap[i]->initDebug(pl_name); v_HashNames[pl_name] = i;
v_HashNames[pl_name] = i; return i;
return i;
}
}
} }
else else
{ {
v_HashNames[pl_name] = v_sizeOfHashMaps; v_HashNames[pl_name] = v_sizeOfHashMaps;
v_HashMap.push_back(new HashMapType<T,H,F>);
// create a new array for hashMaps with new size (size+1) v_HashMap[v_sizeOfHashMaps]->initDebug(pl_name);
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;
return v_sizeOfHashMaps++; return v_sizeOfHashMaps++;
} }
//never reaches //never reaches
...@@ -356,6 +345,7 @@ public: ...@@ -356,6 +345,7 @@ public:
v_HashMap[Hashmap_Iter->second]->clear(); v_HashMap[Hashmap_Iter->second]->clear();
delete v_HashMap[Hashmap_Iter->second]; delete v_HashMap[Hashmap_Iter->second];
v_HashMap[Hashmap_Iter->second] = NULL; v_HashMap[Hashmap_Iter->second] = NULL;
freeSlotsIn_v_HashMap.push(Hashmap_Iter->second);
} }
v_HashNames.erase(Hashmap_Iter); v_HashNames.erase(Hashmap_Iter);
v_numberOfHashMaps--; v_numberOfHashMaps--;
...@@ -385,6 +375,7 @@ public: ...@@ -385,6 +375,7 @@ public:
v_HashMap[pl_id]->clear(); v_HashMap[pl_id]->clear();
delete v_HashMap[pl_id]; delete v_HashMap[pl_id];
v_HashMap[pl_id] = NULL; v_HashMap[pl_id] = NULL;
freeSlotsIn_v_HashMap.push(pl_id);
} }
v_numberOfHashMaps--; 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