Safer list traversing in Multiset<> and Map<>

This commit is contained in:
Pavel Kirienko
2015-05-16 22:46:33 +03:00
parent 02fe76cd6f
commit fdf5100985
2 changed files with 24 additions and 10 deletions
+15 -6
View File
@@ -417,8 +417,10 @@ void MapBase<Key, Value>::removeAllWhere(Predicate predicate)
#endif
KVGroup* p = list_.get();
while (p)
while (p != NULL)
{
KVGroup* const next_group = p->getNextListNode();
for (int i = 0; i < KVGroup::NumKV; i++)
{
const KVPair* const kv = p->kvs + i;
@@ -431,7 +433,8 @@ void MapBase<Key, Value>::removeAllWhere(Predicate predicate)
}
}
}
p = p->getNextListNode();
p = next_group;
}
if (num_removed > 0)
@@ -461,8 +464,10 @@ const Key* MapBase<Key, Value>::find(Predicate predicate) const
#endif
KVGroup* p = list_.get();
while (p)
while (p != NULL)
{
KVGroup* const next_group = p->getNextListNode();
for (int i = 0; i < KVGroup::NumKV; i++)
{
const KVPair* const kv = p->kvs + i;
@@ -474,7 +479,8 @@ const Key* MapBase<Key, Value>::find(Predicate predicate) const
}
}
}
p = p->getNextListNode();
p = next_group;
}
return NULL;
}
@@ -505,8 +511,10 @@ typename MapBase<Key, Value>::KVPair* MapBase<Key, Value>::getByIndex(unsigned i
// Slowly crawling through the dynamic storage
KVGroup* p = list_.get();
while (p)
while (p != NULL)
{
KVGroup* const next_group = p->getNextListNode();
for (int i = 0; i < KVGroup::NumKV; i++)
{
KVPair* const kv = p->kvs + i;
@@ -519,7 +527,8 @@ typename MapBase<Key, Value>::KVPair* MapBase<Key, Value>::getByIndex(unsigned i
index--;
}
}
p = p->getNextListNode();
p = next_group;
}
return NULL;
+9 -4
View File
@@ -435,8 +435,10 @@ void Multiset<T, NumStaticEntries>::removeWhere(Predicate predicate, const Remov
#endif
Chunk* p = list_.get();
while (p)
while (p != NULL)
{
Chunk* const next_chunk = p->getNextListNode(); // For the case if the current entry gets modified
if ((num_removed > 0) && (strategy == RemoveOne))
{
break;
@@ -459,7 +461,7 @@ void Multiset<T, NumStaticEntries>::removeWhere(Predicate predicate, const Remov
}
}
p = p->getNextListNode();
p = next_chunk;
}
if (num_removed > 0)
@@ -486,8 +488,10 @@ T* Multiset<T, NumStaticEntries>::find(Predicate predicate)
#endif
Chunk* p = list_.get();
while (p)
while (p != NULL)
{
Chunk* const next_chunk = p->getNextListNode(); // For the case if the current entry gets modified
for (int i = 0; i < Chunk::NumItems; i++)
{
if (p->items[i].isConstructed())
@@ -498,7 +502,8 @@ T* Multiset<T, NumStaticEntries>::find(Predicate predicate)
}
}
}
p = p->getNextListNode();
p = next_chunk;
}
return NULL;
}