Algorithm-Toy-HashSC
view release on metacpan or search on metacpan
lib/Algorithm/Toy/HashSC.pm view on Meta::CPAN
package Algorithm::Toy::HashSC;
use 5.010;
use strict;
use warnings;
use Carp qw/croak/;
use Moo;
use namespace::clean;
use Scalar::Util qw/looks_like_number/;
our $VERSION = '0.02';
##############################################################################
#
# ATTRIBUTES
# Each list should end up with ~N/M key-value pairs, assuming the input
# is not malicious, and that the hash function is perfect enough. "M"
# here is the modulus, and "N" is the number of key-value pairs added.
lib/Algorithm/Toy/HashSC.pm view on Meta::CPAN
is => 'rw',
default => sub { [] },
);
has modulus => (
is => 'rw',
default => sub { 7 },
coerce => sub {
die 'modulus must be a positive integer > 1'
if !defined $_[0]
or !looks_like_number $_[0]
or $_[0] < 2;
return int $_[0];
},
trigger => sub {
my ($self) = @_;
# clobber extant hash (Moo does not provide old value, so cannot do
# this only when the modulus changes, oh well)
$self->_chain( [] ) unless $self->unsafe;
},
);
( run in 0.645 second using v1.01-cache-2.11-cpan-64827b87656 )