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)


886
887
888
889
# File 'ext/digest/xxhash/ext.c', line 886

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

.digest_lengthInteger

Returns 8

Returns:

  • (Integer)


876
877
878
879
# File 'ext/digest/xxhash/ext.c', line 876

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)


866
867
868
869
# File 'ext/digest/xxhash/ext.c', line 866

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

#digest_lengthInteger

Returns 8

Returns:

  • (Integer)


856
857
858
859
# File 'ext/digest/xxhash/ext.c', line 856

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)


845
846
847
848
849
# File 'ext/digest/xxhash/ext.c', line 845

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)


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
809
810
811
812
# File 'ext/digest/xxhash/ext.c', line 767

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:
			_xxh3_64bits_reset(_get_state_xxh3_64bits(self), FIX2UINT(seed));
			break;
		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)


823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
# File 'ext/digest/xxhash/ext.c', line 823

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)


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

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;
}