lib/KinoSearch1/Util/SortExternal.pm

filter: Statementstmt 95.7% 249 / 260 Branchbran 90.4% 76 / 84 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 94.4% 325 / 344 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« lib/KinoSearch1/Store/InStream.pm ↑ Summary lib/KinoSearch1/Util/VerifyArgs.pm »
1 package KinoSearch1::Util::SortExternal;
2 use strict;
3 use warnings;
4 use KinoSearch1::Util::ToolSet;
5 use base qw( KinoSearch1::Util::CClass );
6  
7 BEGIN {
8 __PACKAGE__->init_instance_vars(
9 # constructor args
10 invindex => undef,
11 seg_name => undef,
12 mem_threshold => 2**24,
13 );
14 }
15 our %instance_vars;
16  
17 sub new {
18 my $class = shift;
19 verify_args( \%instance_vars, @_ );
20 my %args = ( %instance_vars, @_ );
21 my $invindex = $args{invindex};
22  
23 $class = ref($class) || $class;
24  
25 my $filename = "$args{seg_name}.srt";
26 $invindex->delete_file($filename) if $invindex->file_exists($filename);
27 my $outstream = $invindex->open_outstream($filename);
28  
29 return _new( $class, $outstream,
30 @args{qw( invindex seg_name mem_threshold )} );
31 }
32  
33 # Prepare to start fetching sorted results.
34 sub sort_all {
35 my $self = shift;
36  
37 # deal with any items in the cache right now
38 if ( $self->_get_num_runs == 0 ) {
39 # if we've never exceeded mem_threshold, sort in-memory
40 $self->_sort_cache;
41 }
42 else {
43 # create a run from whatever's in the cache right now
44 $self->_sort_run;
45 }
46  
47 # done adding elements, so close file and reopen as an instream
48 $self->_get_outstream->close;
49 my $filename = $self->_get_seg_name . ".srt";
50 my $instream = $self->_get_invindex()->open_instream($filename);
51 $self->_set_instream($instream);
52  
53 # allow fetching now that we're set up
54 $self->_enable_fetch;
55 }
56  
57 sub close { shift->_get_instream()->close }
58  
59 1;
60  
61 __END__
« lib/KinoSearch1/Store/InStream.pm ↑ Summary lib/KinoSearch1/Util/VerifyArgs.pm »