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)


1073
1074
1075
1076
# File 'ext/digest/xxhash/ext.c', line 1073

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

.digest_lengthInteger

Returns 16

Returns:

  • (Integer)


1063
1064
1065
1066
# File 'ext/digest/xxhash/ext.c', line 1063

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)


1053
1054
1055
1056
# File 'ext/digest/xxhash/ext.c', line 1053

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

#digest_lengthInteger

Returns 16

Returns:

  • (Integer)


1043
1044
1045
1046
# File 'ext/digest/xxhash/ext.c', line 1043

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)


1032
1033
1034
1035
1036
# File 'ext/digest/xxhash/ext.c', line 1032

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)


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
994
995
996
997
998
999
# File 'ext/digest/xxhash/ext.c', line 954

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


1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
# File 'ext/digest/xxhash/ext.c', line 1010

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)


909
910
911
912
913
914
915
# File 'ext/digest/xxhash/ext.c', line 909

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