/[Biblio-Isis]/trunk/lib/Biblio/Isis.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Biblio/Isis.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 34 by dpavlin, Thu Jan 6 00:40:07 2005 UTC revision 35 by dpavlin, Thu Jan 6 16:27:07 2005 UTC
# Line 221  sub count { Line 221  sub count {
221          return $self->{'NXTMFN'} - 1;          return $self->{'NXTMFN'} - 1;
222  }  }
223    
 =head2 read_cnt  
   
 Read content of C<.CNT> file and return hash containing it.  
   
   print Dumper($isis->read_cnt);  
   
 This function is not used by module (C<.CNT> files are not required for this  
 module to work), but it can be useful to examine your index (while debugging  
 for example).  
   
 =cut  
   
 sub read_cnt  {  
         my $self = shift;  
   
         croak "missing CNT file in ",$self->{isisdb} unless ($self->{cnt_file});  
   
         # Get the index information from $db.CNT  
     
         open(my $fileCNT, $self->{cnt_file}) || croak "can't read '$self->{cnt_file}': $!";  
         binmode($fileCNT);  
   
         my $buff;  
   
         read($fileCNT, $buff, 26) || croak "can't read first table from CNT: $!";  
         $self->unpack_cnt($buff);  
   
         read($fileCNT, $buff, 26) || croak "can't read second table from CNT: $!";  
         $self->unpack_cnt($buff);  
   
         close($fileCNT);  
   
         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<cnt> with hash. It's used by C<read_cnt>.  
   
 =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("vvvvvvVVVv", $buff);  
   
         print STDERR "unpack_cnt: ",join(" ",@arr),"\n" if ($self->{'debug'});  
   
         my $IDTYPE = shift @arr;  
         foreach (@flds) {  
                 $self->{cnt}->{$IDTYPE}->{$_} = abs(shift @arr);  
         }  
 }  
   
224  =head2 fetch  =head2 fetch
225    
226  Read record with selected MFN  Read record with selected MFN
# Line 576  sub tag_name { Line 502  sub tag_name {
502          return $self->{'TagName'}->{$tag} || $tag;          return $self->{'TagName'}->{$tag} || $tag;
503  }  }
504    
505    
506    =head2 read_cnt
507    
508    Read content of C<.CNT> file and return hash containing it.
509    
510      print Dumper($isis->read_cnt);
511    
512    This function is not used by module (C<.CNT> files are not required for this
513    module to work), but it can be useful to examine your index (while debugging
514    for example).
515    
516    =cut
517    
518    sub read_cnt  {
519            my $self = shift;
520    
521            croak "missing CNT file in ",$self->{isisdb} unless ($self->{cnt_file});
522    
523            # Get the index information from $db.CNT
524      
525            open(my $fileCNT, $self->{cnt_file}) || croak "can't read '$self->{cnt_file}': $!";
526            binmode($fileCNT);
527    
528            my $buff;
529    
530            read($fileCNT, $buff, 26) || croak "can't read first table from CNT: $!";
531            $self->unpack_cnt($buff);
532    
533            read($fileCNT, $buff, 26) || croak "can't read second table from CNT: $!";
534            $self->unpack_cnt($buff);
535    
536            close($fileCNT);
537    
538            return $self->{cnt};
539    }
540    
541    =head2 unpack_cnt
542    
543    Unpack one of two 26 bytes fixed length record in C<.CNT> file.
544    
545    Here is definition of record:
546    
547     off key        description                             size
548      0: IDTYPE     BTree type                              s
549      2: ORDN       Nodes Order                             s
550      4: ORDF       Leafs Order                             s
551      6: N          Number of Memory buffers for nodes      s
552      8: K          Number of buffers for first level index s
553     10: LIV        Current number of Index Levels          s
554     12: POSRX      Pointer to Root Record in N0x           l
555     16: NMAXPOS    Next Available position in N0x          l
556     20: FMAXPOS    Next available position in L0x          l
557     24: ABNORMAL   Formal BTree normality indicator        s
558     length: 26 bytes
559    
560    This will fill C<$self> object under C<cnt> with hash. It's used by C<read_cnt>.
561    
562    =cut
563    
564    sub unpack_cnt {
565            my $self = shift;
566    
567            my @flds = qw(ORDN ORDF N K LIV POSRX NMAXPOS FMAXPOS ABNORMAL);
568    
569            my $buff = shift || return;
570            my @arr = unpack("vvvvvvVVVv", $buff);
571    
572            print STDERR "unpack_cnt: ",join(" ",@arr),"\n" if ($self->{'debug'});
573    
574            my $IDTYPE = shift @arr;
575            foreach (@flds) {
576                    $self->{cnt}->{$IDTYPE}->{$_} = abs(shift @arr);
577            }
578    }
579    
580  1;  1;
581    
582  =head1 BUGS  =head1 BUGS

Legend:
Removed from v.34  
changed lines
  Added in v.35

  ViewVC Help
Powered by ViewVC 1.1.26