Class: Digest::XXHash
- Defined in:
- ext/digest/xxhash/ext.c,
lib/digest/xxhash/version.rb,
ext/digest/xxhash/ext.c
Overview
This is the base class of Digest::XXH32, Digest::XXH64, Digest::XXH3_64bits, and Digest::XXH3_128bits.
Direct Known Subclasses
Constant Summary collapse
- VERSION =
"0.2.3"
- XXH3_SECRET_SIZE_MIN =
:XXHash doesn’t know if this value would change in the future.
Minimum allowed custom secret size defined in the core XXHash code. The current value is 136. The author of Digest
Class Method Summary collapse
-
.Digest::XXHash::digest(str, seed = 0) ⇒ String
Returns the digest value of
str
in string form withseed
as its seed. -
.Digest::XXHash::hexdigest ⇒ Object
Same as ::digest but returns the digest value in hex form.
-
.Digest::XXHash::idigest ⇒ Numeric
Same as ::digest but returns the digest value in numerical form.
Instance Method Summary collapse
-
#digest(*args) ⇒ Object
Returns digest value in string form.
-
#hexdigest(*args) ⇒ Object
Same as #digest but returns the digest value in hex form.
-
#idigest(*args) ⇒ Object
Same as #digest but returns the digest value in numerical form.
-
#idigest! ⇒ Object
Returns current digest value and resets state to default form.
-
#initialize(*args) ⇒ Object
constructor
Returns a new hash instance.
-
#initialize_copy(orig) ⇒ self
This method is called when instances are cloned.
-
#inspect ⇒ String
Returns a string in the form of
#<class_name|hex_digest>
.
Constructor Details
#new ⇒ Object #new(seed) ⇒ Object
Returns a new hash instance.
If seed is provided, the state is reset with its value, otherwise the default seed (0) is used.
seed
can be in the form of a string, a hex string, or a number.
220 221 222 223 224 225 226 |
# File 'ext/digest/xxhash/ext.c', line 220
static VALUE _Digest_XXHash_initialize(int argc, VALUE* argv, VALUE self)
{
if (argc > 0)
rb_funcallv(self, _id_reset, argc, argv);
return self;
}
|
Class Method Details
.Digest::XXHash::digest(str, seed = 0) ⇒ String
Returns the digest value of str
in string form with seed
as its seed.
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.
382 383 384 385 |
# File 'ext/digest/xxhash/ext.c', line 382
static VALUE _Digest_XXHash_singleton_digest(int argc, VALUE* argv, VALUE self)
{
return _instantiate_and_digest(argc, argv, self, _id_digest);
}
|
.Digest::XXHash::hexdigest ⇒ Object
Same as ::digest but returns the digest value in hex form.
392 393 394 395 |
# File 'ext/digest/xxhash/ext.c', line 392
static VALUE _Digest_XXHash_singleton_hexdigest(int argc, VALUE* argv, VALUE self)
{
return _instantiate_and_digest(argc, argv, self, _id_hexdigest);
}
|
.Digest::XXHash::idigest ⇒ Numeric
Same as ::digest but returns the digest value in numerical form.
402 403 404 405 |
# File 'ext/digest/xxhash/ext.c', line 402
static VALUE _Digest_XXHash_singleton_idigest(int argc, VALUE* argv, VALUE self)
{
return _instantiate_and_digest(argc, argv, self, _id_idigest);
}
|
Instance Method Details
#digest ⇒ String #digest(str, seed = 0) ⇒ String
Returns digest value in string form.
If no argument is provided, the current digest value is returned, and no reset happens.
If a string argument is provided, the string’s digest value is calculated with seed
, and is used as the return value. The instance’s state is reset to default afterwards.
Providing an argument means that previous initializations done with custom seeds or secrets, and previous calculations done with #update would be discarded, so be careful with its use.
seed
can be in the form of a string, a hex string, or a number.
279 280 281 282 |
# File 'ext/digest/xxhash/ext.c', line 279
static VALUE _Digest_XXHash_digest(int argc, VALUE* argv, VALUE self)
{
return _do_digest(argc, argv, self, _id_finish);
}
|
#hexdigest ⇒ Object #hexdigest(str) ⇒ Object #hexdigest(str, seed) ⇒ Object
Same as #digest but returns the digest value in hex form.
292 293 294 295 |
# File 'ext/digest/xxhash/ext.c', line 292
static VALUE _Digest_XXHash_hexdigest(int argc, VALUE* argv, VALUE self)
{
return _hex_encode_str(_do_digest(argc, argv, self, _id_finish));
}
|
#idigest ⇒ Numeric #idigest(str) ⇒ Numeric #idigest(str, seed) ⇒ Numeric
Same as #digest but returns the digest value in numerical form.
305 306 307 308 |
# File 'ext/digest/xxhash/ext.c', line 305
static VALUE _Digest_XXHash_idigest(int argc, VALUE* argv, VALUE self)
{
return _do_digest(argc, argv, self, _id_ifinish);
}
|
#idigest! ⇒ Object
Returns current digest value and resets state to default form.
315 316 317 318 319 320 321 |
# File 'ext/digest/xxhash/ext.c', line 315
static VALUE _Digest_XXHash_idigest_bang(VALUE self)
{
VALUE result;
result = rb_funcall(self, _id_ifinish, 0);
rb_funcall(self, _id_reset, 0);
return result;
}
|
#initialize_copy(orig) ⇒ self
This method is called when instances are cloned. It is responsible for replicating internal data.
329 330 331 332 |
# File 'ext/digest/xxhash/ext.c', line 329
static VALUE _Digest_XXHash_initialize_copy(VALUE self, VALUE orig)
{
rb_raise(rb_eNotImpError, "initialize_copy method not implemented.");
}
|
#inspect ⇒ String
Returns a string in the form of #<class_name|hex_digest>
.
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'ext/digest/xxhash/ext.c', line 339
static VALUE _Digest_XXHash_inspect(VALUE self)
{
VALUE klass, klass_name, hexdigest, args[2];
klass = rb_obj_class(self);
klass_name = rb_class_name(klass);
if (klass_name == Qnil)
klass_name = rb_inspect(klass);
hexdigest = rb_funcall(self, _id_hexdigest, 0);
args[0] = klass_name;
args[1] = hexdigest;
return rb_str_format(sizeof(args), args, rb_str_new_literal("#<%s|%s>"));
}
|