Module: MurmurHash3::Native32
- Includes:
- Alias32
- Defined in:
- lib/murmurhash3/native_murmur.rb,
ext/murmurhash3/murmur3.c
Instance Method Summary collapse
-
#murmur3_32_fmix(integer) ⇒ Object
end of MurmurHash3 algorithm.
- #murmur3_32_int32_hash(*args) ⇒ Object
- #murmur3_32_int64_hash(*args) ⇒ Object
- #murmur3_32_str_base64digest(*args) ⇒ Object
- #murmur3_32_str_digest(*args) ⇒ Object
- #murmur3_32_str_hash(*args) ⇒ Object
- #murmur3_32_str_hexdigest(*args) ⇒ Object
Methods included from Alias32
Instance Method Details
#murmur3_32_fmix(integer) ⇒ Object
end of MurmurHash3 algorithm
301 302 303 304 305 306 |
# File 'ext/murmurhash3/murmur3.c', line 301
static VALUE
rb_fmix32(VALUE self, VALUE integer)
{
uint32_t _int = NUM2UINT(integer);
return UINT2NUM(fmix32(_int));
}
|
#murmur3_32_int32_hash(*args) ⇒ Object
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'ext/murmurhash3/murmur3.c', line 412
static VALUE
rb_murmur3_32_int32_hash(int argc, VALUE* argv, VALUE self)
{
uint32_t _int;
uint32_t result;
if (argc == 0 || argc > 2) {
rb_raise(rb_eArgError, "accept 1 or 2 arguments: (int32[, seed])");
}
_int = NUM2UINT(argv[0]);
result = MurmurHash3_x86_32(&_int, 4, argc == 1 ? 0 : NUM2UINT(argv[1]));
return UINT2NUM(result);
}
|
#murmur3_32_int64_hash(*args) ⇒ Object
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'ext/murmurhash3/murmur3.c', line 428
static VALUE
rb_murmur3_32_int64_hash(int argc, VALUE* argv, VALUE self)
{
uint64_t _int;
uint32_t result;
if (argc == 0 || argc > 2) {
rb_raise(rb_eArgError, "accept 1 or 2 arguments: (int64[, seed])");
}
#if SIZEOF_LONG == 8
_int = NUM2ULONG(argv[0]);
#else
_int = NUM2ULL(argv[0]);
#endif
result = MurmurHash3_x86_32(&_int, 8, argc == 1 ? 0 : NUM2UINT(argv[1]));
return UINT2NUM(result);
}
|
#murmur3_32_str_base64digest(*args) ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'ext/murmurhash3/murmur3.c', line 382
static VALUE
rb_murmur3_32_str_base64digest(int argc, VALUE *argv, VALUE self)
{
union {
uint32_t result;
unsigned char res[6];
} r;
char out[8];
int i;
r.result = rb_murmur3_32_hash(argc, argv, self);
#if WORDS_BIGENDIAN
SWAP_32_INT(r.result);
#endif
r.res[4] = 0;
r.res[5] = 0;
for(i = 0; i<2; i++) {
uint32_t b64 =
((uint32_t)r.res[i*3+0] << 16) |
((uint32_t)r.res[i*3+1] << 8) |
(uint32_t)r.res[i*3+2];
out[i*4+0] = base64[(b64 >> 18) & 0x3f];
out[i*4+1] = base64[(b64 >> 12) & 0x3f];
out[i*4+2] = base64[(b64 >> 6) & 0x3f];
out[i*4+3] = base64[(b64 >> 0) & 0x3f];
}
out[6] = '=';
out[7] = '=';
return rb_str_new(out, sizeof(out));
}
|
#murmur3_32_str_digest(*args) ⇒ Object
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'ext/murmurhash3/murmur3.c', line 344
static VALUE
rb_murmur3_32_str_digest(int argc, VALUE* argv, VALUE self)
{
union {
uint32_t result;
char res[4];
} r;
r.result = rb_murmur3_32_hash(argc, argv, self);
#if WORDS_BIGENDIAN
SWAP_32_INT(r.result);
#endif
return rb_str_new(r.res, 4);
}
|
#murmur3_32_str_hash(*args) ⇒ Object
334 335 336 337 338 |
# File 'ext/murmurhash3/murmur3.c', line 334
static VALUE
rb_murmur3_32_str_hash(int argc, VALUE* argv, VALUE self)
{
return UINT2NUM(rb_murmur3_32_hash(argc, argv, self));
}
|
#murmur3_32_str_hexdigest(*args) ⇒ Object
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'ext/murmurhash3/murmur3.c', line 360
static VALUE
rb_murmur3_32_str_hexdigest(int argc, VALUE* argv, VALUE self)
{
union {
uint32_t result;
unsigned char res[4];
} r;
char out[8];
int i;
r.result = rb_murmur3_32_hash(argc, argv, self);
#if WORDS_BIGENDIAN
SWAP_32_INT(r.result);
#endif
for(i = 0; i<4; i++) {
out[i*2] = hex[r.res[i]*2];
out[i*2+1] = hex[r.res[i]*2+1];
}
return rb_str_new(out, 8);
}
|