Merge lp:~zorba-coders/zorba/objects-with-unordered-maps-and-const-char-star into lp:zorba

Proposed by Ghislain Fourny
Status: Merged
Approved by: Ghislain Fourny
Approved revision: 10996
Merged at revision: 11056
Proposed branch: lp:~zorba-coders/zorba/objects-with-unordered-maps-and-const-char-star
Merge into: lp:zorba
Diff against target: 240 lines (+64/-35)
2 files modified
src/store/naive/json_items.cpp (+32/-27)
src/store/naive/json_items.h (+32/-8)
To merge this branch: bzr merge lp:~zorba-coders/zorba/objects-with-unordered-maps-and-const-char-star
Reviewer Review Type Date Requested Status
Ghislain Fourny Approve
Matthias Brantner Approve
Review via email: mp+124225@code.launchpad.net

Commit message

Changing JSON object implementation to unordered maps.

Description of the change

Changing JSON object implementation to unordered maps.

To post a comment you must log in.
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job objects-with-unordered-maps-and-const-char-star-2012-09-13T15-44-40.281Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Pending.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/objects-with-unordered-maps-and-const-char-star into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:274 (message):
  Validation queue job
  objects-with-unordered-maps-and-const-char-star-2012-09-14T03-39-40.545Z is
  finished. The final status was:

  3 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Ghislain Fourny (gislenius) wrote :

Hi Matthias,

I merged some of my changes back and hope it fixes the failing tests.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job objects-with-unordered-maps-and-const-char-star-2012-09-14T14-36-48.373Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve, 1 Pending.

10996. By Matthias Brantner

merge

Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

I benchmarked the following query in RelWithDebInfo:

for $i in 10 to 200
return {
  variable $o := {|
    for $j in 1 to $i
    return { xs:string($j) : "foo" }
  |};

  for $i in 1 to 20
  return {
    $o(string($i));
    $o(string($i - 5));
    $o(string($i - 8));
  }
}

std::unordered_map (this branch)

Number of executions = 5
Average Execution Time : 192.889 (user: 192.556) milliseconds
Average Total Time : 194.554 (user: 194.217) milliseconds
real 0m1.105s
user 0m1.092s
sys 0m0.008s

HashMap (trunk)

Number of executions = 5
Average Execution Time : 271.695 (user: 271.224) milliseconds
Average Total Time : 273.574 (user: 273.099) milliseconds
real 0m1.501s
user 0m1.484s
sys 0m0.016s

