--- trunk/IsisDB.pm 2005/01/01 22:29:35 27 +++ trunk/IsisDB.pm 2005/01/05 15:46:26 32 @@ -9,7 +9,7 @@ BEGIN { use Exporter (); use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); - $VERSION = 0.08; + $VERSION = 0.09; @ISA = qw (Exporter); #Give a hoot don't pollute, do not export more than needed by default @EXPORT = qw (); @@ -30,7 +30,7 @@ isisdb => './cds/cds', ); - for(my $mfn = 1; $mfn <= $isis->{'maxmfn'}; $mfn++) { + for(my $mfn = 1; $mfn <= $isis->count; $mfn++) { print $isis->to_ascii($mfn),"\n"; } @@ -123,8 +123,6 @@ =back -It will also set C<$isis-E{'maxmfn'}> which is maximum MFN stored in database. - =cut sub new { @@ -199,9 +197,6 @@ read($self->{'fileMST'}, $buff, 4); $self->{'NXTMFN'}=unpack("l",$buff) || carp "NXTNFN is zero"; - # save maximum MFN - $self->{'maxmfn'} = $self->{'NXTMFN'} - 1; - @@ -213,6 +208,19 @@ $self ? return $self : return undef; } +=head2 count + +Return number of records in database + + print $isis->count; + +=cut + +sub count { + my $self = shift; + return $self->{'NXTMFN'} - 1; +} + =head2 read_cnt Read content of C<.CNT> file and return hash containing it. @@ -234,36 +242,6 @@ open(fileCNT, $self->{cnt_file}) || croak "can't read '$self->{cnt_file}': $!"; - # There is two 26 Bytes fixed lenght records - - # 0: IDTYPE BTree type 16 - # 2: ORDN Nodes Order 16 - # 4: ORDF Leafs Order 16 - # 6: N Number of Memory buffers for nodes 16 - # 8: K Number of buffers for first level index 16 - # 10: LIV Current number of Index Levels 16 - # 12: POSRX* Pointer to Root Record in N0x 32 - # 16: NMAXPOS* Next Available position in N0x 32 - # 20: FMAXPOS* Next available position in L0x 32 - # 24: ABNORMAL Formal BTree normality indicator 16 - # length: 26 bytes - - sub unpack_cnt { - my $self = shift; - - my @flds = qw(ORDN ORDF N K LIV POSRX NMAXPOS FMAXPOS ABNORMAL); - - my $buff = shift || return; - my @arr = unpack("ssssssllls", $buff); - - print STDERR "unpack_cnt: ",join(" ",@arr),"\n" if ($self->{'debug'}); - - my $IDTYPE = shift @arr; - foreach (@flds) { - $self->{cnt}->{$IDTYPE}->{$_} = abs(shift @arr); - } - } - my $buff; read(fileCNT, $buff, 26); @@ -277,6 +255,45 @@ return $self->{cnt}; } +=head2 unpack_cnt + +Unpack one of two 26 bytes fixed length record in C<.CNT> file. + +Here is definition of record: + + off key description size + 0: IDTYPE BTree type s + 2: ORDN Nodes Order s + 4: ORDF Leafs Order s + 6: N Number of Memory buffers for nodes s + 8: K Number of buffers for first level index s + 10: LIV Current number of Index Levels s + 12: POSRX Pointer to Root Record in N0x l + 16: NMAXPOS Next Available position in N0x l + 20: FMAXPOS Next available position in L0x l + 24: ABNORMAL Formal BTree normality indicator s + length: 26 bytes + +This will fill C<$self> object under C with hash. It's used by C. + +=cut + +sub unpack_cnt { + my $self = shift; + + my @flds = qw(ORDN ORDF N K LIV POSRX NMAXPOS FMAXPOS ABNORMAL); + + my $buff = shift || return; + my @arr = unpack("ssssssllls", $buff); + + print STDERR "unpack_cnt: ",join(" ",@arr),"\n" if ($self->{'debug'}); + + my $IDTYPE = shift @arr; + foreach (@flds) { + $self->{cnt}->{$IDTYPE}->{$_} = abs(shift @arr); + } +} + =head2 fetch Read record with selected MFN