本文整理汇总了C#中BerkeleyDB.BTreeDatabaseConfig.SetCompression方法的典型用法代码示例。如果您正苦于以下问题:C# BTreeDatabaseConfig.SetCompression方法的具体用法?C# BTreeDatabaseConfig.SetCompression怎么用?C# BTreeDatabaseConfig.SetCompression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BerkeleyDB.BTreeDatabaseConfig
的用法示例。
在下文中一共展示了BTreeDatabaseConfig.SetCompression方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCompression
public void TestCompression()
{
testName = "TestCompression";
testHome = testFixtureHome + "/" + testName;
string btreeDBName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
BTreeDatabaseConfig cfg = new BTreeDatabaseConfig();
cfg.Creation = CreatePolicy.ALWAYS;
cfg.SetCompression(compress, decompress);
BTreeDatabase db = BTreeDatabase.Open(btreeDBName, cfg);
DatabaseEntry key, data;
char[] keyData = { 'A', 'A', 'A', 'A' };
byte[] dataData = new byte[20];
Random generator = new Random();
int i;
for (i = 0; i < 20000; i++) {
// Write random data
key = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes(keyData));
generator.NextBytes(dataData);
data = new DatabaseEntry(dataData);
db.Put(key, data);
// Bump the key. Rollover from Z to A if necessary
int j = keyData.Length;
do {
j--;
if (keyData[j]++ == 'Z')
keyData[j] = 'A';
} while (keyData[j] == 'A');
}
db.Close();
}
示例2: TestCompressionDefault
public void TestCompressionDefault()
{
testName = "TestCompressionDefault";
testHome = testFixtureHome + "/" + testName;
string btreeDBName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
BTreeDatabaseConfig cfg = new BTreeDatabaseConfig();
cfg.Creation = CreatePolicy.ALWAYS;
BTreeDatabase db = BTreeDatabase.Open(btreeDBName, cfg);
DatabaseEntry key, data;
char[] keyData = { 'A', 'A', 'A', 'A' };
byte[] dataData = new byte[20];
Random generator = new Random();
int i;
for (i = 0; i < 20000; i++) {
// Write random data
key = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes(keyData));
generator.NextBytes(dataData);
data = new DatabaseEntry(dataData);
db.Put(key, data);
// Bump the key. Rollover from Z to A if necessary
int j = keyData.Length;
do {
j--;
if (keyData[j]++ == 'Z')
keyData[j] = 'A';
} while (keyData[j] == 'A');
}
db.Close();
FileInfo dbInfo = new FileInfo(btreeDBName);
long uncompressedSize = dbInfo.Length;
Configuration.ClearDir(testHome);
cfg = new BTreeDatabaseConfig();
cfg.Creation = CreatePolicy.ALWAYS;
cfg.SetCompression();
db = BTreeDatabase.Open(btreeDBName, cfg);
keyData = new char[]{ 'A', 'A', 'A', 'A' };
for (i = 0; i < 20000; i++) {
// Write random data
key = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes(keyData));
generator.NextBytes(dataData);
data = new DatabaseEntry(dataData);
db.Put(key, data);
// Bump the key. Rollover from Z to A if necessary
int j = keyData.Length;
do {
j--;
if (keyData[j]++ == 'Z')
keyData[j] = 'A';
} while (keyData[j] == 'A');
}
Cursor dbc = db.Cursor();
foreach (KeyValuePair<DatabaseEntry, DatabaseEntry> kvp in dbc)
i--;
dbc.Close();
Assert.AreEqual(i, 0);
db.Close();
dbInfo = new FileInfo(btreeDBName);
Assert.Less(dbInfo.Length, uncompressedSize);
Console.WriteLine("Uncompressed: {0}", uncompressedSize);
Console.WriteLine("Compressed: {0}", dbInfo.Length);
Configuration.ClearDir(testHome);
cfg = new BTreeDatabaseConfig();
cfg.Creation = CreatePolicy.ALWAYS;
cfg.SetCompression();
db = BTreeDatabase.Open(btreeDBName, cfg);
for (i = 1023; i < 1124; i++){
key = new DatabaseEntry(BitConverter.GetBytes(i));
data = new DatabaseEntry(BitConverter.GetBytes(i + 3));
db.Put(key, data);
}
dbc = db.Cursor();
foreach (KeyValuePair<DatabaseEntry, DatabaseEntry> kvp in dbc){
int keyInt = BitConverter.ToInt32(kvp.Key.Data, 0);
int dataInt = BitConverter.ToInt32(kvp.Value.Data, 0);
Assert.AreEqual(3, dataInt - keyInt);
}
dbc.Close();
db.Close();
}
示例3: TestCompression
public void TestCompression()
{
testName = "TestCompression";
SetUpTest(true);
string btreeDBName = testHome + "/" + testName + ".db";
BTreeDatabaseConfig cfg = new BTreeDatabaseConfig();
cfg.Creation = CreatePolicy.ALWAYS;
cfg.SetCompression(compress, decompress);
BTreeDatabase db = BTreeDatabase.Open(btreeDBName, cfg);
DatabaseEntry key, data;
char[] keyData = { 'A', 'A', 'A', 'A' };
data = new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes("abcdefghij"));
int i;
for (i = 0; i < 2000; i++) {
// Write random data
key = new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes(keyData));
db.Put(key, data);
// Bump the key. Rollover from Z to A if necessary
int j = keyData.Length;
do {
j--;
if (keyData[j]++ == 'Z')
keyData[j] = 'A';
} while (keyData[j] == 'A');
}
db.Close();
}