cidr-tools 12.1.0 → 12.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +51 -49
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -241,17 +241,19 @@ function subparts4(pStart, pEnd, output) {
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
function subparts6(pStart, pEnd, output) {
|
|
244
|
+
const fullSize = pEnd - pStart + 1n;
|
|
245
|
+
const startLowBit = pStart & -pStart;
|
|
246
|
+
if ((fullSize & fullSize - 1n) === 0n && (startLowBit === 0n || startLowBit >= fullSize)) {
|
|
247
|
+
output.push(stringifyIp({
|
|
248
|
+
number: pStart,
|
|
249
|
+
version: 6
|
|
250
|
+
}) + prefixStrings[129 - bigintBitLength(fullSize)]);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
244
253
|
let start = pStart;
|
|
245
254
|
while (start <= pEnd) {
|
|
246
255
|
const size = pEnd - start + 1n;
|
|
247
256
|
const lowBit = start & -start;
|
|
248
|
-
if ((size & size - 1n) === 0n && (lowBit === 0n || lowBit >= size)) {
|
|
249
|
-
output.push(stringifyIp({
|
|
250
|
-
number: start,
|
|
251
|
-
version: 6
|
|
252
|
-
}) + prefixStrings[129 - bigintBitLength(size)]);
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
257
|
const blockSize = lowBit !== 0n && lowBit <= size ? lowBit : biggestPowerOfTwo(size);
|
|
256
258
|
output.push(stringifyIp({
|
|
257
259
|
number: start,
|
|
@@ -547,60 +549,60 @@ function containsCidr(a, b) {
|
|
|
547
549
|
}
|
|
548
550
|
if (v4b.length > 0) {
|
|
549
551
|
if (v4a.length === 0) return false;
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
552
|
+
let sorted = false;
|
|
553
|
+
for (const target of v4b) {
|
|
554
|
+
const ts = target.start, te = target.end;
|
|
555
|
+
let covered = false;
|
|
556
|
+
for (const iv of v4a) if (iv.start <= ts && iv.end >= te) {
|
|
557
|
+
covered = true;
|
|
555
558
|
break;
|
|
556
559
|
}
|
|
557
|
-
if (
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
for (const
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
} else hi = mid - 1;
|
|
560
|
+
if (covered) continue;
|
|
561
|
+
if (!sorted) {
|
|
562
|
+
v4a.sort(cmpV4Start);
|
|
563
|
+
sorted = true;
|
|
564
|
+
}
|
|
565
|
+
let cur = ts;
|
|
566
|
+
for (const iv of v4a) {
|
|
567
|
+
if (iv.start > cur) break;
|
|
568
|
+
if (iv.end >= cur) {
|
|
569
|
+
if (iv.end >= te) {
|
|
570
|
+
covered = true;
|
|
571
|
+
break;
|
|
572
|
+
}
|
|
573
|
+
cur = iv.end + 1;
|
|
572
574
|
}
|
|
573
|
-
if (idx < 0 || maxEnd[idx] < target.end) return false;
|
|
574
575
|
}
|
|
576
|
+
if (!covered) return false;
|
|
575
577
|
}
|
|
576
578
|
}
|
|
577
579
|
if (v6b.length > 0) {
|
|
578
580
|
if (v6a.length === 0) return false;
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
581
|
+
let sorted = false;
|
|
582
|
+
for (const target of v6b) {
|
|
583
|
+
const ts = target.start, te = target.end;
|
|
584
|
+
let covered = false;
|
|
585
|
+
for (const iv of v6a) if (iv.start <= ts && iv.end >= te) {
|
|
586
|
+
covered = true;
|
|
584
587
|
break;
|
|
585
588
|
}
|
|
586
|
-
if (
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
for (const
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
} else hi = mid - 1;
|
|
589
|
+
if (covered) continue;
|
|
590
|
+
if (!sorted) {
|
|
591
|
+
v6a.sort(cmpV6Start);
|
|
592
|
+
sorted = true;
|
|
593
|
+
}
|
|
594
|
+
let cur = ts;
|
|
595
|
+
for (const iv of v6a) {
|
|
596
|
+
if (iv.start > cur) break;
|
|
597
|
+
if (iv.end >= cur) {
|
|
598
|
+
if (iv.end >= te) {
|
|
599
|
+
covered = true;
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
602
|
+
cur = iv.end + 1n;
|
|
601
603
|
}
|
|
602
|
-
if (idx < 0 || maxEnd[idx] < target.end) return false;
|
|
603
604
|
}
|
|
605
|
+
if (!covered) return false;
|
|
604
606
|
}
|
|
605
607
|
}
|
|
606
608
|
return true;
|