-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Simple leaf page (#261) (#263) This reverts commit 9fbb48b. * Printing for tree structure * overflowing page added * overflowing * buckets slowly introduced * towards the overflow * stats * more * bit vectors and different lengths of overflow * format * overflow is optional * SlottedArray can store metadata * format * more * page lifecycle test asserted * more overflow pages; set refactored * DataPage enumerates leafs first, before flushing the biggest nibble down
- Loading branch information
Showing
38 changed files
with
1,848 additions
and
975 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using Paprika.Data; | ||
|
||
namespace Paprika.Tests.Data; | ||
|
||
public class BitVector1024Tests | ||
{ | ||
[Test] | ||
public void Set_reset() | ||
{ | ||
var v = new BitVector.Of1024(); | ||
|
||
for (int i = 0; i < BitVector.Of1024.Count; i++) | ||
{ | ||
v[i].Should().BeFalse(); | ||
v[i] = true; | ||
v[i].Should().BeTrue(); | ||
v[i] = false; | ||
v[i].Should().BeFalse(); | ||
} | ||
} | ||
|
||
[TestCase(0)] | ||
[TestCase(1)] | ||
[TestCase(64)] | ||
[TestCase(65)] | ||
[TestCase(BitVector.Of1024.Count - 1)] | ||
[TestCase(BitVector.Of1024.Count)] | ||
public void First_not_set(int set) | ||
{ | ||
var v = new BitVector.Of1024(); | ||
|
||
for (int i = 0; i < set; i++) | ||
{ | ||
v[i] = true; | ||
} | ||
|
||
v.FirstNotSet.Should().Be((ushort)set); | ||
} | ||
|
||
[TestCase(1, true)] | ||
[TestCase(BitVector.Of1024.Count, false)] | ||
public void Any_not_set(int set, bool anyNotSet) | ||
{ | ||
var v = new BitVector.Of1024(); | ||
|
||
for (int i = 0; i < set; i++) | ||
{ | ||
v[i] = true; | ||
} | ||
|
||
v.HasEmptyBits.Should().Be(anyNotSet); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using Paprika.Crypto; | ||
using Paprika.Data; | ||
|
||
namespace Paprika.Tests.Data; | ||
|
||
public class UshortSlottedArrayTests | ||
{ | ||
private const ushort Key0 = 14; | ||
private const ushort Key1 = 28; | ||
private const ushort Key2 = 31; | ||
|
||
private static ReadOnlySpan<byte> Data0 => new byte[] { 23 }; | ||
private static ReadOnlySpan<byte> Data1 => new byte[] { 29, 31 }; | ||
|
||
private static ReadOnlySpan<byte> Data2 => new byte[] { 37, 39 }; | ||
|
||
[Test] | ||
public void Set_Get_Delete_Get_AnotherSet() | ||
{ | ||
Span<byte> span = stackalloc byte[48]; | ||
var map = new UShortSlottedArray(span); | ||
|
||
map.SetAssert(Key0, Data0); | ||
|
||
map.GetAssert(Key0, Data0); | ||
|
||
map.DeleteAssert(Key0); | ||
map.GetShouldFail(Key0); | ||
|
||
// should be ready to accept some data again | ||
map.SetAssert(Key0, Data1, "Should have memory after previous delete"); | ||
map.GetAssert(Key0, Data1); | ||
} | ||
|
||
[Test] | ||
public void Defragment_when_no_more_space() | ||
{ | ||
// by trial and error, found the smallest value that will allow to put these two | ||
Span<byte> span = stackalloc byte[24]; | ||
var map = new UShortSlottedArray(span); | ||
|
||
map.SetAssert(Key0, Data0); | ||
map.SetAssert(Key1, Data1); | ||
|
||
map.DeleteAssert(Key0); | ||
|
||
map.SetAssert(Key2, Data2, "Should retrieve space by running internally the defragmentation"); | ||
|
||
// should contains no key0, key1 and key2 now | ||
map.GetShouldFail(Key0); | ||
|
||
map.GetAssert(Key1, Data1); | ||
map.GetAssert(Key2, Data2); | ||
} | ||
|
||
[Test] | ||
public void Update_in_situ() | ||
{ | ||
// by trial and error, found the smallest value that will allow to put these two | ||
Span<byte> span = stackalloc byte[48]; | ||
var map = new UShortSlottedArray(span); | ||
|
||
map.SetAssert(Key1, Data1); | ||
map.SetAssert(Key1, Data2); | ||
|
||
map.GetAssert(Key1, Data2); | ||
} | ||
|
||
[Test] | ||
public void Update_in_resize() | ||
{ | ||
// Update the value, with the next one being bigger. | ||
Span<byte> span = stackalloc byte[40]; | ||
var map = new UShortSlottedArray(span); | ||
|
||
map.SetAssert(Key0, Data0); | ||
map.SetAssert(Key0, Data2); | ||
|
||
map.GetAssert(Key0, Data2); | ||
} | ||
} | ||
|
||
file static class Extensions | ||
{ | ||
public static void SetAssert(this UShortSlottedArray map, ushort key, ReadOnlySpan<byte> data, | ||
string? because = null) | ||
{ | ||
map.TrySet(key, data).Should().BeTrue(because ?? "TrySet should succeed"); | ||
} | ||
|
||
public static void DeleteAssert(this UShortSlottedArray map, ushort key) | ||
{ | ||
map.Delete(key).Should().BeTrue("Delete should succeed"); | ||
} | ||
|
||
public static void GetAssert(this UShortSlottedArray map, ushort key, ReadOnlySpan<byte> expected) | ||
{ | ||
map.TryGet(key, out var actual).Should().BeTrue(); | ||
actual.SequenceEqual(expected).Should().BeTrue("Actual data should equal expected"); | ||
} | ||
|
||
public static void GetShouldFail(this UShortSlottedArray map, ushort key) | ||
{ | ||
map.TryGet(key, out var actual).Should().BeFalse("The key should not exist"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.