Class: Digest::XXH3_64bits

Inherits:
XXHash show all
Defined in:
ext/digest/xxhash/ext.c,
ext/digest/xxhash/ext.c

Overview

This class implements XXH3_64bits.

Constant Summary

Constants inherited from XXHash

Digest::XXHash::VERSION, Digest::XXHash::XXH3_SECRET_SIZE_MIN

Class Method Summary collapse

Instance Method Summary collapse

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_lengthInteger

Returns 8

Returns:

  • (Integer)


882
883
884
885
# File 'ext/digest/xxhash/ext.c', line 882

static VALUE _Digest_XXH3_64bits_singleton_block_length(VALUE self)
{
	return INT2FIX(_XXH3_64BITS_BLOCK_SIZE);
}

.digest_lengthInteger

Returns 8

Returns:

  • (Integer)


872
873
874
875
# File 'ext/digest/xxhash/ext.c', line 872

static VALUE _Digest_XXH3_64bits_singleton_digest_length(VALUE self)
{
	return INT2FIX(_XXH3_64BITS_DIGEST_SIZE);
}

Instance Method Details

#block_lengthInteger

Returns 8

Returns:

  • (Integer)


862
863
864
865
# File 'ext/digest/xxhash/ext.c', line 862

static VALUE _Digest_XXH3_64bits_block_length(VALUE self)
{
	return INT2FIX(_XXH3_64BITS_BLOCK_SIZE);
}

#digest_lengthInteger

Returns 8

Returns:

  • (Integer)


852
853
854
855
# File 'ext/digest/xxhash/ext.c', line 852

static VALUE _Digest_XXH3_64bits_digest_length(VALUE self)
{
	return INT2FIX(_XXH3_64BITS_DIGEST_SIZE);
}

#initialize_copy(orig) ⇒ self

This method is called when instances are cloned. It is responsible for replicating internal data.

Returns:

  • (self)


841
842
843
844
845
# File 'ext/digest/xxhash/ext.c', line 841

static VALUE _Digest_XXH3_64bits_initialize_copy(VALUE self, VALUE orig)
{
	XXH3_copyState(_get_state_xxh3_64bits(self), _get_state_xxh3_64bits(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.

Returns:

  • (self)


765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
# File 'ext/digest/xxhash/ext.c', line 765

static VALUE _Digest_XXH3_64bits_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.");
				}

				_xxh3_64bits_reset(_get_state_xxh3_64bits(self), decoded_seed);
			}

			break;
		case T_FIXNUM:
		case T_BIGNUM:
			_xxh3_64bits_reset(_get_state_xxh3_64bits(self), NUM2ULL(seed));
			break;
		default:
			rb_raise(rb_eArgError, "Invalid argument type for 'seed'.  "
					"Expecting a string or a number.");
		}
	} else {
		_xxh3_64bits_reset(_get_state_xxh3_64bits(self), _XXH3_64BITS_DEFAULT_SEED);
	}

	return self;
}

#reset_with_secret(secret) ⇒ self

Resets state to initial form using a secret.

This discards previous calculations with #update.

Secret should be a string and have a minimum length of XXH3_SECRET_SIZE_MIN.

Returns:

  • (self)


819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
# File 'ext/digest/xxhash/ext.c', line 819

static VALUE _Digest_XXH3_64bits_reset_with_secret(VALUE self, VALUE secret)
{
	if (TYPE(secret) != T_STRING)
		rb_raise(rb_eArgError, "Argument 'secret' needs to be a string.");

	if (RSTRING_LEN(secret) < XXH3_SECRET_SIZE_MIN)
		rb_raise(rb_eRuntimeError, "Secret needs to be at least %d bytes in length.",
				XXH3_SECRET_SIZE_MIN);

	if (XXH3_64bits_reset_withSecret(_get_state_xxh3_64bits(self), RSTRING_PTR(secret),
			RSTRING_LEN(secret)) != XXH_OK)
		rb_raise(rb_eRuntimeError, "Failed to reset state with secret.");

	return self;
}

#update(str) ⇒ self

Updates current digest value with string.

Returns:

  • (self)


729
730
731
732
733
734
735
# File 'ext/digest/xxhash/ext.c', line 729

static VALUE _Digest_XXH3_64bits_update(VALUE self, VALUE str)
{
	if (XXH3_64bits_update(_get_state_xxh3_64bits(self), RSTRING_PTR(str), RSTRING_LEN(str)) != XXH_OK)
		rb_raise(rb_eRuntimeError, "Failed to update state.");

	return self;
}