diff --git a/src/FlowtideDotNet.Core/Compute/FlxValueComparer.cs b/src/FlowtideDotNet.Core/Compute/FlxValueComparer.cs index 34fa4d797..b8339ce0f 100644 --- a/src/FlowtideDotNet.Core/Compute/FlxValueComparer.cs +++ b/src/FlowtideDotNet.Core/Compute/FlxValueComparer.cs @@ -60,7 +60,7 @@ public static int CompareTo(FlxValue a, FlxValue b) // Check for string comparison if (a.ValueType == FlexBuffers.Type.String) { - return string.Compare(a.AsString, b.AsString); + return FlxString.Compare(a.AsFlxString, b.AsFlxString); } if (a.ValueType == FlexBuffers.Type.Int) { diff --git a/src/FlowtideDotNet.Core/Flexbuffer/FlxValue.cs b/src/FlowtideDotNet.Core/Flexbuffer/FlxValue.cs index 10a098d49..3d2692af3 100644 --- a/src/FlowtideDotNet.Core/Flexbuffer/FlxValue.cs +++ b/src/FlowtideDotNet.Core/Flexbuffer/FlxValue.cs @@ -297,7 +297,38 @@ public bool AsBool throw new Exception($"Type {_type} is not convertible to bool"); } } - + + public FlxString AsFlxString + { + get + { + var span = _buffer.Span; + if (_type == Type.String) + { + var indirectOffset = ComputeIndirectOffset(span, _offset, _parentWidth); + var size = (int)ReadULong(span, indirectOffset - _byteWidth, _byteWidth); + var sizeWidth = (int)_byteWidth; + while (span[indirectOffset + size] != 0) + { + sizeWidth <<= 1; + size = (int)ReadULong(span, indirectOffset - sizeWidth, (byte)sizeWidth); + } + return new FlxString(span.Slice(indirectOffset, size)); + } + if (_type == Type.Key) + { + var indirectOffset = ComputeIndirectOffset(span, _offset, _parentWidth); + var size = 0; + while (indirectOffset + size < _buffer.Length && span[indirectOffset + size] != 0) + { + size++; + } + return new FlxString(span.Slice(indirectOffset, size)); + } + throw new InvalidOperationException("Can only be used on strings"); + } + } + public string AsString { get diff --git a/src/FlowtideDotNet.Storage/Tree/BPlusTreeOptions.cs b/src/FlowtideDotNet.Storage/Tree/BPlusTreeOptions.cs index 8e941c4c9..182ac4eaf 100644 --- a/src/FlowtideDotNet.Storage/Tree/BPlusTreeOptions.cs +++ b/src/FlowtideDotNet.Storage/Tree/BPlusTreeOptions.cs @@ -14,7 +14,7 @@ namespace FlowtideDotNet.Storage.Tree { public class BPlusTreeOptions { - public int BucketSize { get; set; } = 256; + public int BucketSize { get; set; } = 64; public required IComparer Comparer { get; set; }