mirror of
https://github.com/ZoneTree/ZoneTree.git
synced 2026-10-22 09:23:38 +08:00
Fix multi segment incorrect key meta data issue.
This commit is contained in:
@@ -308,19 +308,47 @@ public sealed class MultiSectorDiskSegment<TKey, TValue> : IDiskSegment<TKey, TV
|
||||
{
|
||||
var off = 0;
|
||||
var sectorIndex = 0;
|
||||
while (off + Sectors[sectorIndex].Length <= index)
|
||||
var len = Sectors[sectorIndex].Length;
|
||||
while (off + len <= index)
|
||||
{
|
||||
off += Sectors[sectorIndex].Length;
|
||||
off += len;
|
||||
++sectorIndex;
|
||||
len = Sectors[sectorIndex].Length;
|
||||
}
|
||||
var localIndex = index - off;
|
||||
|
||||
if (localIndex == 0)
|
||||
return SectorKeys[sectorIndex*2];
|
||||
if (localIndex == len - 1)
|
||||
return SectorKeys[sectorIndex * 2 + 1];
|
||||
|
||||
var key = Sectors[sectorIndex].GetKey(localIndex);
|
||||
return key;
|
||||
}
|
||||
|
||||
public TValue GetValue(int index)
|
||||
{
|
||||
var off = 0;
|
||||
var sectorIndex = 0;
|
||||
var len = Sectors[sectorIndex].Length;
|
||||
while (off + len <= index)
|
||||
{
|
||||
off += len;
|
||||
++sectorIndex;
|
||||
len = Sectors[sectorIndex].Length;
|
||||
}
|
||||
var localIndex = index - off;
|
||||
|
||||
if (localIndex == 0)
|
||||
return SectorValues[sectorIndex * 2];
|
||||
if (localIndex == len - 1)
|
||||
return SectorValues[sectorIndex * 2 + 1];
|
||||
|
||||
return Sectors[sectorIndex].GetValue(localIndex);
|
||||
}
|
||||
|
||||
public int GetLastSmallerOrEqualPosition(in TKey key)
|
||||
{
|
||||
var sparseArrayLength = SectorKeys.Length;
|
||||
(var left, var found) = SearchLastSmallerOrEqualPositionInSparseArray(in key);
|
||||
var sectorIndex = left / 2;
|
||||
var isStartOfSector = left % 2 == 0 ? 1 : 0;
|
||||
@@ -359,19 +387,6 @@ public sealed class MultiSectorDiskSegment<TKey, TValue> : IDiskSegment<TKey, TV
|
||||
return new SeekableIterator<TKey, TValue>(this);
|
||||
}
|
||||
|
||||
public TValue GetValue(int index)
|
||||
{
|
||||
var off = 0;
|
||||
var sectorIndex = 0;
|
||||
while (off + Sectors[sectorIndex].Length <= index)
|
||||
{
|
||||
off += Sectors[sectorIndex].Length;
|
||||
++sectorIndex;
|
||||
}
|
||||
var localIndex = index - off;
|
||||
return Sectors[sectorIndex].GetValue(localIndex);
|
||||
}
|
||||
|
||||
public void InitSparseArray(int size)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -155,10 +155,10 @@ public sealed class MultiSectorDiskSegmentCreator<TKey, TValue> : IDiskSegmentCr
|
||||
{
|
||||
var len = Sectors.Count * 2;
|
||||
bw.Write(len);
|
||||
for (var i = 0; i < len; i += 2)
|
||||
for (var i = 0; i < len; ++i)
|
||||
{
|
||||
var a = i / 2;
|
||||
var b = a + 1;
|
||||
var a = i++;
|
||||
var b = i;
|
||||
var k1 = SectorKeys[a];
|
||||
var bytes = KeySerializer.Serialize(k1);
|
||||
bw.Write(bytes.Length);
|
||||
@@ -175,10 +175,10 @@ public sealed class MultiSectorDiskSegmentCreator<TKey, TValue> : IDiskSegmentCr
|
||||
{
|
||||
var len = Sectors.Count * 2;
|
||||
bw.Write(len);
|
||||
for (var i = 0; i < len; i += 2)
|
||||
for (var i = 0; i < len; ++i)
|
||||
{
|
||||
var a = i / 2;
|
||||
var b = a + 1;
|
||||
var a = i++;
|
||||
var b = i;
|
||||
var v1 = SectorValues[a];
|
||||
var bytes = ValueSerializer.Serialize(v1);
|
||||
bw.Write(bytes.Length);
|
||||
|
||||
Reference in New Issue
Block a user