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
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.
681 682 683 684 |
# File 'ext/digest/xxhash/ext.c', line 681 static VALUE _Digest_XXH64_singleton_block_length(VALUE self) { return INT2FIX(_XXH64_BLOCK_SIZE); } |
.digest_length ⇒ Integer
Returns 8.
671 672 673 674 |
# File 'ext/digest/xxhash/ext.c', line 671 static VALUE _Digest_XXH64_singleton_digest_length(VALUE self) { return INT2FIX(_XXH64_DIGEST_SIZE); } |
Instance Method Details
#block_length ⇒ Integer
Returns 8.
661 662 663 664 |
# File 'ext/digest/xxhash/ext.c', line 661 static VALUE _Digest_XXH64_block_length(VALUE self) { return INT2FIX(_XXH64_BLOCK_SIZE); } |
#digest_length ⇒ Integer
Returns 8.
651 652 653 654 |
# File 'ext/digest/xxhash/ext.c', line 651 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.
640 641 642 643 644 |
# File 'ext/digest/xxhash/ext.c', line 640 static VALUE _Digest_XXH64_initialize_copy(VALUE self, VALUE orig) { XXH64_copyState(_get_state_64(self), _get_state_64(orig)); return self; } |
#reset(seed = 0) ⇒ self
Resets state to initial form with seed.
This would discard previous calculations with #update.
seed can be in the form of a string, a hex string, or a number.
If seed is not provided, the default value would be 0.
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 |
# File 'ext/digest/xxhash/ext.c', line 590 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); uint64_t decoded_seed; if (len == (sizeof(uint64_t) * 2)) { unsigned char hex_decoded_seed[sizeof(uint64_t)]; if (! hex_decode_str_implied(RSTRING_PTR(seed), sizeof(uint64_t) * 2, hex_decoded_seed)) rb_raise(rb_eArgError, "Invalid hex string seed: %s\n", StringValueCStr(seed)); decoded_seed = _decode_big_endian_64_cstr(hex_decoded_seed); } else if (len == sizeof(uint64_t)) { decoded_seed = _decode_big_endian_64_cstr(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_64(self), decoded_seed); } break; case T_FIXNUM: _xxh64_reset(_get_state_64(self), FIX2UINT(seed)); break; case T_BIGNUM: _xxh64_reset(_get_state_64(self), NUM2ULL(seed)); break; default: rb_raise(rb_eArgError, "Invalid argument type for seed. Expecting a string or number."); } } else { _xxh64_reset(_get_state_64(self), _XXH64_DEFAULT_SEED); } return self; } |
#update(str) ⇒ self
Updates current digest value with string.
557 558 559 560 561 562 563 |
# File 'ext/digest/xxhash/ext.c', line 557 static VALUE _Digest_XXH64_update(VALUE self, VALUE str) { if (XXH64_update(_get_state_64(self), RSTRING_PTR(str), RSTRING_LEN(str)) != XXH_OK) rb_raise(rb_eRuntimeError, "Failed to update state."); return self; } |