IN2OSM  1.0.1
Hasher< Encoding, Allocator >

#include <schema.h>

Collaboration diagram for Hasher< Encoding, Allocator >:
Collaboration graph

Classes

struct  Number
 

Public Types

typedef Encoding::Ch Ch
 

Public Member Functions

 Hasher (Allocator *allocator=0, size_t stackCapacity=kDefaultSize)
 
bool Null ()
 
bool Bool (bool b)
 
bool Int (int i)
 
bool Uint (unsigned u)
 
bool Int64 (int64_t i)
 
bool Uint64 (uint64_t u)
 
bool Double (double d)
 
bool RawNumber (const Ch *str, SizeType len, bool)
 
bool String (const Ch *str, SizeType len, bool)
 
bool StartObject ()
 
bool Key (const Ch *str, SizeType len, bool copy)
 
bool EndObject (SizeType memberCount)
 
bool StartArray ()
 
bool EndArray (SizeType elementCount)
 
bool IsValid () const
 
uint64_t GetHashCode () const
 

Private Member Functions

bool WriteType (Type type)
 
bool WriteNumber (const Number &n)
 
bool WriteBuffer (Type type, const void *data, size_t len)
 

Static Private Member Functions

static uint64_t Hash (uint64_t h, uint64_t d)
 

Private Attributes

Stack< Allocator > stack_
 

Static Private Attributes

static const size_t kDefaultSize = 256
 

Detailed Description

template<typename Encoding, typename Allocator>
class internal::Hasher< Encoding, Allocator >

Definition at line 220 of file schema.h.

Member Typedef Documentation

◆ Ch

typedef Encoding::Ch Ch

Definition at line 222 of file schema.h.

Constructor & Destructor Documentation

◆ Hasher()

Hasher ( Allocator *  allocator = 0,
size_t  stackCapacity = kDefaultSize 
)
inline

Definition at line 224 of file schema.h.

224 : stack_(allocator, stackCapacity) {}
Stack< Allocator > stack_
Definition: schema.h:309

Member Function Documentation

◆ Bool()

bool Bool ( bool  b)
inline

Definition at line 227 of file schema.h.

227 { return WriteType(b ? kTrueType : kFalseType); }
false
Definition: rapidjson.h:644
true
Definition: rapidjson.h:645
bool WriteType(Type type)
Definition: schema.h:288

◆ Double()

bool Double ( double  d)
inline

Definition at line 232 of file schema.h.

232  {
233  Number n;
234  if (d < 0) n.u.i = static_cast<int64_t>(d);
235  else n.u.u = static_cast<uint64_t>(d);
236  n.d = d;
237  return WriteNumber(n);
238  }
bool WriteNumber(const Number &n)
Definition: schema.h:290
unsigned __int64 uint64_t
Definition: stdint.h:136
signed __int64 int64_t
Definition: stdint.h:135

◆ EndArray()

bool EndArray ( SizeType  elementCount)
inline

Definition at line 262 of file schema.h.

