public void Write(Entry entry) { var value = _converter.Convert(entry); long offset; if (!_store.TryWrite(value, out offset)) throw new OutOfSpaceException(); entry.Offset = offset; }
public void RemoveTest() { var entry = new Entry { Key = new Int32Key(1), ValueOffset = 0, ValueLength = 200 }; var store = new FakeBinaryStore(EntryBinaryConverter.Instance.Convert(entry)); bool isFragmented; var key = new Int32Key(1); var tableOfContent = TableOfContent.From(store, out isFragmented); Assert.IsFalse(isFragmented); Assert.IsTrue(tableOfContent.Contains(key)); Assert.IsTrue(tableOfContent.TryRemove(key)); Assert.IsFalse(tableOfContent.Contains(key)); tableOfContent = TableOfContent.From(store, out isFragmented); Assert.IsTrue(isFragmented); Assert.IsFalse(tableOfContent.Contains(key)); }
public bool TryGetNext(out Entry entry) { if (_data.Length <= _index) { entry = null; return false; } if (!EntryBinaryConverter.IsActive(_data, _index)) { entry = null; _isFragmented = true; return false; } entry = _converter.Convert(_data, _index); entry.Offset = _start + _index; _index += EntryBinaryConverter.GetLength(entry.Key); return true; }
public void AddMultileAndRemoveTest() { var entry = new Entry { Key = new Int32Key(1), ValueOffset = 0, ValueLength = 200 }; var store = new FakeBinaryStore(EntryBinaryConverter.Instance.Convert(entry)); bool isFragmented; var tableOfContent = TableOfContent.From(store, out isFragmented); Assert.IsFalse(isFragmented); tableOfContent.Add(new Int32Key(2), 200, 215); tableOfContent.Add(new Int32Key(3), 415, 215); tableOfContent.Add(new Int32Key(4), 630, 230); tableOfContent.Add(new Int32Key(5), 860, 640); tableOfContent.Add(new Int32Key(6), 1500, 500); Assert.AreEqual(22 * 6, store.Length); Assert.AreEqual(22 * 6, store.CurrentOffset); var key1 = new Int32Key(1); var key2 = new Int32Key(2); var key3 = new Int32Key(3); Assert.IsTrue(tableOfContent.Contains(key1)); Assert.IsTrue(tableOfContent.Contains(key2)); Assert.IsTrue(tableOfContent.Contains(key3)); Assert.IsTrue(tableOfContent.TryRemove(key2)); Assert.IsTrue(tableOfContent.Contains(key1)); Assert.IsFalse(tableOfContent.Contains(key2)); Assert.IsTrue(tableOfContent.Contains(key3)); Assert.IsTrue(tableOfContent.TryRemove(key3)); Assert.IsTrue(tableOfContent.Contains(key1)); Assert.IsFalse(tableOfContent.Contains(key2)); Assert.IsFalse(tableOfContent.Contains(key3)); tableOfContent = TableOfContent.From(store, out isFragmented); Assert.IsTrue(isFragmented); Assert.IsTrue(tableOfContent.Contains(key1)); Assert.IsFalse(tableOfContent.Contains(key2)); Assert.IsFalse(tableOfContent.Contains(key3)); }
public bool TryReserve(IKey key, out Entry entry) { entry = new Entry { Key = key, IsReserved = true }; if (!_entries.TryAdd(key, entry)) { entry = null; return false; } return true; }
public void Enable(Entry entry) { entry.IsReserved = false; _entryWriter.Write(entry); }
public void WriteRemove(Entry entry) { var offset = entry.Offset + EntryBinaryConverter.IsActiveValueOffset; var data = BitConverter.GetBytes(false); _store.Write(offset, data); }
byte[] IStorageManagerService.GetContent(Entry entry) { return _store.Read(entry.ValueOffset, entry.ValueLength); }