本文整理汇总了C#中KeyValueDB类的典型用法代码示例。如果您正苦于以下问题:C# KeyValueDB类的具体用法?C# KeyValueDB怎么用?C# KeyValueDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyValueDB类属于命名空间,在下文中一共展示了KeyValueDB类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateDb
static ObjectDB CreateDb(IFileCollection fc)
{
var lowDb = new KeyValueDB(fc);
var db = new ObjectDB();
db.Open(lowDb, true);
return db;
}
开发者ID:Bobris,项目名称:BTDB,代码行数:7,代码来源:RelationSpeedTest.cs
示例2: AddingContinueToNewFileAfterReopenWithCorruption
public void AddingContinueToNewFileAfterReopenWithCorruption()
{
using (var fileCollection = new InMemoryFileCollection())
{
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(_key1, _key1);
tr.Commit();
}
}
fileCollection.SimulateCorruptionBySetSize(20 + 16);
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
Assert.Equal(0, tr.GetKeyValueCount());
tr.CreateOrUpdateKeyValue(Key2, Key2);
tr.Commit();
}
Console.WriteLine(db.CalcStats());
}
Assert.True(2 <= fileCollection.GetCount());
}
}
开发者ID:tomasdeml,项目名称:BTDB,代码行数:26,代码来源:KeyValueDBTest.cs
示例3: EmptyWritingTransaction
public void EmptyWritingTransaction()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartWritingTransaction().Result)
{
tr.Commit();
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:11,代码来源:KeyValueDBTest.cs
示例4: KeyValueDBTransaction
public KeyValueDBTransaction(KeyValueDB keyValueDB, IBTreeRootNode btreeRoot, bool writting, bool readOnly)
{
_preapprovedWritting = writting;
_readOnly = readOnly;
_keyValueDB = keyValueDB;
_btreeRoot = btreeRoot;
_prefix = BitArrayManipulation.EmptyByteArray;
_prefixKeyStart = 0;
_prefixKeyCount = -1;
_keyIndex = -1;
_keyValueDB.StartedUsingBTreeRoot(_btreeRoot);
}
开发者ID:tomasdeml,项目名称:BTDB,代码行数:12,代码来源:KeyValueDBTransaction.cs
示例5: FirstTransaction
public void FirstTransaction()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
Assert.True(tr.CreateOrUpdateKeyValue(ByteBuffer.NewAsync(_key1), ByteBuffer.NewAsync(new byte[0])));
tr.Commit();
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:12,代码来源:KeyValueDBTest.cs
示例6: CanGetSizeOfPair
public void CanGetSizeOfPair()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(ByteBuffer.NewAsync(_key1), ByteBuffer.NewAsync(new byte[1]));
var s = tr.GetStorageSizeOfCurrentKey();
Assert.Equal((uint)_key1.Length, s.Key);
Assert.Equal(1u, s.Value);
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:14,代码来源:KeyValueDBTest.cs
示例7: Main
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Need to have just one parameter with directory of ObjectDB");
return;
}
using (var dfc = new OnDiskFileCollection(args[0]))
using (var kdb = new KeyValueDB(dfc))
using (var odb = new ObjectDB())
{
odb.Open(kdb, false);
using (var tr = odb.StartTransaction())
{
var visitor = new ToStringVisitor();
var iterator = new ODBIterator(tr, visitor);
iterator.Iterate();
var text = visitor.ToString();
Console.WriteLine(text);
}
}
}
开发者ID:tomasdeml,项目名称:BTDB,代码行数:22,代码来源:Program.cs
示例8: AddingContinueToSameFileAfterReopen
public void AddingContinueToSameFileAfterReopen()
{
using (var fileCollection = new InMemoryFileCollection())
{
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(_key1, _key1);
tr.Commit();
}
}
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(Key2, Key2);
tr.Commit();
}
Console.WriteLine(db.CalcStats());
}
Assert.Equal(2u, fileCollection.GetCount()); // Log + Index
}
}
开发者ID:tomasdeml,项目名称:BTDB,代码行数:24,代码来源:KeyValueDBTest.cs
示例9: ALotOf5KbTransactionsWorks
public void ALotOf5KbTransactionsWorks()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
for (int i = 0; i < 5000; i++)
{
var key = new byte[5000];
using (var tr = db.StartTransaction())
{
key[0] = (byte)(i / 256);
key[1] = (byte)(i % 256);
Assert.True(tr.CreateKey(key));
tr.Commit();
}
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:18,代码来源:KeyValueDBTest.cs
示例10: AdvancedEraseRangeWorks
void AdvancedEraseRangeWorks(int createKeys, int removeStart, int removeCount)
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
var key = new byte[2];
using (var tr = db.StartTransaction())
{
for (int i = 0; i < createKeys; i++)
{
key[0] = (byte)(i / 256);
key[1] = (byte)(i % 256);
tr.CreateKey(key);
}
tr.Commit();
}
using (var tr = db.StartTransaction())
{
tr.EraseRange(removeStart, removeStart + removeCount - 1);
Assert.Equal(createKeys - removeCount, tr.GetKeyValueCount());
tr.Commit();
}
using (var tr = db.StartTransaction())
{
Assert.Equal(createKeys - removeCount, tr.GetKeyValueCount());
for (int i = 0; i < createKeys; i++)
{
key[0] = (byte)(i / 256);
key[1] = (byte)(i % 256);
if (i >= removeStart && i < removeStart + removeCount)
{
Assert.False(tr.FindExactKey(key), $"{i} should be removed");
}
else
{
Assert.True(tr.FindExactKey(key), $"{i} should be found");
}
}
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:41,代码来源:KeyValueDBTest.cs
示例11: SimpleEraseCurrentWorks
public void SimpleEraseCurrentWorks()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateKey(_key1);
tr.CreateKey(Key2);
tr.CreateKey(_key3);
tr.EraseCurrent();
Assert.True(tr.FindFirstKey());
Assert.Equal(_key1, tr.GetKeyAsByteArray());
Assert.True(tr.FindNextKey());
Assert.Equal(Key2, tr.GetKeyAsByteArray());
Assert.False(tr.FindNextKey());
Assert.Equal(2, tr.GetKeyValueCount());
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:20,代码来源:KeyValueDBTest.cs
示例12: PrefixWithFindPrevKeyWorks
public void PrefixWithFindPrevKeyWorks()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateKey(_key1);
tr.CreateKey(Key2);
tr.SetKeyPrefix(ByteBuffer.NewAsync(Key2, 0, 1));
Assert.True(tr.FindFirstKey());
Assert.False(tr.FindPreviousKey());
tr.Commit();
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:16,代码来源:KeyValueDBTest.cs
示例13: SimplePrefixWorks
public void SimplePrefixWorks()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateKey(_key1);
tr.CreateKey(Key2);
tr.CreateKey(_key3);
Assert.Equal(3, tr.GetKeyValueCount());
tr.SetKeyPrefix(ByteBuffer.NewAsync(_key1, 0, 3));
Assert.Equal(2, tr.GetKeyValueCount());
tr.FindFirstKey();
Assert.Equal(new byte[0], tr.GetKeyAsByteArray());
tr.FindLastKey();
Assert.Equal(_key3.Skip(3).ToArray(), tr.GetKeyAsByteArray());
tr.Commit();
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:21,代码来源:KeyValueDBTest.cs
示例14: MultipleTransactions2
public void MultipleTransactions2(int transactionCount)
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
var key = new byte[2 + transactionCount * 10];
for (int i = 0; i < transactionCount; i++)
{
key[0] = (byte)((transactionCount - i) / 256);
key[1] = (byte)((transactionCount - i) % 256);
using (var tr1 = db.StartTransaction())
{
tr1.CreateOrUpdateKeyValue(ByteBuffer.NewSync(key, 0, 2 + i * 10), ByteBuffer.NewEmpty());
if (i % 100 == 0 || i == transactionCount - 1)
{
for (int j = 0; j < i; j++)
{
key[0] = (byte)((transactionCount - j) / 256);
key[1] = (byte)((transactionCount - j) % 256);
Assert.Equal(FindResult.Exact, tr1.Find(ByteBuffer.NewSync(key, 0, 2 + j * 10)));
}
}
tr1.Commit();
}
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:27,代码来源:KeyValueDBTest.cs
示例15: CompressibleValueLoad
public void CompressibleValueLoad()
{
using (var fileCollection = new InMemoryFileCollection())
{
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateOrUpdateKeyValue(_key1, new byte[1000]);
Assert.Equal(new byte[1000], tr.GetValueAsByteArray());
tr.Commit();
}
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:15,代码来源:KeyValueDBTest.cs
示例16: ReadOnlyTransactionThrowsOnWriteAccess
public void ReadOnlyTransactionThrowsOnWriteAccess()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartReadOnlyTransaction())
{
Assert.Throws<BTDBTransactionRetryException>(() => tr.CreateKey(new byte[1]));
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:12,代码来源:KeyValueDBTest.cs
示例17: RepairsOnReopen
public void RepairsOnReopen()
{
using (var fileCollection = new InMemoryFileCollection())
{
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
tr.CreateKey(_key1);
tr.Commit();
}
using (var tr = db.StartTransaction())
{
tr.CreateKey(Key2);
tr.Commit();
}
using (var tr = db.StartTransaction())
{
tr.CreateKey(_key3);
// rollback
}
using (IKeyValueDB db2 = new KeyValueDB(fileCollection))
{
using (var tr = db2.StartTransaction())
{
Assert.True(tr.FindExactKey(_key1));
Assert.True(tr.FindExactKey(Key2));
Assert.False(tr.FindExactKey(_key3));
}
}
}
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
Assert.True(tr.FindExactKey(_key1));
Assert.True(tr.FindExactKey(Key2));
Assert.False(tr.FindExactKey(_key3));
}
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:42,代码来源:KeyValueDBTest.cs
示例18: AdvancedFindPreviousAndNextKeyWorks
public void AdvancedFindPreviousAndNextKeyWorks()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
var key = new byte[2];
const int keysCreated = 10000;
using (var tr = db.StartTransaction())
{
for (int i = 0; i < keysCreated; i++)
{
key[0] = (byte)(i / 256);
key[1] = (byte)(i % 256);
tr.CreateKey(key);
}
tr.Commit();
}
using (var tr = db.StartTransaction())
{
Assert.Equal(-1, tr.GetKeyIndex());
tr.FindExactKey(key);
Assert.Equal(keysCreated - 1, tr.GetKeyIndex());
for (int i = 1; i < keysCreated; i++)
{
Assert.True(tr.FindPreviousKey());
Assert.Equal(keysCreated - 1 - i, tr.GetKeyIndex());
}
Assert.False(tr.FindPreviousKey());
Assert.Equal(-1, tr.GetKeyIndex());
for (int i = 0; i < keysCreated; i++)
{
Assert.True(tr.FindNextKey());
Assert.Equal(i, tr.GetKeyIndex());
}
Assert.False(tr.FindNextKey());
Assert.Equal(-1, tr.GetKeyIndex());
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:39,代码来源:KeyValueDBTest.cs
示例19: SimpleFindNextKeyWorks
public void SimpleFindNextKeyWorks()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr1 = db.StartTransaction())
{
tr1.CreateKey(_key1);
tr1.CreateKey(Key2);
tr1.CreateKey(_key3);
tr1.Commit();
}
using (var tr2 = db.StartTransaction())
{
Assert.True(tr2.FindExactKey(_key3));
Assert.True(tr2.FindNextKey());
Assert.Equal(Key2, tr2.GetKeyAsByteArray());
Assert.False(tr2.FindNextKey());
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:21,代码来源:KeyValueDBTest.cs
示例20: FindKeyWithPreferPreviousKeyWorks
public void FindKeyWithPreferPreviousKeyWorks()
{
const int keyCount = 10000;
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartTransaction())
{
var key = new byte[100];
for (int i = 0; i < keyCount; i++)
{
key[0] = (byte)(i / 256);
key[1] = (byte)(i % 256);
tr.CreateKey(key);
}
tr.Commit();
}
using (var tr = db.StartTransaction())
{
var key = new byte[101];
for (int i = 0; i < keyCount; i++)
{
key[0] = (byte)(i / 256);
key[1] = (byte)(i % 256);
var findKeyResult = tr.Find(ByteBuffer.NewSync(key));
Assert.Equal(FindResult.Previous, findKeyResult);
Assert.Equal(i, tr.GetKeyIndex());
}
}
using (var tr = db.StartTransaction())
{
var key = new byte[99];
for (int i = 0; i < keyCount; i++)
{
key[0] = (byte)(i / 256);
key[1] = (byte)(i % 256);
var findKeyResult = tr.Find(ByteBuffer.NewSync(key));
if (i == 0)
{
Assert.Equal(FindResult.Next, findKeyResult);
Assert.Equal(i, tr.GetKeyIndex());
}
else
{
Assert.Equal(FindResult.Previous, findKeyResult);
Assert.Equal(i - 1, tr.GetKeyIndex());
}
}
}
}
}
开发者ID:Bobris,项目名称:BTDB,代码行数:51,代码来源:KeyValueDBTest.cs
注:本文中的KeyValueDB类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论