262  {
263  uint64_t h = Hash(0, kArrayType);
264  uint64_t* e = stack_.template Pop<uint64_t>(elementCount);
265  for (SizeType i = 0; i < elementCount; i++)
266  h = Hash(h, e[i]); // Use hash to achieve element order sensitive
267  *stack_.template Push<uint64_t>() = h;
268  return true;
269  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
array
Definition: rapidjson.h:647
static uint64_t Hash(uint64_t h, uint64_t d)
Definition: schema.h:302
unsigned __int64 uint64_t
Definition: stdint.h:136
Stack< Allocator > stack_
Definition: schema.h:309

◆ EndObject()

bool EndObject ( SizeType  memberCount)
inline

Definition at line 252 of file schema.h.

252  {
253  uint64_t h = Hash(0, kObjectType);
254  uint64_t* kv = stack_.template Pop<uint64_t>(memberCount * 2);
255  for (SizeType i = 0; i < memberCount; i++)
256  h ^= Hash(kv[i * 2], kv[i * 2 + 1]); // Use xor to achieve member order insensitive
257  *stack_.template Push<uint64_t>() = h;
258  return true;
259  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
object
Definition: rapidjson.h:646
static uint64_t Hash(uint64_t h, uint64_t d)
Definition: schema.h:302
unsigned __int64 uint64_t
Definition: stdint.h:136
Stack< Allocator > stack_
Definition: schema.h:309

◆ GetHashCode()

uint64_t GetHashCode ( ) const
inline

Definition at line 273 of file schema.h.

273  {
275  return *stack_.template Top<uint64_t>();
276  }
bool IsValid() const
Definition: schema.h:271
Stack< Allocator > stack_
Definition: schema.h:309
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Here is the call graph for this function:

◆ Hash()

static uint64_t Hash ( uint64_t  h,
uint64_t  d 
)
inlinestaticprivate

Definition at line 302 of file schema.h.

302  {
303  static const uint64_t kPrime = RAPIDJSON_UINT64_C2(0x00000100, 0x000001b3);
304  h ^= d;
305  h *= kPrime;
306  return h;
307  }
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:289
unsigned __int64 uint64_t
Definition: stdint.h:136

◆ Int()

bool Int ( int  i)
inline

Definition at line 228 of file schema.h.

228 { Number n; n.u.i = i; n.d = static_cast<double>(i); return WriteNumber(n); }
bool WriteNumber(const Number &n)
Definition: schema.h:290

◆ Int64()

bool Int64 ( int64_t  i)
inline

Definition at line 230 of file schema.h.

230 { Number n; n.u.i = i; n.d = static_cast<double>(i); return WriteNumber(n); }
bool WriteNumber(const Number &n)
Definition: schema.h:290

◆ IsValid()

bool IsValid ( ) const
inline

Definition at line 271 of file schema.h.

271 { return stack_.GetSize() == sizeof(uint64_t); }
unsigned __int64 uint64_t
Definition: stdint.h:136
Stack< Allocator > stack_
Definition: schema.h:309

◆ Key()

bool Key ( const Ch str,
SizeType  len,
bool  copy 
)
inline

Definition at line 251 of file schema.h.

251 { return String(str, len, copy); }
bool String(const Ch *str, SizeType len, bool)
Definition: schema.h:245

◆ Null()

bool Null ( )
inline

Definition at line 226 of file schema.h.

226 { return WriteType(kNullType); }
null
Definition: rapidjson.h:643
bool WriteType(Type type)
Definition: schema.h:288

◆ RawNumber()

bool RawNumber ( const Ch str,
SizeType  len,
bool   
)
inline

Definition at line 240 of file schema.h.

240  {
241  WriteBuffer(kNumberType, str, len * sizeof(Ch));
242  return true;
243  }
bool WriteBuffer(Type type, const void *data, size_t len)
Definition: schema.h:292
number
Definition: rapidjson.h:649
Encoding::Ch Ch
Definition: schema.h:222

◆ StartArray()

bool StartArray ( )
inline

Definition at line 261 of file schema.h.

261 { return true; }

◆ StartObject()

bool StartObject ( )
inline

Definition at line 250 of file schema.h.

250 { return true; }

◆ String()

bool String ( const Ch str,
SizeType  len,
bool   
)
inline

Definition at line 245 of file schema.h.

245  {
246  WriteBuffer(kStringType, str, len * sizeof(Ch));
247  return true;
248  }
string
Definition: rapidjson.h:648
bool WriteBuffer(Type type, const void *data, size_t len)
Definition: schema.h:292
Encoding::Ch Ch
Definition: schema.h:222

◆ Uint()

bool Uint ( unsigned  u)
inline

Definition at line 229 of file schema.h.

229 { Number n; n.u.u = u; n.d = static_cast<double>(u); return WriteNumber(n); }
bool WriteNumber(const Number &n)
Definition: schema.h:290

◆ Uint64()

bool Uint64 ( uint64_t  u)
inline

Definition at line 231 of file schema.h.

231 { Number n; n.u.u = u; n.d = static_cast<double>(u); return WriteNumber(n); }
bool WriteNumber(const Number &n)
Definition: schema.h:290

◆ WriteBuffer()

bool WriteBuffer ( Type  type,
const void *  data,
size_t  len 
)
inlineprivate

Definition at line 292 of file schema.h.

292  {
293  // FNV-1a from http://isthe.com/chongo/tech/comp/fnv/
294  uint64_t h = Hash(RAPIDJSON_UINT64_C2(0x84222325, 0xcbf29ce4), type);
295  const unsigned char* d = static_cast<const unsigned char*>(data);
296  for (size_t i = 0; i < len; i++)
297  h = Hash(h, d[i]);
298  *stack_.template Push<uint64_t>() = h;
299  return true;
300  }
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:289
static uint64_t Hash(uint64_t h, uint64_t d)
Definition: schema.h:302
unsigned __int64 uint64_t
Definition: stdint.h:136
Stack< Allocator > stack_
Definition: schema.h:309

◆ WriteNumber()

bool WriteNumber ( const Number n)
inlineprivate

Definition at line 290 of file schema.h.

290 { return WriteBuffer(kNumberType, &n, sizeof(n)); }
bool WriteBuffer(Type type, const void *data, size_t len)
Definition: schema.h:292
number
Definition: rapidjson.h:649

◆ WriteType()

bool WriteType ( Type  type)
inlineprivate

Definition at line 288 of file schema.h.

288 { return WriteBuffer(type, 0, 0); }
bool WriteBuffer(Type type, const void *data, size_t len)
Definition: schema.h:292

Member Data Documentation

◆ kDefaultSize

const size_t kDefaultSize = 256
staticprivate

Definition at line 279 of file schema.h.

◆ stack_

Stack<Allocator> stack_
private

Definition at line 309 of file schema.h.


The documentation for this class was generated from the following file: