Class: Digest::XXH3_128bits

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

Overview

This class implements XXH3_128bits.

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 16

Returns:

  • (Integer)


1067
1068
1069
1070
# File 'ext/digest/xxhash/ext.c', line 1067

static VALUE _Digest_XXH3_128bits_singleton_block_length(VALUE self)
{
	return INT2FIX(_XXH3_128BITS_BLOCK_SIZE);
}

.digest_lengthInteger

Returns 16

Returns:

  • (Integer)


1057
1058
1059
1060
# File 'ext/digest/xxhash/ext.c', line 1057

static VALUE _Digest_XXH3_128bits_singleton_digest_length(VALUE self)
{
	return INT2FIX(_XXH3_128BITS_DIGEST_SIZE);
}

Instance Method Details

#block_lengthInteger

Returns 16

Returns:

  • (Integer)


1047
1048
1049
1050
# File 'ext/digest/xxhash/ext.c', line 1047

static VALUE _Digest_XXH3_128bits_block_length(VALUE self)
{
	return INT2FIX(_XXH3_128BITS_BLOCK_SIZE);
}

#digest_lengthInteger

Returns 16

Returns:

  • (Integer)


1037
1038
1039
1040
# File 'ext/digest/xxhash/ext.c', line 1037

static VALUE _Digest_XXH3_128bits_digest_length(VALUE self)
{
	return INT2FIX(_XXH3_128BITS_DIGEST_SIZE);
}

#initialize_copy(orig) ⇒ self

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

Returns:

  • (self)


1026
1027
1028
1029
1030
# File 'ext/digest/xxhash/ext.c', line 1026

static VALUE _Digest_XXH3_128bits_initialize_copy(VALUE self, VALUE orig)
{
	XXH3_copyState(_get_state_xxh3_128bits(self), _get_state_xxh3_128bits(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 and not 128-bits.

If seed is not provided, the default value would be 0.

Returns:

  • (self)


950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
# File 'ext/digest/xxhash/ext.c', line 950

static VALUE _Digest_XXH3_128bits_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_128bits_reset(_get_state_xxh3_128bits(self), decoded_seed);
			}

			break;
		case T_FIXNUM:
		case T_BIGNUM:
			_xxh3_128bits_reset(_get_state_xxh3_128bits(self), NUM2ULL(seed));
			break;
		default:
			rb_raise(rb_eArgError, "Invalid argument type for 'seed'.  "
					"Expecting a string or a number.");
		}
	} else {
		_xxh3_128bits_reset(_get_state_xxh3_128bits(self), _XXH3_128BITS_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 having a minimum length of XXH3_SECRET_SIZE_MIN.

Returns:

  • (self)


1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
# File 'ext/digest/xxhash/ext.c', line 1004

static VALUE _Digest_XXH3_128bits_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_128bits_reset_withSecret(_get_state_xxh3_128bits(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)


905
906
907
908
909
910
911
# File 'ext/digest/xxhash/ext.c', line 905

static VALUE _Digest_XXH3_128bits_update(VALUE self, VALUE str)
{
	if (XXH3_128bits_update(_get_state_xxh3_128bits(self), RSTRING_PTR(str), RSTRING_LEN(str)) != XXH_OK)
		rb_raise(rb_eRuntimeError, "Failed to update state.");

	return self;
}