void PackVIntIsOrderableForPositiveCore(long t) { var buf1 = new byte[9]; var o1 = 0; PackUnpack.PackVInt(buf1, ref o1, t - 1); var buf2 = new byte[9]; var o2 = 0; PackUnpack.PackVInt(buf2, ref o2, t); if (t >= int.MinValue && t <= int.MaxValue) { Assert.Equal(o2, PackUnpack.LengthVInt((int)t)); } Assert.Equal(o2, PackUnpack.LengthVInt(t)); Assert.Equal(o2, PackUnpack.LengthVInt(buf2, 0)); Assert.True(0 > BitArrayManipulation.CompareByteArray(buf1, o1, buf2, o2)); var o1A = 0; Assert.Equal(t - 1, PackUnpack.UnpackVInt(buf1, ref o1A)); Assert.Equal(o1, o1A); var o2A = 0; Assert.Equal(t, PackUnpack.UnpackVInt(buf2, ref o2A)); Assert.Equal(o2, o2A); }
public void Run(string dbDirectory, CancellationToken cancellationToken) { using var fc = new OnDiskFileCollection(dbDirectory); using var lowDb = new KeyValueDB(fc, new NoCompressionStrategy(), 2000); var values = new List <byte[]>(100); for (var i = 0; i < 100; i++) { values.Add(new byte[i]); } var rnd = new Random(); var mre = new ManualResetEvent(false); var t = Task.Run(async() => { var keyBuffer = new byte[10]; while (true) { using var tr = await lowDb.StartWritingTransaction(); for (var j = 0; j < 10000; j++) { var pos = 0; PackUnpack.PackVInt(keyBuffer, ref pos, j); tr.CreateOrUpdateKeyValue(keyBuffer.AsSpan(0, pos), values[rnd.Next(0, 99)]); if (cancellationToken.IsCancellationRequested) { return; } } Console.WriteLine("w "); tr.Commit(); mre.Set(); } }, cancellationToken); if (!cancellationToken.IsCancellationRequested) { mre.WaitOne(); } var r1 = StartReader(lowDb, "r1", 1, cancellationToken); var r2 = StartReader(lowDb, "r2", 10, cancellationToken); var r3 = StartReader(lowDb, "r3", 100, cancellationToken); Task.WaitAll(t, r1, r2, r3); }
public void WriteVInt64(long value) { var l = PackUnpack.LengthVInt(value); if (Pos + l > End) { FlushBuffer(); if (Pos + l > End) { var b = new byte[l]; int i = 0; PackUnpack.PackVInt(b, ref i, value); WriteBlock(b); return; } } PackUnpack.PackVInt(Buf, ref Pos, value); }