Class: Digest::XXH64
- Defined in:
- ext/digest/xxhash/ext.c,
ext/digest/xxhash/ext.c
Overview
This class implements XXH64.
Constant Summary
Constants inherited from XXHash
Digest::XXHash::VERSION, Digest::XXHash::XXH3_SECRET_SIZE_MIN
Class Method Summary collapse
-
.block_length ⇒ Integer
Returns 8.
-
.digest_length ⇒ Integer
Returns 8.
Instance Method Summary collapse
-
#block_length ⇒ Integer
Returns 8.
-
#digest_length ⇒ Integer
Returns 8.
-
#initialize_copy(orig) ⇒ self
This method is called when instances are cloned.
-
#reset(seed = 0) ⇒ self
Resets state to initial form with seed.
-
#update(str) ⇒ self
Updates current digest value with string.
Methods inherited from XXHash
#digest, digest, #hexdigest, hexdigest, idigest, #idigest, #idigest!, #initialize, #inspect
Constructor Details
This class inherits a constructor from Digest::XXHash
Class Method Details
.block_length ⇒ Integer
Returns 8
706 707 708 709 |
# File 'ext/digest/xxhash/ext.c', line 706
static VALUE _Digest_XXH64_singleton_block_length(VALUE self)
{
return INT2FIX(_XXH64_BLOCK_SIZE);
}
|
.digest_length ⇒ Integer
Returns 8
696 697 698 699 |
# File 'ext/digest/xxhash/ext.c', line 696
static VALUE _Digest_XXH64_singleton_digest_length(VALUE self)
{
return INT2FIX(_XXH64_DIGEST_SIZE);
}
|
Instance Method Details
#block_length ⇒ Integer
Returns 8
686 687 688 689 |
# File 'ext/digest/xxhash/ext.c', line 686
static VALUE _Digest_XXH64_block_length(VALUE self)
{
return INT2FIX(_XXH64_BLOCK_SIZE);
}
|
#digest_length ⇒ Integer
Returns 8
676 677 678 679 |
# File 'ext/digest/xxhash/ext.c', line 676
static VALUE _Digest_XXH64_digest_length(VALUE self)
{
return INT2FIX(_XXH64_DIGEST_SIZE);
}
|
#initialize_copy(orig) ⇒ self
This method is called when instances are cloned. It is responsible for replicating internal data.
665 666 667 668 669 |
# File 'ext/digest/xxhash/ext.c', line 665
static VALUE _Digest_XXH64_initialize_copy(VALUE self, VALUE orig)
{
XXH64_copyState(_get_state_xxh64(self), _get_state_xxh64(orig));
return self;
}
|
#reset(seed = 0) ⇒ self
Resets state to initial form with seed.
This discards previous calculations with #update.
seed
can be in the form of a string, a hex string, or a number. Its virtual length should be 64-bits.
If seed
is not provided, the default value would be 0.
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 |
# File 'ext/digest/xxhash/ext.c', line 614
static VALUE _Digest_XXH64_reset(int argc, VALUE* argv, VALUE self)
{
VALUE seed;
if (rb_scan_args(argc, argv, "01", &seed) > 0) {
switch (TYPE(seed)) {
case T_STRING:
{
int len = RSTRING_LEN(seed);
XXH64_hash_t decoded_seed;
if (len == _TWICE(sizeof(XXH64_hash_t))) {
unsigned char hex_decoded_seed[sizeof(XXH64_hash_t)];
if (! hex_decode_str_implied(_RSTRING_PTR_U(seed), len, hex_decoded_seed))
rb_raise(rb_eArgError, "Invalid hex string seed: %s\n",
StringValueCStr(seed));
decoded_seed = XXH_readBE64(hex_decoded_seed);
} else if (len == sizeof(XXH64_hash_t)) {
decoded_seed = XXH_readBE64(RSTRING_PTR(seed));
} else {
rb_raise(rb_eArgError, "Invalid seed length. "
"Expecting a 16-character hex string or an 8-byte string.");
}
_xxh64_reset(_get_state_xxh64(self), decoded_seed);
}
break;
case T_FIXNUM:
case T_BIGNUM:
_xxh64_reset(_get_state_xxh64(self), NUM2ULL(seed));
break;
default:
rb_raise(rb_eArgError, "Invalid argument type for 'seed'. "
"Expecting a string or a number.");
}
} else {
_xxh64_reset(_get_state_xxh64(self), _XXH64_DEFAULT_SEED);
}
return self;
}
|
#update(str) ⇒ self
Updates current digest value with string.
578 579 580 581 582 583 584 |
# File 'ext/digest/xxhash/ext.c', line 578
static VALUE _Digest_XXH64_update(VALUE self, VALUE str)
{
if (XXH64_update(_get_state_xxh64(self), RSTRING_PTR(str), RSTRING_LEN(str)) != XXH_OK)
rb_raise(rb_eRuntimeError, "Failed to update state.");
return self;
}
|