refactor: 增加边界数据支持

This commit is contained in:
Argo Zhang 2025-11-20 16:25:25 +08:00
parent af82b7e18e
commit a2778f9b98
1 changed files with 4 additions and 4 deletions

View File

@ -67,7 +67,7 @@ public class Searcher : ISearcher
var dataLen = 0; var dataLen = 0;
long dataPtr = 0; long dataPtr = 0;
while (l < h) while (l <= h)
{ {
int m = (int)(l + h) >> 1; int m = (int)(l + h) >> 1;
@ -76,18 +76,18 @@ public class Searcher : ISearcher
var s = buff.Span.Slice(0, length); var s = buff.Span.Slice(0, length);
var e = buff.Span.Slice(length, length); var e = buff.Span.Slice(length, length);
if (ByteCompare(ipBytes, s) == -1) if (ByteCompare(ipBytes, s) < 0)
{ {
h = m - 1; h = m - 1;
} }
else if (ByteCompare(ipBytes, e) == 1) else if (ByteCompare(ipBytes, e) > 0)
{ {
l = m + 1; l = m + 1;
} }
else else
{ {
dataLen = BinaryPrimitives.ReadUInt16LittleEndian(buff.Span.Slice(length * 2, 2)); dataLen = BinaryPrimitives.ReadUInt16LittleEndian(buff.Span.Slice(length * 2, 2));
dataPtr = BinaryPrimitives.ReadUInt32LittleEndian(buff.Span.Slice(length * 2 + 2)); dataPtr = BinaryPrimitives.ReadUInt32LittleEndian(buff.Span.Slice(length * 2 + 2, 4));
break; break;
} }
} }