speeded up search and load of dx spots (a lot)
authordjk <djk>
Mon, 13 Jul 1998 22:04:45 +0000 (22:04 +0000)
committerdjk <djk>
Mon, 13 Jul 1998 22:04:45 +0000 (22:04 +0000)
perl/gdx.pl
perl/spot.pm

index 8f6f2065edd75b8395c581d8146ed1279a5ea77d..3d311e38264d4d36a5be378c331c1faba986c047 100755 (executable)
@@ -1,3 +1,4 @@
+#!/usr/bin/perl
 #
 # grep for expressions in various fields of the dx file
 #
@@ -8,7 +9,13 @@ use DXDebug;
 use spot;
 
 # initialise spots file
+STDOUT->autoflush(1);
+
+print "reading in spot data ..";
+$t = time;
 $count = spot->init();
+$t = time - $t;
+print "done ($t secs)\n";
 
 dbgadd('spot');
 
@@ -18,8 +25,6 @@ $time = time;
 
 print "$count database records read in\n";
 
-STDOUT->autoflush(1);
-
 #loada();
 for (;;) {
   print "field: ";
index 811a708034f471070d824e7a71d95cbe31a3f736..1d0ac75331c79d53ad0a48311489134acd600018 100644 (file)
@@ -34,11 +34,14 @@ sub init
     my $ref = spot->open(@first);
        if ($ref) {
          my $fh = $ref->{fh};
+         my @out = ();
          while (<$fh>) {
            chomp;
            my @ent = split /\^/;
-           unshift @spot::table, [ @ent ];                # stick this ref to anon list on the FRONT of the table
-               ++$count;
+
+        push @spot::table, \@ent;                # stick this ref to anon list on the FRONT of the table
+
+           ++$count;
          }
        }
     @first = julian->add(@first, 1);
@@ -57,7 +60,7 @@ sub new
   $spot[2] = 0 + $spot[2];
   
   # save it on the front of the list
-  unshift @spot::table, [ @spot ];
+  unshift @spot::table,  \@spot;
   
   # compare dates to see whether need to open a other save file
   my @date = julian->unixtoj($spot[2]);
@@ -91,10 +94,11 @@ sub purge
 #
 sub search
 {
-  my ($pkg, $field, $expr) = @_;
+  my ($pkg, $field, $expr, $from, $to) = @_;
   my $eval;
   my @out;
   my $ref;
+  my $i;
  
   dbg('spot', "input expr = $expr\n");
   if ($field == 0 || $field == 2) {              # numeric fields
@@ -106,7 +110,12 @@ sub search
   
   # build up eval to execute
   $eval = qq(foreach \$ref (\@spot::table) {
-    push \@out, \$ref if $expr;
+    next if \$i < \$from;
+       if ($expr) {
+       unshift(\@out, \$ref);
+          \$i++;
+          last if \$to && \$i >= \$to;
+       }
   });
   dbg('spot', "eval = $eval\n");
   eval $eval;                                   # execute it