Low commit activity in last 3 years
No release in over a year
Generates Hash 64 and mask bit 63 (0-63) to remove signedness to be compatible with postgres bigints, supports xxHash32 and xxHash64 also
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 13.0
~> 3.0
~> 1.7

Runtime

~> 0.4.0
 Project Readme

DigestGenerator

A simple digest generator which uses xxhash for digest generation.

Installation

Add this line to your application's Gemfile:

gem 'digest_generator', :branch => 'master' 

And then run bundle install in application root directory.

Usage

Supported Algorithm at present is xxHash.

This gem can be used in two ways:

To generate Hash 64 and mask bit 63 (0-63) (to remove signedness to be compatible with postgress bigints) call:

DigestGenerator.digest_63bit(payload)

To generate Hash 64 bit digest

DigestGenerator.digest_64bit(payload)

To generate Hash 32 bit digest

DigestGenerator.digest_32bit(payload)

To use digest as a primary key for a model you need to include DigestGenerator module and define DIGEST_VALID_KEYS as:

include DigestGenerator
self.primary_key = 'digest'
DIGEST_VALID_KEYS = %w[
    name
  ].freeze

Call refresh_digest on an instance of your model to set its digest value.

person = Person.new(name: 'something')
# (Set the supported algorithm. As xxHash is the default algorithm you can skip this step if you want to use xxHash algorithm.)
person.algorithm = 'xxHash'
# (now your digest key is set to 64 bit and mask bit 63 (0-63) value)
person.refresh_digest 

You can also set algorithm by creating a file digest_generator.rb in config/initializers folder with:

DigestGenerator.algorithm = 'xxHash' 

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the DigestGenerator project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.