« blib/lib/App/RecordStream/Aggregator/Internal/ForField.pm
↑ Summary
blib/lib/App/RecordStream/Operation/fromre.pm »
| 1 | package App::RecordStream::LRUSheriff; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | our $VERSION = "4.0.23"; | |||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | sub new | ||||||||||
| 9 | { | ||||||||||
| 10 | 11 | ▶ | my $class = shift; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 11 | |||||||||||
| 12 | 11 | my $this = { }; | |||||||||
| 13 | |||||||||||
| 14 | 11 | $this->{'hr'} = { }; | |||||||||
| 15 | 11 | $this->{'head'} = undef; | |||||||||
| 16 | 11 | $this->{'tail'} = undef; | |||||||||
| 17 | 11 | $this->{'ct'} = 0; | |||||||||
| 18 | |||||||||||
| 19 | 11 | bless $this, $class; | |||||||||
| 20 | |||||||||||
| 21 | 11 | return $this; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | sub find | ||||||||||
| 25 | { | ||||||||||
| 26 | 62 | ▶ | my ($this, $k) = @_; | ||||||||
|
Subroutine
find: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 27 | |||||||||||
| 28 | 62 | my $data = $this->{'hr'}->{$k}; | |||||||||
| 29 | |||||||||||
| 30 | 62 | ▶ | if($data) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | { | ||||||||||
| 32 | 28 | $this->_unlink($data->[0]); | |||||||||
| 33 | 28 | $this->_head($data->[0]); | |||||||||
| 34 | 28 | return $data->[1]; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 34 | return undef; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | sub put | ||||||||||
| 41 | { | ||||||||||
| 42 | 34 | ▶ | my ($this, $k, $v) = @_; | ||||||||
|
Subroutine
put: called CC=2 SCAR=8.3
Pod
undocumented
| |||||||||||
| 43 | |||||||||||
| 44 | 34 | my $data = $this->{'hr'}->{$k}; | |||||||||
| 45 | 34 | ▶ | if($data) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | { | ||||||||||
| 47 | 0 | $data->[1] = $v; | |||||||||
| 48 | 0 | $this->_unlink($data->[0]); | |||||||||
| 49 | 0 | $this->_head($data->[0]); | |||||||||
| 50 | 0 | return; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 34 | my $node = [undef, undef, $k]; | |||||||||
| 54 | 34 | $this->_head($node); | |||||||||
| 55 | 34 | $this->{'hr'}->{$k} = [$node, $v]; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | sub _unlink | ||||||||||
| 59 | { | ||||||||||
| 60 | 62 | ▶ | my ($this, $node) = @_; | ||||||||
|
Subroutine
_unlink: called CC=3 SCAR=11.0
| |||||||||||
| 61 | |||||||||||
| 62 | 62 | ▶ | if($node->[0]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | { | ||||||||||
| 64 | 29 | $node->[0]->[1] = $node->[1]; | |||||||||
| 65 | } | ||||||||||
| 66 | else | ||||||||||
| 67 | { | ||||||||||
| 68 | 33 | $this->{'head'} = $node->[1]; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 62 | ▶ | if($node->[1]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | { | ||||||||||
| 73 | 13 | $node->[1]->[0] = $node->[0]; | |||||||||
| 74 | } | ||||||||||
| 75 | else | ||||||||||
| 76 | { | ||||||||||
| 77 | 49 | $this->{'tail'} = $node->[0]; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 62 | --$this->{'ct'}; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | sub _head | ||||||||||
| 84 | { | ||||||||||
| 85 | 62 | ▶ | my ($this, $node) = @_; | ||||||||
|
Subroutine
_head: called CC=2 SCAR=6.9
| |||||||||||
| 86 | |||||||||||
| 87 | 62 | $node->[0] = undef; | |||||||||
| 88 | 62 | $node->[1] = $this->{'head'}; | |||||||||
| 89 | 62 | $this->{'head'} = $node; | |||||||||
| 90 | 62 | ▶ | if($node->[1]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | { | ||||||||||
| 92 | 42 | $node->[1]->[0] = $node; | |||||||||
| 93 | } | ||||||||||
| 94 | else | ||||||||||
| 95 | { | ||||||||||
| 96 | 20 | $this->{'tail'} = $node; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 62 | ++$this->{'ct'}; | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | sub purgenate | ||||||||||
| 103 | { | ||||||||||
| 104 | 73 | ▶ | my ($this, $size) = @_; | ||||||||
|
Subroutine
purgenate: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 105 | |||||||||||
| 106 | 73 | my @goners; | |||||||||
| 107 | 73 | ▶ | while($this->{'ct'} > $size) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | { | ||||||||||
| 109 | 34 | my $node = $this->{'tail'}; | |||||||||
| 110 | 34 | $this->_unlink($node); | |||||||||
| 111 | 34 | my $key = $node->[2]; | |||||||||
| 112 | 34 | my $data = delete $this->{'hr'}->{$key}; | |||||||||
| 113 | 34 | push @goners, $data->[1]; | |||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 73 | return @goners; | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 5 | 1; | |||||||||