NAME
Tie::PerfectHash - Minimal Perfect Hash
SYNOPSIS
use Tie::PerfectHash;
== OO Interface ==
@k = qw/heaven earth wind lake thunder mountain fire water/;
$ph = Tie::PerfectHash->new({ KEYSET => \@k,
MAX_KEYLEN => 16,
MAPSIZE => 23});
$ph->store('heaven', 'sign');
$ph->fetch('earth');
== Tie Interface ==
tie %PH, 'Tie::PerfectHash',{ KEYSET => \@k,
MAX_KEYLEN => 16,
MAPSIZE => 23
};
$PH{heaven} = 'sign';
print $PH{earth};
DESCRIPTION
* Tie::PerfectHash implements "Minimal Perfect Hashing Algorithm".
* It improves hash performance under some conditions.
E.g. Accessing a full-text search dictionary
* OO and tie interface are available
* Options for initialization
KEYSET := Reference to an array of keys
MAX_KEYLEN := Maximal length of keys. Default is 128
MAPSIZE := Mapping table size for creating minimal
perfect hash
Default is 1.9 times the size of KEYSET
MAX_CHARWEIGHT := Maximal weight of a character in a key.
It is for generating random hash function.
Default is 64.
* Usage and Public Methods
== OO Interface ==
@k = qw/heaven earth wind lake thunder mountain fire water/;
# Tie::PerfectHash allocates space for the keyset,
# and make it perfect.
$ph = Tie::PerfectHash->new({ KEYSET => \@k,
MAX_KEYLEN => 16,
MAX_CHARWEIGHT => 64,
MAPSIZE => 23,
});
$ph->store('heaven', 'sign'); # assign value to a key
print $ph->fetch('earth'); # get a key's value
print $ph->getkeys(); # returns an array of keyset,
# without duplications
print $ph->getidx('wind'); # get a key's internal serial
== Tie Interface ==
tie %PH, 'Tie::PerfectHash',{
KEYSET => \@k,
MAX_KEYLEN => 16,
MAX_CHARWEIGHT => 64,
MAPSIZE => 23,
};
# then you can treat it like an ordinary hash,
except its limited vocabulary
$PH{heaven} = 'sign';
print $PH{earth};
print "$_ => $PH{$_}\n" for keys %PH;
%PH = ();
untie %PH;
AUTHOR
xern <xern@cpan.org>
REFERENCE
Ian H. Witten, Alistair Moffat, Timothy C. Bell.
Managing Gigabytes 2nd. ed. : Morgan Kaufman
COPYRIGHT
Copyright 2002 by xern <xern@cpan.org>
This program is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.