| 1 | package Set::SegmentTree; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | our $VERSION = '0.05'; | |||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use Carp qw/confess croak carp/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Set::SegmentTree::ValueLookup; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use List::Util qw/uniq/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use File::Map qw/map_file/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use Set::SegmentTree::Builder; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | sub new { | ||||||||||
| 19 | 0 | ▶ | croak 'There is no new. Do you mean Set::Interval::Builder->new(\$' | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 20 | . 'options)?'; | ||||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | sub from_file { | ||||||||||
| 24 | 1 | ▶ | my ( $class, $filename ) = @_; | ||||||||
|
Subroutine
from_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 25 | 1 | map_file my $bin, $filename, '<'; | |||||||||
| 26 | return | ||||||||||
| 27 | 1 | bless { | |||||||||
| 28 | flatbuffer => Set::SegmentTree::ValueLookup->deserialize($bin) }, | ||||||||||
| 29 | $class; | ||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | sub deserialize { | ||||||||||
| 33 | 1 | ▶ | my ( $class, $serialization ) = @_; | ||||||||
|
Subroutine
deserialize: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 34 | return | ||||||||||
| 35 | 1 | bless { flatbuffer => | |||||||||
| 36 | Set::SegmentTree::ValueLookup->deserialize($serialization) }, | ||||||||||
| 37 | $class; | ||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | sub find { | ||||||||||
| 41 | 28 | ▶ | my ( $self, $instant ) = @_; | ||||||||
|
Subroutine
find: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 42 | return uniq $self->find_segments( | ||||||||||
| 43 | 28 | $self->node( $self->{flatbuffer}->root ), $instant ); | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | sub node { | ||||||||||
| 47 | 264 | ▶ | my ( $self, $offset ) = @_; | ||||||||
|
Subroutine
node: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 48 | 264 | return $self->{flatbuffer}->nodes->[$offset]; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | sub find_segments { | ||||||||||
| 52 | 170 | ▶ | my ( $self, $node, $instant ) = @_; | ||||||||
|
Subroutine
find_segments: called CC=6 SCAR=18.6
Pod
documented
| |||||||||||
| 53 | warn "instant $instant node " | ||||||||||
| 54 | . $node->min . '->' | ||||||||||
| 55 | . $node->max . q^: ^ | ||||||||||
| 56 | 0 | ▶ | . join( q^ ^, sort @{ $node->segments || [] } ) . "\n" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 170 | ▶ | if $self->{verbose}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 170 | ▶ | return uniq @{ $node->segments || [] }, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 142 | map { $self->find_segments( $_, $instant ) } | |||||||||
| 60 | 236 | ▶ | grep { $instant >= $_->{min} && $instant <= $_->{max} } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 170 | ▶ | map { $node->$_ ? $self->node( $node->$_ ) : () } qw/low high/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 1 | 1; | |||||||||
| 65 | __END__ | ||||||||||