1 |
package jsFind; |
package jsFind; |
2 |
|
|
3 |
use 5.008004; |
use 5.005; |
4 |
use strict; |
use strict; |
5 |
use warnings; |
use warnings; |
6 |
use HTML::Entities; |
use HTML::Entities; |
7 |
|
|
8 |
our $VERSION = '0.03'; |
our $VERSION = '0.04'; |
9 |
|
|
10 |
use Exporter 'import'; |
use Exporter 'import'; |
11 |
use Carp; |
use Carp; |
57 |
|
|
58 |
=back |
=back |
59 |
|
|
60 |
|
You can also examine examples which come as tests with this module, |
61 |
|
for example C<t/04words.t>. |
62 |
|
|
63 |
=head1 jsFind methods |
=head1 jsFind methods |
64 |
|
|
65 |
C<jsFind> is mode implementing methods which you, the user, are going to |
C<jsFind> is mode implementing methods which you, the user, are going to |
407 |
use Carp; |
use Carp; |
408 |
use File::Path; |
use File::Path; |
409 |
use Text::Iconv; |
use Text::Iconv; |
410 |
|
use POSIX; |
411 |
|
|
412 |
use base 'jsFind'; |
use base 'jsFind'; |
413 |
|
|
777 |
return $d; |
return $d; |
778 |
} |
} |
779 |
|
|
780 |
|
=head2 base62 |
781 |
|
|
782 |
|
Convert number to base62 (used for jsFind index filenames). |
783 |
|
|
784 |
|
my $n = $tree->base62(50); |
785 |
|
|
786 |
|
=cut |
787 |
|
|
788 |
|
sub base62 { |
789 |
|
my $self = shift; |
790 |
|
|
791 |
|
my $value = shift; |
792 |
|
|
793 |
|
confess("need non-negative number") if (! defined($value) || $value < 0); |
794 |
|
|
795 |
|
my @digits = qw( |
796 |
|
0 1 2 3 4 5 6 7 8 9 |
797 |
|
a b c d e f g h i j k l m n o p q r s t u v w x y z |
798 |
|
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z |
799 |
|
); |
800 |
|
|
801 |
|
my $base = scalar(@digits); |
802 |
|
my $out = ""; |
803 |
|
my $pow = 1; |
804 |
|
my $pos = 0; |
805 |
|
|
806 |
|
|
807 |
|
if($value == 0) { |
808 |
|
return "0"; |
809 |
|
} |
810 |
|
|
811 |
|
while($value > 0) { |
812 |
|
$pos = $value % $base; |
813 |
|
$out = $digits[$pos] . $out; |
814 |
|
$value = floor($value/$base); |
815 |
|
$pow *= $base; |
816 |
|
} |
817 |
|
|
818 |
|
return $out; |
819 |
|
} |
820 |
|
|
821 |
=head2 to_jsfind |
=head2 to_jsfind |
822 |
|
|
823 |
Create jsFind xml files |
Create jsFind xml files |
828 |
|
|
829 |
=cut |
=cut |
830 |
|
|
|
|
|
831 |
sub to_jsfind { |
sub to_jsfind { |
832 |
my $self = shift; |
my $self = shift; |
833 |
my ($path,$file) = @_; |
my ($path,$file) = @_; |
837 |
confess("path is undefined.") unless ($path); |
confess("path is undefined.") unless ($path); |
838 |
confess("file is undefined. Did you call \$t->root->to_jsfind(..) instead of \$t->to_jsfind(..) ?") unless (defined($file)); |
confess("file is undefined. Did you call \$t->root->to_jsfind(..) instead of \$t->to_jsfind(..) ?") unless (defined($file)); |
839 |
|
|
840 |
|
$file = $self->base62($file); |
841 |
|
|
842 |
my $nr_keys = 0; |
my $nr_keys = 0; |
843 |
|
|
844 |
my ($k, $d, $s) = @$self; |
my ($k, $d, $s) = @$self; |
892 |
|
|
893 |
B-Trees in perl web site L<http://perl.plover.com/BTree/> |
B-Trees in perl web site L<http://perl.plover.com/BTree/> |
894 |
|
|
895 |
|
This module web site L<http://www.rot13.org/~dpavlin/jsFind.html> |
896 |
|
|
897 |
=head1 AUTHORS |
=head1 AUTHORS |
898 |
|
|
899 |
Mark-Jonson Dominus E<lt>mjd@pobox.comE<gt> wrote C<BTree.pm> which was |
Mark-Jonson Dominus E<lt>mjd@pobox.comE<gt> wrote C<BTree.pm> which was |