blib/lib/Net/IPAM/Block/Private.pm

filter: Statementstmt 100% 139 / 139 Branchbran 90.6% 29 / 32 Conditioncond 92.0% 23 / 25 MC/DCmcdc 86.6% 13 / 15 Subroutinesub 100% 25 / 25 Podpod n/a totaltotal 97.0% 229 / 236 CC 28 SCAR 12.0
CC
28
Cov
97%
_fromMask
8.0
_fromRange
5.0
_leading_zeros
4.0
CRAP 3.3
« Build ↑ 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 sub _fromMask {
29 227 ▶ my ( $self, $addr, $idx ) = @_;
Subroutine _fromMask: called CC=8 SCAR=20.8
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 227 my $prefix_str = substr( $addr, 0, $idx );
37 227 my $suffix_str = substr( $addr, $idx + 1 );
38  
39 227 ▶ my $prefix = Net::IPAM::IP->new($prefix_str) // return;
Condition100%2/2
"Net::IPAM::IP"->new($prefix_str) // (return)
l!l
2252
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 225 my $mask_n;
42 225 ▶ if ( index( $suffix_str, '.' ) >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($suffix_str, '.') != -1) { } 7 218 225
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 218 my $bits = 32;
49 218 ▶ $bits = 128 if $prefix->version == 6;
Branch: 1 branch
BranchTrueFalseTotal
if $prefix->version == 6 135 83 218
50  
51 218 ▶ return unless $suffix_str =~ m/^\d+$/; # pos integer
Branch: 1 branch
BranchTrueFalseTotal
unless $suffix_str =~ /^\d+$/ 2 216 218
52 216 ▶ return if $suffix_str > $bits;
Branch: 1 branch
BranchTrueFalseTotal
if $suffix_str > $bits 4 212 216
53  
54 212 $mask_n = _make_mask_n( $suffix_str, $bits );
55 }
56  
57 217 $self->{base} = Net::IPAM::IP->new_from_bytes( _make_base_n( $prefix->bytes, $mask_n ) );
58 217 $self->{last} = Net::IPAM::IP->new_from_bytes( _make_last_n( $prefix->bytes, $mask_n ) );
59  
60 217 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 sub _fromRange {
66 80 ▶ my ( $self, $addr, $idx ) = @_;
Subroutine _fromRange: called CC=5 SCAR=16.1
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 80 my $base_str = substr( $addr, 0, $idx );
70 80 my $last_str = substr( $addr, $idx + 1 );
71  
72 80 ▶ my $base_ip = Net::IPAM::IP->new($base_str) // return;
Condition100%2/2
"Net::IPAM::IP"->new($base_str) // (return)
l!l
791
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 79 ▶ my $last_ip = Net::IPAM::IP->new($last_str) // return;
Condition100%2/2
"Net::IPAM::IP"->new($last_str) // (return)
l!l
772
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 77 my $version = $base_ip->version;
77 77 ▶ return if $version != $last_ip->version;
Branch: 1 branch
BranchTrueFalseTotal
if $version != $last_ip->version 2 75 77
78  
79 # base > last?
80 75 ▶ return if $base_ip->cmp($last_ip) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $base_ip->cmp($last_ip) > 0 2 73 75
81  
82 73 $self->{base} = $base_ip;
83 73 $self->{last} = $last_ip;
84  
85 73 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 sub _fromAddr {
91 65 ▶ my ( $self, $addr ) = @_;
Subroutine _fromAddr: called CC=2 SCAR=6.9
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 sub _fromIP {
104 4 ▶ my ( $self, $ip ) = @_;
Subroutine _fromIP: called CC=3 SCAR=11.8
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 sub _clone {
116 19 ▶ my $self = shift;
Subroutine _clone: called CC=1 SCAR=0.0
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 sub _contains_ip {
127 8 ▶ return $_[0]->{base}->cmp( $_[1] ) <= 0 && $_[0]->{last}->cmp( $_[1] ) >= 0;
Subroutine _contains_ip: called CC=2 SCAR=6.9
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 sub _contains_block {
131  
132 # a == b, return false
133 249 ▶ return 0 if $_[0]->cmp( $_[1] ) == 0;
Subroutine _contains_block: called CC=3 SCAR=11.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 sub _leading_zeros {
141 430 ▶ my $n = shift or die 'missing arg,';
Subroutine _leading_zeros: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
my $n = shift() or die "missing arg," 0 430 430
142 430 my $zeros = 0;
143  
144 # step byte-wise through $n from left to right
145 430 for my $i ( 0 .. length($n) - 1 ) {
146 2329 my $byte = vec( $n, $i, 8 );
147  
148 # count bytes
149 2329 ▶ if ( $byte == 0x00 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($byte == 0) 2006 323 2329
150 2006 $zeros += 8;
151 2006 next;
152 }
153  
154 # count bits, use a pre-calculated table
155 323 $zeros += $nlz8[$byte];
156 323 last;
157 }
158  
159 430 return $zeros;
160 }
161  
162 # number of common leading bits
163 sub _common_prefix {
164 430 ▶ my ( $base_n, $last_n ) = @_;
Subroutine _common_prefix: called CC=1 SCAR=0.0
165 430 return _leading_zeros( $base_n ^ $last_n );
166 }
167  
168 # recursion ahead
169 # end condition: is_cidr
170 # split the range in the middle
171 # call both halves recursively
172 #
173 sub _to_cidrs_rec {
174 23 ▶ my ( $self, $buf ) = @_;
Subroutine _to_cidrs_rec: called CC=3 SCAR=11.0
175  
176 23 ▶ if ( $self->is_cidr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_cidr) 16 7 23
177 16 push @$buf, $self;
178 16 return $buf;
179 }
180  
181 7 my $base_ip = $self->{base};
182 7 my $last_ip = $self->{last};
183  
184 7 my $base_n = $self->{base}->bytes;
185 7 my $last_n = $self->{last}->bytes;
186  
187 7 my $pfx = _common_prefix( $base_n, $last_n );
188 7 my $bits = 32;
189 7 ▶ $bits = 128 if $self->version == 6;
Branch: 1 branch
BranchTrueFalseTotal
if $self->version == 6 1 6 7
190  
191 # make next mask
192 7 my $mask_n = _make_mask_n( $pfx + 1, $bits );
193  
194 # split range with new mask
195 7 my $mid_last_n = _make_last_n( $base_n, $mask_n );
196 7 my $mid_base_n = _make_base_n( $last_n, $mask_n );
197  
198 # make IPs from bitstring
199 7 my $mid_last_ip = Net::IPAM::IP->new_from_bytes($mid_last_n);
200 7 my $mid_base_ip = Net::IPAM::IP->new_from_bytes($mid_base_n);
201  
202 # make two new blocks
203 7 my $b1 = bless {}, ref $self;
204 7 $b1->{base} = $base_ip;
205 7 $b1->{last} = $mid_last_ip;
206  
207 7 my $b2 = bless {}, ref $self;
208 7 $b2->{base} = $mid_base_ip;
209 7 $b2->{last} = $last_ip;
210  
211 # make rec-descent call with both halves
212 7 $buf = _to_cidrs_rec( $b1, $buf );
213 7 $buf = _to_cidrs_rec( $b2, $buf );
214  
215 7 return $buf;
216 }
217  
218 # returns true if base and last forms a CIDR range
219 sub _is_cidr {
220 248 ▶ my $self = shift;
Subroutine _is_cidr: called CC=2 SCAR=6.9
221  
222 248 ▶ if ( $self->version == 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->version == 4) 142 106 248
223 142 return _is_cidr4( $self->{base}->bytes, $self->{last}->bytes );
224 }
225  
226 106 return _is_cidr6( $self->{base}->bytes, $self->{last}->bytes );
227 }
228  
229 sub _is_cidr4 {
230 142 ▶ my ( $base_n, $last_n ) = @_;
Subroutine _is_cidr4: called CC=2 SCAR=6.9
231  
232 # get the mask
233 142 my $pfx = _common_prefix( $base_n, $last_n );
234 142 my $mask_n = _strip_to_32_bits( $table_mask_n[$pfx] );
235  
236 # apply mask to base and last as AND and OR
237 # and check for all zeros and all ones => it's a CIDR
238 142 my $is_all_zeros = ( $base_n ^ ( $base_n & $mask_n ) ) eq _strip_to_32_bits( $table_mask_n[0] );
239 142 my $is_all_ones = ( $last_n | $mask_n ) eq _strip_to_32_bits( $table_mask_n[128] );
240  
241 142 ▶ return $is_all_zeros && $is_all_ones;
Condition100%3/3
$is_all_zeros && $is_all_ones
!ll&&!rl&&r
197116
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
242 }
243  
244 sub _is_cidr6 {
245 106 ▶ my ( $base_n, $last_n ) = @_;
Subroutine _is_cidr6: called CC=2 SCAR=6.9
246  
247 # get the mask
248 106 my $pfx = _common_prefix( $base_n, $last_n );
249 106 my $mask_n = $table_mask_n[$pfx];
250  
251 # apply mask to base and last as AND and OR
252 # and check for all zeros and all ones => it's a CIDR
253 106 my $is_all_zeros = ( $base_n ^ ( $base_n & $mask_n ) ) eq $table_mask_n[0];
254 106 my $is_all_ones = ( $last_n | $mask_n ) eq $table_mask_n[128];
255  
256 106 ▶ return $is_all_zeros && $is_all_ones;
Condition100%3/3
$is_all_zeros && $is_all_ones
!ll&&!rl&&r
6991
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
257 }
258  
259 # base = addr & netMask
260 sub _make_base_n {
261 233 ▶ my ( $addr_n, $mask_n ) = @_;
Subroutine _make_base_n: called CC=1 SCAR=0.0
262 233 return $addr_n & $mask_n;
263 }
264  
265 # last = addr | hostMask
266 sub _make_last_n {
267 242 ▶ my ( $addr_n, $mask_n ) = @_;
Subroutine _make_last_n: called CC=1 SCAR=0.0
268 242 return $addr_n | ~$mask_n;
269 }
270  
271 # cut off the bits after 32, used for IPv4
272 516 ▶sub _strip_to_32_bits { return $_[0] & "\xff\xff\xff\xff" }
Subroutine _strip_to_32_bits: called CC=1 SCAR=0.0
273  
274 # make CIDR mask from bits:
275 # (24, 32) => 0xffff_ff00
276 # (56, 128) => 0xffff_ffff_ffff_ff00_0000_0000_0000_0000
277 #
278 sub _make_mask_n {
279 230 ▶ my ( $n, $bits ) = @_;
Subroutine _make_mask_n: called CC=2 SCAR=6.9
280 230 my $mask_n = $table_mask_n[$n];
281 #
282 # cut to first 32 bits
283 230 ▶ if ( $bits == 32 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bits == 32) 90 140 230
284 90 return _strip_to_32_bits($mask_n);
285 }
286 140 return $mask_n;
287 }
288  
289 sub _get_mask_n {
290 2 ▶ my ( $base_ip, $last_ip ) = @_;
Subroutine _get_mask_n: called CC=2 SCAR=7.0
291  
292 2 my $pfx = _common_prefix( $base_ip->bytes, $last_ip->bytes );
293  
294 2 my $bits = 32;
295 2 ▶ $bits = 128 if $base_ip->version == 6;
Branch: 1 branch
BranchTrueFalseTotal
if $base_ip->version == 6 0 2 2
296  
297 2 return _make_mask_n( $pfx, $bits );
298 }
299  
300 #############################
301 # pre-calc tables
302 #############################
303  
304 #<<< skip marker for perltidy
305  
306 # pre-calced masks for 0.0.0.0 - 255.255.255.255
307 # only IPv4 addresses representable as a sequence of 1 bits followed by 0 bits
308 # are allowed as masks as input
309  
310 13 %valid_masks4 = (
311 "\x00\x00\x00\x00" => 0, "\x80\x00\x00\x00" => 1, "\xc0\x00\x00\x00" => 2,
312 "\xe0\x00\x00\x00" => 3, "\xf0\x00\x00\x00" => 4, "\xf8\x00\x00\x00" => 5,
313 "\xfc\x00\x00\x00" => 6, "\xfe\x00\x00\x00" => 7, "\xff\x00\x00\x00" => 8,
314 "\xff\x80\x00\x00" => 9, "\xff\xc0\x00\x00" => 10, "\xff\xe0\x00\x00" => 11,
315 "\xff\xf0\x00\x00" => 12, "\xff\xf8\x00\x00" => 13, "\xff\xfc\x00\x00" => 14,
316 "\xff\xfe\x00\x00" => 15, "\xff\xff\x00\x00" => 16, "\xff\xff\x80\x00" => 17,
317 "\xff\xff\xc0\x00" => 18, "\xff\xff\xe0\x00" => 19, "\xff\xff\xf0\x00" => 20,
318 "\xff\xff\xf8\x00" => 21, "\xff\xff\xfc\x00" => 22, "\xff\xff\xfe\x00" => 23,
319 "\xff\xff\xff\x00" => 24, "\xff\xff\xff\x80" => 25, "\xff\xff\xff\xc0" => 26,
320 "\xff\xff\xff\xe0" => 27, "\xff\xff\xff\xf0" => 28, "\xff\xff\xff\xf8" => 29,
321 "\xff\xff\xff\xfc" => 30, "\xff\xff\xff\xfe" => 31, "\xff\xff\xff\xff" => 32,
322 );
323  
324 # pre-calced CIDR masks for /0 .. /128,
325 # e.g.
326 # $table_mask_n[3] == "\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
327 # $table_mask_n[64] == "\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00"
328 # $table_mask_n[128] == "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
329  
330 13 @table_mask_n = (
331 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
332 "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
333 "\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
334 "\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
335 "\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
336 "\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
337 "\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
338 "\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
339 "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
340 "\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
341 "\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
342 "\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
343 "\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
344 "\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
345 "\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
346 "\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
347 "\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
348 "\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
349 "\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
350 "\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
351 "\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
352 "\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
353 "\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
354 "\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
355 "\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
356 "\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
357 "\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
358 "\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
359 "\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
360 "\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
361 "\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
362 "\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
363 "\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
364 "\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
365 "\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
366 "\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
367 "\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
368 "\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
369 "\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
370 "\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
371 "\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
372 "\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
373 "\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
374 "\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
375 "\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
376 "\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
377 "\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
378 "\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
379 "\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
380 "\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00",
381 "\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00",
382 "\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00",
383 "\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00",
384 "\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00",
385 "\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00",
386 "\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00",
387 "\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00",
388 "\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00",
389 "\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00",
390 "\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00",
391 "\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00\x00",
392 "\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00",
393 "\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00",
394 "\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00",
395 "\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00",
396 "\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00",
397 "\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00",
398 "\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00",
399 "\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x00",
400 "\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00",
401 "\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00",
402 "\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00",
403 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00",
404 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00",
405 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00",
406 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00",
407 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00",
408 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00",
409 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00",
410 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00",
411 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00",
412 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00",
413 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00",
414 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00",
415 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00",
416 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00",
417 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00",
418 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00",
419 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00",
420 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00",
421 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00",
422 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00",
423 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00",
424 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00",
425 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00",
426 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00",
427 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00",
428 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00",
429 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00",
430 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00",
431 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00",
432 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00",
433 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00",
434 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00",
435 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00",
436 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00",
437 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00",
438 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00",
439 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00",
440 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00",
441 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00",
442 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00",
443 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00",
444 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00",
445 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00",
446 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00",
447 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00",
448 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00",
449 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00",
450 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00",
451 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00",
452 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80",
453 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0",
454 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0",
455 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0",
456 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8",
457 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc",
458 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe",
459 "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",
460 );
461  
462 # pre-calced 'number of leading zeros' for byte values 0x00 - 0xff
463 # e.g.
464 # $nlz[0] == 8 # 0b0000_0000
465 # $nlz[1] == 7 # 0b0000_0001
466 # $nlz[64] == 1 # 0b0100_0000
467 # $nlz[128] == 0 # 0b1000_0000
468  
469 13 @nlz8 = (
470 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
471 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
472 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
473 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
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, # 80..9f
475 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
476 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
477 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
478 );
479  
480 ####################################
481 #>>> end of skip marker for perltidy
482 ####################################
483  
484 =head1 AUTHOR
485  
486 Karl Gaissmaier, C<< <karl.gaissmaier(at)uni-ulm.de> >>
487  
488 =head1 LICENSE AND COPYRIGHT
489  
490 This software is copyright (c) 2020-2021 by Karl Gaissmaier.
491  
492 This is free software; you can redistribute it and/or modify it under
493 the same terms as the Perl 5 programming language system itself.
494  
495 =cut
496  
497 13 1;
« Build ↑ Summary