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

[CR #1837502] remove unnecessary counters v_sizeOfHashMaps and v_numberOfHashMaps



Change-Id: Ie76bd529fafb956fe615167d03e44c7b21c3727d
Signed-off-by: József Gyürüsi's avatarJózsef Gyürüsi <jozsef.gyurusi@ericsson.com>
parent d988097f
...@@ -186,7 +186,7 @@ public: ...@@ -186,7 +186,7 @@ public:
#define ASSERT_VALID_ID(pl_id) \ #define ASSERT_VALID_ID(pl_id) \
\ \
if(pl_id<0){TTCN_error("HashMap Error: pl_id<0");};\ if(pl_id<0){TTCN_error("HashMap Error: pl_id<0");};\
if(pl_id>=v_sizeOfHashMaps){TTCN_error("HashMap Error: pl_id>=v_sizeOfHashMaps");};\ if(pl_id>=(int)v_HashMap.size()){TTCN_error("HashMap Error: pl_id>=v_sizeOfHashMaps");};\
if(v_HashMap[pl_id]==NULL){TTCN_error("HashMap Error: v_HashMap[pl_id]==NULL");};\ if(v_HashMap[pl_id]==NULL){TTCN_error("HashMap Error: v_HashMap[pl_id]==NULL");};\
...@@ -198,15 +198,11 @@ private: ...@@ -198,15 +198,11 @@ private:
typedef HashMapType<T,H,F>* HashMapTypePtr; typedef HashMapType<T,H,F>* HashMapTypePtr;
typedef typename HashMapType<T,H,F>::iterator HashMapTypeIter; typedef typename HashMapType<T,H,F>::iterator HashMapTypeIter;
typedef typename HashMapType<T,H,F>::hasher HashMapTypeHasher; typedef typename HashMapType<T,H,F>::hasher HashMapTypeHasher;
int v_sizeOfHashMaps;
int v_numberOfHashMaps;
NamesHashMapType v_HashNames; NamesHashMapType v_HashNames;
std::vector<HashMapTypePtr> v_HashMap; std::vector<HashMapTypePtr> v_HashMap;
std::stack<int> freeSlotsIn_v_HashMap; std::stack<int> freeSlotsIn_v_HashMap;
public: public:
HashMapTypeCT(){ HashMapTypeCT(){
v_sizeOfHashMaps = 0;
v_numberOfHashMaps = 0;
} }
~HashMapTypeCT(){ ~HashMapTypeCT(){
NamesHashMapType::iterator Hashmap_Iter; NamesHashMapType::iterator Hashmap_Iter;
...@@ -230,22 +226,19 @@ public: ...@@ -230,22 +226,19 @@ public:
v_HashMap[Hashmap_Iter->second] = NULL; v_HashMap[Hashmap_Iter->second] = NULL;
} }
v_HashNames.erase(Hashmap_Iter); v_HashNames.erase(Hashmap_Iter);
v_numberOfHashMaps--;
Hashmap_Iter = v_HashNames.begin(); Hashmap_Iter = v_HashNames.begin();
} }
v_HashMap.clear(); v_HashMap.clear();
v_sizeOfHashMaps = 0;
v_numberOfHashMaps = 0;
} }
inline void assertValid(const INTEGER& pl_id){ inline void assertValid(const INTEGER& pl_id){
if(pl_id<0){TTCN_error("HashMap Error: pl_id<0");}; if(pl_id<0){TTCN_error("HashMap Error: pl_id<0");};
if(pl_id>=v_sizeOfHashMaps){TTCN_error("HashMap Error: pl_id>=v_sizeOfHashMaps");}; if(pl_id>=(int)v_HashMap.size()){TTCN_error("HashMap Error: pl_id>=v_sizeOfHashMaps");};
if(v_HashMap[pl_id]==NULL){TTCN_error("HashMap Error: v_HashMap[pl_id]==NULL");}; if(v_HashMap[pl_id]==NULL){TTCN_error("HashMap Error: v_HashMap[pl_id]==NULL");};
} }
inline bool checkValid(const INTEGER& pl_id){ inline bool checkValid(const INTEGER& pl_id){
if(pl_id<0){return false;}; if(pl_id<0){return false;};
if(pl_id>=v_sizeOfHashMaps){return false;}; if(pl_id>=(int)v_HashMap.size()){return false;};
if(v_HashMap[pl_id]==NULL){return false;}; if(v_HashMap[pl_id]==NULL){return false;};
return true; return true;
} }
...@@ -268,8 +261,7 @@ public: ...@@ -268,8 +261,7 @@ public:
} }
return -1; return -1;
} }
v_numberOfHashMaps++; if(! freeSlotsIn_v_HashMap.empty())
if(v_numberOfHashMaps<v_sizeOfHashMaps)
{ {
int i = freeSlotsIn_v_HashMap.top(); int i = freeSlotsIn_v_HashMap.top();
freeSlotsIn_v_HashMap.pop(); freeSlotsIn_v_HashMap.pop();
...@@ -280,10 +272,11 @@ public: ...@@ -280,10 +272,11 @@ public:
} }
else else
{ {
v_HashNames[pl_name] = v_sizeOfHashMaps; int i = v_HashMap.size();
v_HashNames[pl_name] = i;
v_HashMap.push_back(new HashMapType<T,H,F>); v_HashMap.push_back(new HashMapType<T,H,F>);
v_HashMap[v_sizeOfHashMaps]->initDebug(pl_name); v_HashMap[i]->initDebug(pl_name);
return v_sizeOfHashMaps++; return i;
} }
//never reaches //never reaches
return -1; return -1;
...@@ -348,7 +341,6 @@ public: ...@@ -348,7 +341,6 @@ public:
freeSlotsIn_v_HashMap.push(Hashmap_Iter->second); freeSlotsIn_v_HashMap.push(Hashmap_Iter->second);
} }
v_HashNames.erase(Hashmap_Iter); v_HashNames.erase(Hashmap_Iter);
v_numberOfHashMaps--;
} }
void deleteHashMap( void deleteHashMap(
...@@ -377,7 +369,6 @@ public: ...@@ -377,7 +369,6 @@ public:
v_HashMap[pl_id] = NULL; v_HashMap[pl_id] = NULL;
freeSlotsIn_v_HashMap.push(pl_id); freeSlotsIn_v_HashMap.push(pl_id);
} }
v_numberOfHashMaps--;
} }
void dumpByID (const INTEGER& pl_id) void dumpByID (const INTEGER& pl_id)
......
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