Block/Private.pm

filter: Statementstmt 100% 134 / 134 Branchbran 91.1% 31 / 34 Conditioncond 90.9% 20 / 22 MC/DCmcdc 84.6% 11 / 13 Subroutinesub 100% 24 / 24 Podpod n/a totaltotal 96.9% 220 / 227 CC 28 SCAR 12.4
CC
28
Cov
97%
_fromMask
8.0
_fromRange
5.0
_leading_zeros
4.0
CRAP 3.4
« Block.pm ↑ Summary
1 package Net::IPAM::Block::Private;
2  
3 13 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use Net::IPAM::IP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 Net::IPAM::Block::Private - Just private functions for Net::IPAM::Block
15  
16 =head1 DESCRIPTION
17  
18 Don't pollute the B<< namespace >> of Net::IPAM::Block
19  
20 =cut
21  
22 # use some pre-calculated tables for speed, see end of package
23 13 my ( %valid_masks4, @table_mask_n, @nlz8 );
24  
25 # 1.2.3.4/255.0.0.0 => {base: 1.0.0.0, last: 1.255.255.255, mask: 255.0.0.0}
26 # 1.2.3.4/24 => {base: 1.2.3.0, last: 1.2.3.255, mask: 255.255.255.0}
27 # fe80::1/124 => {base: fe80::, last: fe80::f, mask: ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0}
28 228 ▶sub _fromMask {
Subroutine _fromMask: called CC=8 SCAR=20.8
29 228 my ( $self, $addr, $idx ) = @_;
30  
31 # split input in prefix and suffix:
32 # 10.0.0.0/255.0.0.0 => 10.0.0.0, 255.0.0.0
33 # 10.0.0.0/8 => 10.0.0.0, 8
34 # fe80::1/124 => fe80::1, 124
35 #
36 228 my $prefix_str = substr( $addr, 0, $idx );
37 228 my $suffix_str = substr( $addr, $idx + 1 );
38  
39 228 ▶ my $prefix = Net::IPAM::IP->new($prefix_str) // return;
Condition100%2/2
"Net::IPAM::IP"->new($prefix_str) // (return)
l!l
2262
MC/DC100%1/1
"Net::IPAM::IP"->new($prefix_str) // (return)
"Net::IPAM::IP"->new($prefix_str)
Truth table100%2/2
A
A= "Net::IPAM::IP"->new($prefix_str)
Aresult
11
00
40  
41 226 my $mask_n;
42 226 ▶ if ( index( $suffix_str, '.' ) >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($suffix_str, '.') != -1) { } 7 219 226
43 7 ▶ my $ip = Net::IPAM::IP->new($suffix_str) // return;
Condition100%2/2
"Net::IPAM::IP"->new($suffix_str) // (return)
l!l
61
MC/DC100%1/1
"Net::IPAM::IP"->new($suffix_str) // (return)
"Net::IPAM::IP"->new($suffix_str)
Truth table100%2/2
A
A= "Net::IPAM::IP"->new($suffix_str)
Aresult
11
00
44 6 $mask_n = $ip->bytes;
45 6 ▶ return unless exists $valid_masks4{$mask_n};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $valid_masks4{$mask_n} 1 5 6
46 }
47 else {
48 219 my $bits = 32;
49 219 ▶ $bits = 128 if $prefix->version == 6;
Branch: 1 branch
BranchTrueFalseTotal
if $prefix->version == 6 136 83 219
50  
51 219 ▶ return unless $suffix_str =~ m/^\d+$/; # pos integer
Branch: 1 branch
BranchTrueFalseTotal
unless $suffix_str =~ /^\d+$/ 2 217 219
52 217 ▶ return if $suffix_str > $bits;
Branch: 1 branch
BranchTrueFalseTotal
if $suffix_str > $bits 4 213 217
53  
54 213 $mask_n = _make_mask_n( $suffix_str, $bits );
55 }
56  
57 218 $self->{base} = Net::IPAM::IP->new_from_bytes( _make_base_n( $prefix->bytes, $mask_n ) );
58 218 $self->{last} = Net::IPAM::IP->new_from_bytes( _make_last_n( $prefix->bytes, $mask_n ) );
59  
60 218 return $self;
61 }
62  
63 # 1.2.3.4-1.2.3.17 => {base: 1.2.3.4, last: 1.2.3.17, mask: undef}
64 # fe80::-fe80::ffff => {base: fe80::, last: fe80::ffff, mask: ffff:ffff:ffff:ffff:ffff:ffff:ffff::}
65 81 ▶sub _fromRange {
Subroutine _fromRange: called CC=5 SCAR=16.1
66 81 my ( $self, $addr, $idx ) = @_;
67  
68 # split range in base and last 10.0.0.1-10.0.0.3 => 10.0.0.1, 10.0.0.3
69 81 my $base_str = substr( $addr, 0, $idx );
70 81 my $last_str = substr( $addr, $idx + 1 );
71  
72 81 ▶ my $base_ip = Net::IPAM::IP->new($base_str) // return;
Condition100%2/2
"Net::IPAM::IP"->new($base_str) // (return)
l!l
801
MC/DC100%1/1
"Net::IPAM::IP"->new($base_str) // (return)
"Net::IPAM::IP"->new($base_str)
Truth table100%2/2
A
A= "Net::IPAM::IP"->new($base_str)
Aresult
11
00
73 80 ▶ my $last_ip = Net::IPAM::IP->new($last_str) // return;
Condition100%2/2
"Net::IPAM::IP"->new($last_str) // (return)
l!l
782
MC/DC100%1/1
"Net::IPAM::IP"->new($last_str) // (return)
"Net::IPAM::IP"->new($last_str)
Truth table100%2/2
A
A= "Net::IPAM::IP"->new($last_str)
Aresult
11
00
74  
75 # version base != version last
76 78 my $version = $base_ip->version;
77 78 ▶ return if $version != $last_ip->version;
Branch: 1 branch
BranchTrueFalseTotal
if $version != $last_ip->version 2 76 78
78  
79 # base > last?
80 76 ▶ return if $base_ip->cmp($last_ip) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $base_ip->cmp($last_ip) > 0 2 74 76
81  
82 74 $self->{base} = $base_ip;
83 74 $self->{last} = $last_ip;
84  
85 74 return $self;
86 }
87  
88 # 1.2.3.4 => {base: 1.2.3.4, last: 1.2.3.4, mask: 255.255.255.255}
89 # fe80::1 => {base: fe80::1, last: fe80::1, mask: ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff}
90 65 ▶sub _fromAddr {
Subroutine _fromAddr: called CC=2 SCAR=6.9
91 65 my ( $self, $addr ) = @_;
92  
93 65 ▶ my $base = Net::IPAM::IP->new($addr) // return;
Condition100%2/2
"Net::IPAM::IP"->new($addr) // (return)
l!l
632
MC/DC100%1/1
"Net::IPAM::IP"->new($addr) // (return)
"Net::IPAM::IP"->new($addr)
Truth table100%2/2
A
A= "Net::IPAM::IP"->new($addr)
Aresult
11
00
94  
95 63 $self->{base} = $base;
96 63 $self->{last} = $base;
97  
98 63 return $self;
99 }
100  
101 # 1.2.3.4 => {base: 1.2.3.4, last: 1.2.3.4, mask: 255.255.255.255}
102 # fe80::1 => {base: fe80::1, last: fe80::1, mask: ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff}
103 4 ▶sub _fromIP {
Subroutine _fromIP: called CC=3 SCAR=11.8
104 4 my ( $self, $ip ) = @_;
105  
106 4 ▶ return unless Scalar::Util::blessed($ip) && $ip->isa('Net::IPAM::IP');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($ip) and $ip->isa("Net::IPAM::IP") 0 4 4
Condition33%1/3
builtin::blessed($ip) and $ip->isa("Net::IPAM::IP")
!ll&&!rl&&r
004
MC/DC0%0/2
builtin::blessed($ip) and $ip->isa("Net::IPAM::IP")
builtin::blessed($ip) $ip->isa("Net::IPAM::IP")
Truth table33%1/3
A and B
A= builtin::blessed($ip)B= $ip->isa("Net::IPAM::IP")
ABresult
0X0
100
111
107  
108 4 $self->{base} = $ip;
109 4 $self->{last} = $ip;
110  
111 4 return $self;
112 }
113  
114 # my $b = _clone($self)
115 19 ▶sub _clone {
Subroutine _clone: called CC=1 SCAR=0.0
116 19 my $self = shift;
117 19 my $clone = bless {}, ref $self;
118  
119 19 $clone->{base} = Net::IPAM::IP->new_from_bytes( $self->{base}->bytes );
120 19 $clone->{last} = Net::IPAM::IP->new_from_bytes( $self->{last}->bytes );
121  
122 19 return $clone;
123 }
124  
125 # a.base <= b && a.last >= b
126 8 ▶sub _contains_ip {
Subroutine _contains_ip: called CC=2 SCAR=6.9
127 8 ▶ return $_[0]->{base}->cmp( $_[1] ) <= 0 && $_[0]->{last}->cmp( $_[1] ) >= 0;
Condition100%3/3
$_[0]{'base'}->cmp($_[1]) <= 0 && $_[0]{'last'}->cmp($_[1]) >= 0
!ll&&!rl&&r
134
MC/DC100%2/2
$_[0]{'base'}->cmp($_[1]) <= 0 && $_[0]{'last'}->cmp($_[1]) >= 0
$_[0]{'base'}->cmp($_[1]) <= 0 $_[0]{'last'}->cmp($_[1]) >= 0
Truth table100%3/3
A && B
A= $_[0]{'base'}->cmp($_[1]) <= 0B= $_[0]{'last'}->cmp($_[1]) >= 0
ABresult
0X0
100
111
128 }
129  
130 249 ▶sub _contains_block {
Subroutine _contains_block: called CC=3 SCAR=11.0
131  
132 # a == b, return false
133 249 ▶ return 0 if $_[0]->cmp( $_[1] ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->cmp($_[1]) == 0 2 247 249
134  
135 # a.base <= b.base && a.last >= b.last
136 247 ▶ return $_[0]->{base}->cmp( $_[1]->{base} ) <= 0 && $_[0]->{last}->cmp( $_[1]->{last} ) >= 0;
Condition100%3/3
$_[0]{'base'}->cmp($_[1]{'base'}) <= 0 && $_[0]{'last'}->cmp($_[1]{'last'}) >= 0
!ll&&!rl&&r
8210164
MC/DC100%2/2
$_[0]{'base'}->cmp($_[1]{'base'}) <= 0 && $_[0]{'last'}->cmp($_[1]{'last'}) >= 0
$_[0]{'base'}->cmp($_[1]{'base'}) <= 0 $_[0]{'last'}->cmp($_[1]{'last'}) >= 0
Truth table100%3/3
A && B
A= $_[0]{'base'}->cmp($_[1]{'base'}) <= 0B= $_[0]{'last'}->cmp($_[1]{'last'}) >= 0
ABresult
0X0
100
111
137 }
138  
139 # count leading zeros
140 679 ▶sub _leading_zeros {
Subroutine _leading_zeros: called CC=4 SCAR=13.9
141 679 ▶ my $n = shift or die 'missing arg,';
Branch: 1 branch
BranchTrueFalseTotal
my $n = shift() or die "missing arg," 679 0 679
142 679 my $zeros = 0;
143  
144 # step byte-wise through $n from left to right
145 679 for my $i ( 0 .. length($n) - 1 ) {
146 4490 my $byte = vec( $n, $i, 8 );
147  
148 # count bytes
149 4490 ▶ if ( $byte == 0x00 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($byte == 0) 3919 571 4490
150 3919 $zeros += 8;
151 3919 next;
152 }
153  
154 # count bits, use a pre-calculated table
155 571 $zeros += $nlz8[$byte];
156 571 last;
157 }
158  
159 679 return $zeros;
160 }
161  
162 # number of common leading bits
163 679 ▶sub _common_prefix {
Subroutine _common_prefix: called CC=1 SCAR=0.0
164 679 my ( $base_n, $last_n ) = @_;
165 679 return _leading_zeros( $base_n ^ $last_n );
166 }
167  
168 # returns the common prefix bits and ok. ok is true when the range is a CIDR.
169 504 ▶sub _common_ok {
Subroutine _common_ok: called CC=2 SCAR=6.9
170 504 my ( $base_n, $last_n, $bits ) = @_;
171  
172 504 my $pfx = _common_prefix( $base_n, $last_n );
173 504 my $mask_n = _make_mask_n( $pfx, $bits );
174  
175 # apply mask to base and last as AND and OR
176 # and check for all zeros and all ones => it's a CIDR
177 504 my $is_all_zeros = ( $base_n ^ ( $base_n & $mask_n ) ) eq _make_mask_n( 0, $bits );
178 504 my $is_all_ones = ( $last_n | $mask_n ) eq _make_mask_n( 128, $bits );
179  
180 504 ▶ return $pfx, $is_all_zeros && $is_all_ones;
Condition100%3/3
$is_all_zeros && $is_all_ones
!ll&&!rl&&r
25143336
MC/DC100%2/2
$is_all_zeros && $is_all_ones
$is_all_zeros $is_all_ones
Truth table100%3/3
A && B
A= $is_all_zerosB= $is_all_ones
ABresult
0X0
100
111
181 }
182  
183 # switch to binary representation
184 # push start block on stack
185 #
186 # loop while stack not dry
187 # check if is_cidr
188 # split the range in the middle
189 # put both halves on stack (reverse order)
190 # next
191 #
192 # return cidrs
193 #
194 10 ▶sub _to_cidrs_iter {
Subroutine _to_cidrs_iter: called CC=4 SCAR=13.9
195 10 my $self = shift;
196 10 my @stack;
197 my @result;
198  
199 10 my $bits = 32;
200 10 ▶ $bits = 128 if $self->version == 6;
Branch: 1 branch
BranchTrueFalseTotal
if $self->version == 6 4 6 10
201  
202 # make binary representation, put it as start on the stack
203 10 push @stack, [ $self->{base}->bytes, $self->{last}->bytes ];
204  
205 10 ▶ while ( scalar @stack > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @stack > 0) 278 10 288
206 278 my $block_n = pop @stack;
207 278 my $base_n = $block_n->[0];
208 278 my $last_n = $block_n->[1];
209  
210 278 my ( $pfx, $is_cidr ) = _common_ok( $base_n, $last_n, $bits );
211  
212 # is this block already a CIDR?
213 278 ▶ if ($is_cidr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_cidr) 144 134 278
214  
215 # add block ro result
216 144 my $block = bless {}, ref $self;
217 144 $block->{base} = Net::IPAM::IP->new_from_bytes($base_n);
218 144 $block->{last} = Net::IPAM::IP->new_from_bytes($last_n);
219  
220 144 push @result, $block;
221 144 next;
222 }
223  
224 # split block in two halves, add 1 to common prefix
225 134 my $mask_n = _make_mask_n( $pfx + 1, $bits );
226  
227 # split range with new mask
228 134 my $mid_last_n = _make_last_n( $base_n, $mask_n );
229 134 my $mid_base_n = _make_base_n( $last_n, $mask_n );
230  
231 # make two new blocks
232 134 my $block1_n = [ $base_n, $mid_last_n ];
233 134 my $block2_n = [ $mid_base_n, $last_n ];
234  
235 # push both blocks to stack, reverse the order
236 134 push @stack, $block2_n, $block1_n;
237 }
238  
239 10 return \@result;
240 }
241  
242 # returns true if base and last forms a CIDR range
243 226 ▶sub _is_cidr {
Subroutine _is_cidr: called CC=2 SCAR=6.9
244 226 my $self = shift;
245  
246 226 my $bits = 32;
247 226 ▶ $bits = 128 if $self->version == 6;
Branch: 1 branch
BranchTrueFalseTotal
if $self->version == 6 102 124 226
248  
249 226 my $base_n = $self->{base}->bytes;
250 226 my $last_n = $self->{last}->bytes;
251  
252 226 my ( $pfx, $is_cidr ) = _common_ok( $base_n, $last_n, $bits );
253 226 return $is_cidr;
254 }
255  
256 # base = addr & netMask
257 361 ▶sub _make_base_n {
Subroutine _make_base_n: called CC=1 SCAR=0.0
258 361 my ( $addr_n, $mask_n ) = @_;
259 361 return $addr_n & $mask_n;
260 }
261  
262 # last = addr | hostMask
263 370 ▶sub _make_last_n {
Subroutine _make_last_n: called CC=1 SCAR=0.0
264 370 my ( $addr_n, $mask_n ) = @_;
265 370 return $addr_n | ~$mask_n;
266 }
267  
268 # cut off the bits after 32, used for IPv4
269 516 ▶sub _strip_to_32_bits { return $_[0] & "\xff\xff\xff\xff" }
Subroutine _strip_to_32_bits: called CC=1 SCAR=0.0
270  
271 # make CIDR mask from bits:
272 # (24, 32) => 0xffff_ff00
273 # (56, 128) => 0xffff_ffff_ffff_ff00_0000_0000_0000_0000
274 #
275 1870 ▶sub _make_mask_n {
Subroutine _make_mask_n: called CC=2 SCAR=6.9
276 1870 my ( $n, $bits ) = @_;
277 1870 my $mask_n = $table_mask_n[$n];
278 #
279 # cut to first 32 bits
280 1870 ▶ if ( $bits == 32 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bits == 32) 516 1354 1870
281 516 return _strip_to_32_bits($mask_n);
282 }
283 1354 return $mask_n;
284 }
285  
286 2 ▶sub _get_mask_n {
Subroutine _get_mask_n: called CC=2 SCAR=7.0
287 2 my ( $base_ip, $last_ip ) = @_;
288  
289 2 my $pfx = _common_prefix( $base_ip->bytes, $last_ip->bytes );
290  
291 2 my $bits = 32;
292 2 ▶ $bits = 128 if $base_ip->version == 6;
Branch: 1 branch
BranchTrueFalseTotal
if $base_ip->version == 6 0 2 2
293  
294 2 return _make_mask_n( $pfx, $bits );
295 }
296  
297 #############################
298 # pre-calc tables
299 #############################
300  
301 #<<< skip marker for perltidy
302  
303 # pre-calced masks for 0.0.0.0 - 255.255.255.255
304 # only IPv4 addresses representable as a sequence of 1 bits followed by 0 bits
305 # are allowed as masks as input
306  
307 13 %valid_masks4 = (
308 "\x00\x00\x00\x00" => 0, "\x80\x00\x00\x00" => 1, "\xc0\x00\x00\x00" => 2,
309 "\xe0\x00\x00\x00" => 3, "\xf0\x00\x00\x00" => 4, "\xf8\x00\x00\x00" => 5,
310 "\xfc\x00\x00\x00" => 6, "\xfe\x00\x00\x00" => 7, "\xff\x00\x00\x00" => 8,
311 "\xff\x80\x00\x00" => 9, "\xff\xc0\x00\x00" => 10, "\xff\xe0\x00\x00" => 11,
312 "\xff\xf0\x00\x00" => 12, "\xff\xf8\x00\x00" => 13, "\xff\xfc\x00\x00" => 14,
313 "\xff\xfe\x00\x00" => 15, "\xff\xff\x00\x00" => 16, "\xff\xff\x80\x00" => 17,
314 "\xff\xff\xc0\x00" => 18, "\xff\xff\xe0\x00" => 19, "\xff\xff\xf0\x00" => 20,
315 "\xff\xff\xf8\x00" => 21, "\xff\xff\xfc\x00" => 22, "\xff\xff\xfe\x00" => 23,
316 "\xff\xff\xff\x00" => 24, "\xff\xff\xff\x80" => 25, "\xff\xff\xff\xc0" => 26,
317 "\xff\xff\xff\xe0" => 27, "\xff\xff\xff\xf0" => 28, "\xff\xff\xff\xf8" => 29,
318 "\xff\xff\xff\xfc" => 30, "\xff\xff\xff\xfe" => 31, "\xff\xff\xff\xff" => 32,
319 );
320  
321 # pre-calced CIDR masks for /0 .. /128,
322 # e.g.
323 # $table_mask_n[3] == "\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
324 # $table_mask_n[64] == "\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00"
325 # $table_mask_n[128] == "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
326  
327 13 @table_mask_n = (
328 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
329 "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
330 "\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
331 "\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
332 "\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
333 "\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
334 "\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
335 "\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
336 "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
337 "\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
338 "\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
339 "\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
340 "\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
341 "\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
342 "\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
343 "\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
344 "\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
345 "\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
346 "\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
347 "\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
348 "\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
349 "\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
350 "\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
351 "\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
352 "\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
353 "\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
354 "\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
355 "\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
356 "\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
357 "\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
358 "\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
359 "\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
360 "\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
361 "\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
362 "\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
363 "\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
364 "\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
365 "\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
366 "\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
367 "\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
368 "\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
369 "\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
370 "\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
371 "\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
372 "\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
373 "\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
374 "\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
375 "\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
376 "\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
377 "\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00",
378 "\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00",
379 "\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00",
380 "\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00",
381 "\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00",
382 "\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00",
383 "\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00",
384 "\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00",
385 "\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00",
386 "\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00",
387 "\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00",
388 "\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00",
389 "\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00",
390 "\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00",
391 "\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00",
392 "\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00",
393 "\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00",
394 "\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00",
395 "\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00",
396 "\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00",
397 "\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00",
398 "\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00",
399 "\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00",
400 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00",
401 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00",
402 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00",
403 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00",
404 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00",
405 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00",
406 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00",
407 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00",
408 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00",
409 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00",
410 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00",
411 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00",
412 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00",
413 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00",
414 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00",
415 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00",
416 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00",
417 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00",
418 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00",
419 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00",
420 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00",
421 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00",
422 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00",
423 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00",
424 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00",
425 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00",
426 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00",
427 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00",
428 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00",
429 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00",
430 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00",
431 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00",
432 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00",
433 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00",
434 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00",
435 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00",
436 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00",
437 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00",
438 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00",
439 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00",
440 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00",
441 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00",
442 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00",
443 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00",
444 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00",
445 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00",
446 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00",
447 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00",
448 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00",
449 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80",
450 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0",
451 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0",
452 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0",
453 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8",
454 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc",
455 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe",
456 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",
457 );
458  
459 # pre-calced 'number of leading zeros' for byte values 0x00 - 0xff
460 # e.g.
461 # $nlz[0] == 8 # 0b0000_0000
462 # $nlz[1] == 7 # 0b0000_0001
463 # $nlz[64] == 1 # 0b0100_0000
464 # $nlz[128] == 0 # 0b1000_0000
465  
466 13 @nlz8 = (
467 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, # 00..1f
468 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, # 20..3f
469 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, # 40..5f
470 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, # 60..7f
471 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 80..9f
472 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # a0..bf
473 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # c0..df
474 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # e0..ff
475 );
476  
477 ####################################
478 #>>> end of skip marker for perltidy
479 ####################################
480  
481 =head1 AUTHOR
482  
483 Karl Gaissmaier, C<< <karl.gaissmaier(at)uni-ulm.de> >>
484  
485 =head1 LICENSE AND COPYRIGHT
486  
487 This software is copyright (c) 2020-2022 by Karl Gaissmaier.
488  
489 This is free software; you can redistribute it and/or modify it under
490 the same terms as the Perl 5 programming language system itself.
491  
492 =cut
493  
494 13 1;
« Block.pm ↑ Summary