review: Approve
Revision history for this message
Ghislain Fourny (gislenius) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job objects-with-unordered-maps-and-const-char-star-2012-09-24T15-46-14.382Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/store/naive/json_items.cpp'
2--- src/store/naive/json_items.cpp 2012-09-14 15:32:12 +0000
3+++ src/store/naive/json_items.cpp 2012-09-14 16:01:19 +0000
4@@ -292,9 +292,9 @@
5 bool accumulate)
6 {
7 ASSERT_INVARIANT();
8- zstring lName = aName->getStringValue();
9+ const char* lName = aName->getStringValue().c_str();
10
11- Keys::iterator ite = theKeys.find(lName.c_str());
12+ Keys::iterator ite = theKeys.find(lName);
13
14 if (ite == theKeys.end())
15 {
16@@ -308,7 +308,7 @@
17 }
18
19 csize lPosition = thePairs.size();
20- theKeys.insert(lName.c_str(), lPosition);
21+ theKeys.insert(std::make_pair(lName, lPosition));
22 thePairs.push_back(std::make_pair(aName.getp(), lValue));
23 aName->addReference();
24 lValue->addReference();
25@@ -318,7 +318,7 @@
26 }
27 else if (accumulate)
28 {
29- csize lPosition = ite.getValue();
30+ csize lPosition = ite->second;
31
32 assert(thePairs[lPosition].first->getStringValue() == lName);
33
34@@ -359,15 +359,16 @@
35 {
36 ASSERT_INVARIANT();
37
38- zstring lName = aName->getStringValue();
39- csize lPosition = 0;
40+ const char* lName = aName->getStringValue().c_str();
41 store::Item_t lValue;
42
43- if (!theKeys.get(lName.c_str(), lPosition))
44+ Keys::iterator lIter = theKeys.find(lName);
45+ if (lIter == theKeys.end())
46 {
47 ASSERT_INVARIANT();
48 return 0;
49 }
50+ csize lPosition = lIter->second;
51
52 store::Item* lKey;
53
54@@ -385,7 +386,7 @@
55 lValue->removeReference();
56
57 thePairs.erase(thePairs.begin() + lPosition);
58- theKeys.erase(lName.c_str());
59+ theKeys.erase(lIter);
60
61 if (lPosition < thePairs.size())
62 {
63@@ -393,10 +394,10 @@
64 Keys::iterator lKeysEnd = theKeys.end();
65 for (; lKeysIte != lKeysEnd; ++lKeysIte)
66 {
67- csize lPos = lKeysIte.getValue();
68+ csize lPos = lKeysIte->second;
69 if (lPos > lPosition)
70 {
71- lKeysIte.setValue(lPos - 1);
72+ lKeysIte->second = lPos - 1;
73 }
74 }
75 }
76@@ -414,14 +415,15 @@
77 const store::Item_t& aValue)
78 {
79 ASSERT_INVARIANT();
80- zstring lName = aName->getStringValue();
81- csize lPosition = 0;
82+ const char* lName = aName->getStringValue().c_str();
83
84- if (!theKeys.get(lName.c_str(), lPosition))
85+ Keys::const_iterator lIter = theKeys.find(lName);
86+ if (lIter == theKeys.end())
87 {
88 ASSERT_INVARIANT();
89- return NULL;
90+ return 0;
91 }
92+ csize lPosition = lIter->second;
93
94 assert(thePairs[lPosition].first->getStringValue() == lName);
95
96@@ -461,16 +463,17 @@
97 const store::Item_t& aNewName)
98 {
99 ASSERT_INVARIANT();
100- zstring lName = aName->getStringValue();
101- zstring lNewName = aNewName->getStringValue();
102+ const char* lName = aName->getStringValue().c_str();
103+ const char* lNewName = aNewName->getStringValue().c_str();
104
105- if (theKeys.exists(lNewName.c_str()))
106+ Keys::const_iterator lIter = theKeys.find(lNewName);
107+ if (lIter != theKeys.end())
108 {
109 ASSERT_INVARIANT();
110 return false;
111 }
112
113- Keys::iterator ite = theKeys.find(lName.c_str());
114+ Keys::iterator ite = theKeys.find(lName);
115
116 if (ite == theKeys.end())
117 {
118@@ -478,14 +481,14 @@
119 return false;
120 }
121
122- csize lPosition = ite.getValue();
123+ csize lPosition = ite->second;
124 assert(thePairs[lPosition].first->getStringValue() == lName);
125
126 thePairs[lPosition].first->removeReference();
127 aNewName->addReference();
128 thePairs[lPosition].first = aNewName.getp();
129 theKeys.erase(ite);
130- theKeys.insert(lNewName.c_str(), lPosition);
131+ theKeys.insert(std::make_pair(lNewName, lPosition));
132
133 ASSERT_INVARIANT();
134 return true;
135@@ -560,13 +563,15 @@
136 store::Item_t SimpleJSONObject::getObjectValue(const store::Item_t& aKey) const
137 {
138 ASSERT_INVARIANT();
139- zstring lName = aKey->getStringValue();
140-
141- csize lPosition = 0;
142- if (!theKeys.get(lName.c_str(), lPosition))
143+ const char* lName = aKey->getStringValue().c_str();
144+
145+ Keys::const_iterator lIter = theKeys.find(lName);
146+
147+ if (lIter == theKeys.end())
148 {
149 return NULL;
150 }
151+ csize lPosition = lIter->second;
152
153 assert(thePairs[lPosition].first->equals(aKey));
154 return thePairs[lPosition].second;
155@@ -593,15 +598,15 @@
156 JSONItem::assertInvariant();
157 assert(theKeys.size() == thePairs.size());
158
159- for(Keys::iterator lIter = theKeys.begin();
160+ for(Keys::const_iterator lIter = theKeys.begin();
161 lIter != theKeys.end();
162 ++lIter)
163 {
164- csize lPosition = lIter.getValue();
165+ csize lPosition = lIter->second;
166 assert(lPosition < thePairs.size());
167 assert(thePairs[lPosition].first != NULL);
168 assert(thePairs[lPosition].first->isAtomic());
169- assert(thePairs[lPosition].first->getStringValue() == lIter.getKey());
170+ assert(thePairs[lPosition].first->getStringValue() == lIter->first);
171 assert(thePairs[lPosition].second != NULL);
172 }
173 }
174
175=== modified file 'src/store/naive/json_items.h'
176--- src/store/naive/json_items.h 2012-09-14 15:32:12 +0000
177+++ src/store/naive/json_items.h 2012-09-14 16:01:19 +0000
178@@ -17,11 +17,10 @@
179 #ifndef ZORBA_STORE_JSON_ITEMS_H
180 #define ZORBA_STORE_JSON_ITEMS_H
181
182-#include <set>
183 #include <vector>
184
185 #include <zorba/config.h>
186-#include <zorbautils/hashmap_cstring.h>
187+#include "util/unordered_map.h"
188
189 #include "store/api/item_handle.h"
190 #include "store/api/iterator.h"
191@@ -241,8 +240,36 @@
192 class SimpleJSONObject : public JSONObject
193 {
194 protected:
195- CSTRING_HASH_MAP(csize, Keys);
196-
197+ class ConstCharStarHash
198+ {
199+ public:
200+ typedef size_t result_type;
201+ size_t operator()(const char* a) const
202+ {
203+ size_t hash = 5381;
204+ int c;
205+
206+ while ((c = *a++))
207+ hash = ((hash << 5) + hash) + c;
208+
209+ return hash;
210+ }
211+ };
212+
213+ class ConstCharStarComparator
214+ {
215+ public:
216+ bool operator()(const char* a, const char* b) const
217+ {
218+ return strcmp(a, b) == 0;
219+ }
220+ };
221+
222+ typedef std::unordered_map<
223+ const char*,
224+ csize,
225+ ConstCharStarHash,
226+ ConstCharStarComparator> Keys;
227 typedef std::vector<std::pair<store::Item*, store::Item*> > Pairs;
228
229 class KeyIterator : public store::Iterator
230@@ -271,10 +298,7 @@
231
232 public:
233 SimpleJSONObject()
234- :
235- theKeys(64, false)
236- {
237- }
238+ {}
239
240 virtual ~SimpleJSONObject();
241

Subscribers

People subscribed via source and target branches