Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/hashmap into
lp:zorba.
Requested reviews:
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/hashmap/+merge/125187
HashMap optimizations
--
https://code.launchpad.net/~zorba-coders/zorba/hashmap/+merge/125187
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/context/static_context.h'
--- src/context/static_context.h 2012-09-17 00:36:37 +
+++ src/context/static_context.h 2012-09-19 12:44:24 +
@@ -42,6 +42,7 @@
#include zorbautils/hashmap_zstring.h
#include zorbautils/hashmap_itemp.h
+#include zorbautils/checked_vector.h
#include common/shared_types.h
=== modified file 'src/store/naive/qname_pool.cpp'
--- src/store/naive/qname_pool.cpp 2012-09-17 00:36:37 +
+++ src/store/naive/qname_pool.cpp 2012-09-19 12:44:24 +
@@ -63,12 +63,12 @@
/
QNamePool::~QNamePool()
{
- csize n = theHashSet.theHashTab.size();
+ csize n = theHashSet.capacity();
for (csize i = 0; i n; ++i)
{
if (!theHashSet.theHashTab[i].isFree()
-theHashSet.theHashTab[i].theItem-isOverflow())
- delete theHashSet.theHashTab[i].theItem;
+theHashSet.theHashTab[i].key()-isOverflow())
+ delete theHashSet.theHashTab[i].key();
}
if (theCache != NULL)
@@ -297,12 +297,12 @@
bool found;
entry = theHashSet.hashInsert(qn, hval, found);
- entry-theItem = qn;
+ entry-key() = qn;
ZORBA_FATAL(!found, );
}
else
{
- qn = entry-theItem;
+ qn = entry-key();
cachePin(qn);
}
@@ -389,12 +389,12 @@
bool found;
entry = theHashSet.hashInsert(qn, hval, found);
- entry-theItem = qn;
+ entry-key() = qn;
ZORBA_FATAL(!found, );
}
else
{
- qn = entry-theItem;
+ qn = entry-key();
cachePin(qn);
}
@@ -478,7 +478,7 @@
while (entry != NULL)
{
-QNameItem* qn = entry-theItem;
+QNameItem* qn = entry-key();
if (ztd::equals(qn-getLocalName(), ln, lnlen)
ztd::equals(qn-getNamespace(), ns, nslen)
=== modified file 'src/store/naive/string_pool.cpp'
--- src/store/naive/string_pool.cpp 2012-09-17 00:36:37 +
+++ src/store/naive/string_pool.cpp 2012-09-19 12:44:24 +
@@ -28,13 +28,14 @@
StringPool::~StringPool()
{
csize count = 0;
- csize n = theHashTab.size();
+ csize n = capacity();
for (csize i = 0; i n; ++i)
{
-if (theHashTab[i].theItem.is_shared())
+if (!theHashTab[i].isFree() theHashTab[i].key().is_shared())
{
- std::cerr ID: i Referenced URI: theHashTab[i].theItem std::endl;
+ std::cerr ID: i Referenced URI:
+ theHashTab[i].key() std::endl;
//delete theHashTab[i].theString.getp();
count++;
}
@@ -57,7 +58,8 @@
bool found = false;
zstring::size_type len = strlen(str);
- ulong hval = hashfun::h32(str, len, FNV_32_INIT) % theHashTabSize;
+
+ ulong hval = hashfun::h32(str, len, FNV_32_INIT) % bucket_count();
{
SYNC_CODE(AutoMutex lock(theMutex);)
@@ -68,7 +70,7 @@
{
while (entry != NULL)
{
-if (ztd::equals(entry-theItem, str, len))
+if (ztd::equals(entry-key(), str, len))
{
found = true;
break;
@@ -79,7 +81,7 @@
if (found)
{
- outStr = entry-theItem;
+ outStr = entry-key();
return false;
}
}
@@ -97,76 +99,78 @@
/
void StringPool::garbageCollect()
{
- HashEntryzstring, DummyHashValue* entry;
+ HashEntryzstring, DummyHashValue* currEntry;
HashEntryzstring, DummyHashValue* freeList = NULL;
- zstring::size_type size = theHashTabSize;
+ csize size = bucket_count();
- for (ulong i = 0; i size; ++i)
+ for (csize i = 0; i size; ++i)
{
-entry = theHashTab[i];
+currEntry = theHashTab[i];
// If the current hash bucket is empty, move to the next one
-if (entry-isFree())
+if (currEntry-isFree())
{
- ZORBA_FATAL(entry-theNext == 0, );
+ ZORBA_FATAL(currEntry-theNext == 0, );
continue;
}
// Handle the 1st hash entry of the current hash bucket
-while (!entry-theItem.is_shared())
+while (!currEntry-key().is_shared())
{
- if (entry-theNext == 0)
+ if (currEntry-theNext == 0)
{
-entry-setFree();
-theNumEntries--;
+currEntry-setFree();
+--theNumEntries;
break;
}
else
{
-HashEntryzstring, DummyHashValue* nextEntry = entry-getNext();
-*entry = *nextEntry;
-entry-setNext(nextEntry-getNext());
+HashEntryzstring, DummyHashValue* nextEntry = currEntry-getNext();
+assert(!nextEntry-isFree());
+*currEntry = *nextEntry;
+