Merge lp:~paul-lucas/zorba/pjl-misc into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Paul J. Lucas
Approved revision: 11187
Merged at revision: 11386
Proposed branch: lp:~paul-lucas/zorba/pjl-misc
Merge into: lp:zorba
Diff against target: 178 lines (+80/-33)
4 files modified
src/store/naive/json_items.h (+3/-27)
src/util/hash/hash.cpp (+30/-6)
src/util/hash/hash.h (+25/-0)
src/util/stl_util.h (+22/-0)
To merge this branch: bzr merge lp:~paul-lucas/zorba/pjl-misc
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Paul J. Lucas Approve
Review via email: mp+159290@code.launchpad.net

Commit message

Added hash_c_str() and hash<char const*>.

Description of the change

Added hash_c_str() and hash<char const*>.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

Please use the functions for the unordered_map in json_items.h.

review: Needs Fixing
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:~paul-lucas/zorba/pjl-misc into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job pjl-misc-2013-04-18T01-59-51.531Z is finished. The
  final status was:

  Undetermined, probably an error - please email <email address hidden> with the
  number of this job!

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

lp:~paul-lucas/zorba/pjl-misc updated
11187. By Paul J. Lucas

Side merge from bug-1131990 branch since trunk is broken.

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

Validation queue job pjl-misc-2013-04-18T03-02-04.504Z 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
=== modified file 'src/store/naive/json_items.h'
--- src/store/naive/json_items.h 2013-04-04 01:37:05 +0000
+++ src/store/naive/json_items.h 2013-04-18 02:12:27 +0000
@@ -20,6 +20,7 @@
20#include <vector>20#include <vector>
2121
22#include <zorba/config.h>22#include <zorba/config.h>
23#include "util/stl_util.h"
23#include "util/unordered_map.h"24#include "util/unordered_map.h"
2425
25#include "diagnostics/assert.h"26#include "diagnostics/assert.h"
@@ -208,36 +209,11 @@
208class SimpleJSONObject : public JSONObject209class SimpleJSONObject : public JSONObject
209{210{
210protected:211protected:
211 class ConstCharStarHash
212 {
213 public:
214 typedef size_t result_type;
215 size_t operator()(const char* a) const
216 {
217 size_t hash = 5381;
218 int c;
219
220 while ((c = *a++))
221 hash = ((hash << 5) + hash) + c;
222
223 return hash;
224 }
225 };
226
227 class ConstCharStarComparator
228 {
229 public:
230 bool operator()(const char* a, const char* b) const
231 {
232 return strcmp(a, b) == 0;
233 }
234 };
235
236 typedef std::unordered_map<212 typedef std::unordered_map<
237 const char*,213 const char*,
238 csize,214 csize,
239 ConstCharStarHash,215 ztd::hash<char const*>,
240 ConstCharStarComparator> Keys;216 ztd::equal_to<char const*> > Keys;
241217
242 typedef std::vector<std::pair<store::Item*, store::Item*> > Pairs;218 typedef std::vector<std::pair<store::Item*, store::Item*> > Pairs;
243219
244220
=== modified file 'src/util/hash/hash.cpp'
--- src/util/hash/hash.cpp 2013-02-07 17:24:36 +0000
+++ src/util/hash/hash.cpp 2013-04-18 02:12:27 +0000
@@ -31,15 +31,15 @@
31///////////////////////////////////////////////////////////////////////////////31///////////////////////////////////////////////////////////////////////////////
3232
33size_t hash_bytes( void const *p, size_t len, size_t result ) {33size_t hash_bytes( void const *p, size_t len, size_t result ) {
34 unsigned char const *c = reinterpret_cast<unsigned char const*>( p );34 unsigned char const *u = reinterpret_cast<unsigned char const*>( p );
35 unsigned char const *const end = c + len;35 unsigned char const *const end = u + len;
36#ifdef ZORBA_HASH_FN_FNV_1a36#ifdef ZORBA_HASH_FN_FNV_1a
37 //37 //
38 // FNV-1a (Fowler/Noll/Vo) hashing algorithm.38 // FNV-1a (Fowler/Noll/Vo) hashing algorithm.
39 //39 //
40 while ( c < end ) {40 while ( u < end ) {
41 result *= Hash_Prime;41 result *= Hash_Prime;
42 result ^= *c++;42 result ^= *u++;
43 }43 }
44#endif /* ZORBA_HASH_FN_FNV_1a */44#endif /* ZORBA_HASH_FN_FNV_1a */
45#ifdef ZORBA_HASH_FN_PJW45#ifdef ZORBA_HASH_FN_PJW
@@ -61,8 +61,32 @@
61 static size_t const OneEighth = BitsInSizeT / 8;61 static size_t const OneEighth = BitsInSizeT / 8;
62 static size_t const HighBits = ~( (size_t)(~0ul) >> OneEighth );62 static size_t const HighBits = ~( (size_t)(~0ul) >> OneEighth );
6363
64 while ( c < end ) {64 while ( u < end ) {
65 result = (result << OneEighth) + *c++;65 result = (result << OneEighth) + *u++;
66 if ( size_t temp = result & HighBits )
67 result = (result ^ (temp >> ThreeFourths)) & ~HighBits;
68 }
69#endif /* ZORBA_HASH_FN_PJW */
70 return result;
71}
72
73size_t hash_c_str( char const *s, size_t result ) {
74 unsigned char const *u = reinterpret_cast<unsigned char const*>( s );
75#ifdef ZORBA_HASH_FN_FNV_1a
76 while ( *u ) {
77 result *= Hash_Prime;
78 result ^= *u++;
79 }
80#endif /* ZORBA_HASH_FN_FNV_1a */
81#ifdef ZORBA_HASH_FN_PJW
82 static size_t const BitsInSizeT = sizeof( size_t ) *
83 numeric_limits<unsigned char>::digits;
84 static size_t const ThreeFourths = BitsInSizeT * 3 / 4;
85 static size_t const OneEighth = BitsInSizeT / 8;
86 static size_t const HighBits = ~( (size_t)(~0ul) >> OneEighth );
87
88 while ( *u ) {
89 result = (result << OneEighth) + *u++;
66 if ( size_t temp = result & HighBits )90 if ( size_t temp = result & HighBits )
67 result = (result ^ (temp >> ThreeFourths)) & ~HighBits;91 result = (result ^ (temp >> ThreeFourths)) & ~HighBits;
68 }92 }
6993
=== modified file 'src/util/hash/hash.h'
--- src/util/hash/hash.h 2013-02-07 17:24:36 +0000
+++ src/util/hash/hash.h 2013-04-18 02:12:27 +0000
@@ -79,6 +79,31 @@
79 return hash_bytes( &v, sizeof( v ) );79 return hash_bytes( &v, sizeof( v ) );
80}80}
8181
82/**
83 * Generic hash function that hashes a null-terminated C string.
84 *
85 * @param s A pointer to the C string to hash.
86 * @param init The initialization value.
87 * @return Returns the hash code for the given C string.
88 */
89size_t hash_c_str( char const *s, size_t init = Hash_Init );
90
91/**
92 * The generic %hash unary_function class.
93 *
94 * @tparam T The type to hash.
95 */
96template<typename T>
97struct hash : std::unary_function<T,size_t> {
98 size_t operator()( T ) const; // not defined
99};
100
101/** Specialization for <code>char const*</code>. */
102template<> inline
103size_t hash<char const*>::operator()( char const *s ) const {
104 return hash_c_str( s );
105}
106
82} // namespace ztd107} // namespace ztd
83} // namespace zorba108} // namespace zorba
84109
85110
=== modified file 'src/util/stl_util.h'
--- src/util/stl_util.h 2013-03-22 19:06:19 +0000
+++ src/util/stl_util.h 2013-04-18 02:12:27 +0000
@@ -93,6 +93,28 @@
93///////////////////////////////////////////////////////////////////////////////93///////////////////////////////////////////////////////////////////////////////
9494
95/**95/**
96 * Copy of std::equal_to in this namespace so we can specialize it below.
97 */
98template<typename T>
99struct equal_to : std::binary_function<T,T,bool> {
100 bool operator()( T const &a, T const &b ) const {
101 return a == b;
102 }
103};
104
105/**
106 * Specialization of std::equal_to for C strings.
107 */
108template<>
109struct equal_to<char const*> :
110 std::binary_function<char const*,char const*,bool>
111{
112 bool operator()( char const *s1, char const *s2 ) const {
113 return std::strcmp( s1, s2 ) == 0;
114 }
115};
116
117/**
96 * Implementation of SGI's %identity extension.118 * Implementation of SGI's %identity extension.
97 * See: http://www.sgi.com/tech/stl/identity.html119 * See: http://www.sgi.com/tech/stl/identity.html
98 */120 */

Subscribers

People subscribed via source and target branches