public long GetKeyValueCount() { if (_prefixKeyCount >= 0) { return(_prefixKeyCount); } if (_prefix.Length == 0) { _prefixKeyCount = ArtRoot.GetCount(); return(_prefixKeyCount); } CalcPrefixKeyStart(); if (_prefixKeyStart < 0) { _prefixKeyCount = 0; return(0); } if (_cursor2 == null) { _cursor2 = ArtRoot.CreateCursor(); } _cursor2.FindLast(_prefix); _prefixKeyCount = _cursor2.CalcIndex() - _prefixKeyStart + 1; return(_prefixKeyCount); }
public long CalcDistance(ICursor to) { if (_rootNode != ((Cursor)to)._rootNode) { throw new ArgumentException("Cursor must be from same transaction", nameof(to)); } return(to.CalcIndex() - CalcIndex()); }
public long GetKeyIndex() { if (_keyIndex < 0) { if (!_cursor.IsValid()) { return(-1); } _keyIndex = _cursor.CalcIndex(); } CalcPrefixKeyStart(); return(_keyIndex - _prefixKeyStart); }
void CalcPrefixKeyStart() { if (_prefixKeyStart >= 0) { return; } if (_cursor2 == null) { _cursor2 = BTreeRoot.CreateCursor(); } if (_cursor2.FindFirst(_prefix)) { _prefixKeyStart = _cursor2.CalcIndex(); } else { _prefixKeyStart = -1; } }
public void InvalidCursorBehaviour() { Assert.Equal(-1, _cursor.CalcIndex()); }
public void MultipleInsertsInSingleTransaction() { var val = GetSampleValue().ToArray(); var key = new byte[1]; for (var i = 0; i < 256; i++) { key[0] = (byte)i; Assert.True(_cursor.Upsert(key, val)); Assert.Equal(i, _cursor.CalcIndex()); Assert.Equal(i + 1, _root.GetCount()); Assert.Equal(key.Length, _cursor.GetKeyLength()); Assert.Equal(key, _cursor.GetKeyAsArray()); Assert.Equal(val.Length, _cursor.GetValueLength()); Assert.Equal(val, _cursor.GetValue().ToArray()); for (var j = 0; j < 256; j++) { key[0] = (byte)j; Assert.Equal(j <= i, _cursor.FindExact(key)); } } key = new byte[2]; key[0] = 20; for (var j = 0; j < 256; j++) { key[1] = (byte)j; Assert.False(_cursor.FindExact(key)); } for (var i = 0; i < 256; i++) { key[1] = (byte)i; Assert.True(_cursor.Upsert(key, val)); Assert.Equal(256 + i + 1, _root.GetCount()); Assert.Equal(20 + 1 + i, _cursor.CalcIndex()); Assert.Equal(key.Length, _cursor.GetKeyLength()); Assert.Equal(key, _cursor.GetKeyAsArray()); Assert.Equal(val.Length, _cursor.GetValueLength()); Assert.Equal(val, _cursor.GetValue().ToArray()); for (var j = 0; j < 256; j++) { key[1] = (byte)j; Assert.Equal(j <= i, _cursor.FindExact(key)); } } Assert.False(_cursor.Upsert(key, val)); Assert.Equal(key.Length, _cursor.GetKeyLength()); Assert.Equal(key, _cursor.GetKeyAsArray()); Assert.Equal(val.Length, _cursor.GetValueLength()); Assert.Equal(val, _cursor.GetValue().ToArray()); val = GetSampleValue(1).ToArray(); Assert.False(_cursor.Upsert(key, val)); Assert.Equal(key.Length, _cursor.GetKeyLength()); Assert.Equal(key, _cursor.GetKeyAsArray()); Assert.Equal(val.Length, _cursor.GetValueLength()); Assert.Equal(val, _cursor.GetValue().ToArray()); val = GetSampleValue().ToArray(); Assert.False(_cursor.Upsert(key, val)); Assert.Equal(key.Length, _cursor.GetKeyLength()); Assert.Equal(key, _cursor.GetKeyAsArray()); Assert.Equal(val.Length, _cursor.GetValueLength()); Assert.Equal(val, _cursor.GetValue().ToArray()); }