From: djk Date: Mon, 13 Jul 1998 22:04:45 +0000 (+0000) Subject: speeded up search and load of dx spots (a lot) X-Git-Tag: SPIDER_1_5~45 X-Git-Url: http://www.dxcluster.org/gitweb/gitweb.cgi?p=spider.git;a=commitdiff_plain;h=8cc3ac88ee6ba2216a9f19761385c9869a2f91b1 speeded up search and load of dx spots (a lot) --- diff --git a/perl/gdx.pl b/perl/gdx.pl index 8f6f2065..3d311e38 100755 --- a/perl/gdx.pl +++ b/perl/gdx.pl @@ -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: "; diff --git a/perl/spot.pm b/perl/spot.pm index 811a7080..1d0ac753 100644 --- a/perl/spot.pm +++ b/perl/spot.pm @@ -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