Algorithm-AhoCorasick
view release on metacpan or search on metacpan
lib/Algorithm/AhoCorasick/SearchMachine.pm view on Meta::CPAN
my %keywords;
foreach (@_) {
if (!defined($_) || ($_ eq '')) {
die "empty keyword";
}
$keywords{$_} = 1;
}
my $self = { keywords => [ keys %keywords ] };
bless $self, $class;
$self->_build_tree();
return $self;
}
sub _build_tree {
my $self = shift;
$self->{root} = Algorithm::AhoCorasick::Node->new();
# build transition links
lib/Algorithm/AhoCorasick/SearchMachine.pm view on Meta::CPAN
use warnings;
use Scalar::Util qw(weaken);
sub new {
my $class = shift;
my $self = { @_ };
$self->{results} = { };
$self->{transitions} = { };
weaken $self->{parent} if $self->{parent};
return bless $self, $class;
}
sub char {
my $self = shift;
if (!exists($self->{char})) {
die "root node has no character";
}
return $self->{char};
( run in 1.253 second using v1.01-cache-2.11-cpan-de7293f3b23 )