本文整理汇总了C#中BerkeleyDB.HashDatabaseConfig类的典型用法代码示例。如果您正苦于以下问题:C# HashDatabaseConfig类的具体用法?C# HashDatabaseConfig怎么用?C# HashDatabaseConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HashDatabaseConfig类属于BerkeleyDB命名空间,在下文中一共展示了HashDatabaseConfig类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ConfigCase1
public void ConfigCase1(HashDatabaseConfig dbConfig)
{
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.Duplicates = DuplicatesPolicy.UNSORTED;
dbConfig.FillFactor = 10;
dbConfig.TableSize = 20;
dbConfig.PageSize = 4096;
}
开发者ID:gildafnai82,项目名称:craq,代码行数:8,代码来源:HashDatabaseTest.cs
示例2: GetHashDBAndCursor
public void GetHashDBAndCursor(string home, string name,
out HashDatabase db, out HashCursor cursor)
{
string dbFileName = home + "/" + name + ".db";
HashDatabaseConfig dbConfig = new HashDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
db = HashDatabase.Open(dbFileName, dbConfig);
cursor = db.Cursor();
}
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:9,代码来源:HashCursorTest.cs
示例3: TestConfigWithoutEnv
public override void TestConfigWithoutEnv()
{
testName = "TestConfigWithoutEnv";
SetUpTest(false);
XmlElement xmlElem = Configuration.TestSetUp(
testFixtureName, testName);
HashDatabaseConfig hashConfig = new HashDatabaseConfig();
Config(xmlElem, ref hashConfig, true);
Confirm(xmlElem, hashConfig, true);
}
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:10,代码来源:HashDatabaseConfigTest.cs
示例4: Confirm
public static void Confirm(XmlElement xmlElement,
HashDatabaseConfig hashDBConfig, bool compulsory)
{
DatabaseConfig dbConfig = hashDBConfig;
Confirm(xmlElement, dbConfig, compulsory);
// Confirm Hash database specific configuration.
Configuration.ConfirmCreatePolicy(xmlElement,
"Creation", hashDBConfig.Creation, compulsory);
Configuration.ConfirmDuplicatesPolicy(xmlElement,
"Duplicates", hashDBConfig.Duplicates, compulsory);
Configuration.ConfirmUint(xmlElement, "FillFactor",
hashDBConfig.FillFactor, compulsory);
Configuration.ConfirmUint(xmlElement, "NumElements",
hashDBConfig.TableSize, compulsory);
}
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:16,代码来源:HashDatabaseConfigTest.cs
示例5: Main
static void Main( string[] args )
{
try {
var cfg = new HashDatabaseConfig();
cfg.Duplicates = DuplicatesPolicy.UNSORTED;
cfg.Creation = CreatePolicy.IF_NEEDED;
cfg.CacheSize = new CacheInfo( 0, 64 * 1024, 1 );
cfg.PageSize = 8 * 1024;
Database db = HashDatabase.Open( "d:\\test.db", "hat_db", cfg );
Console.WriteLine("db opened");
var key = new DatabaseEntry();
var data = new DatabaseEntry();
key.Data = System.Text.Encoding.ASCII.GetBytes("key1");
data.Data = System.Text.Encoding.ASCII.GetBytes("val1");
try {
db.Put( key, data );
db.Put( key, data );
}
catch ( Exception ex ) {
Console.WriteLine( ex.Message );
}
using ( var dbc = db.Cursor() ) {
System.Text.ASCIIEncoding decode = new ASCIIEncoding();
/* Walk through the database and print out key/data pairs. */
Console.WriteLine( "All key : data pairs:" );
foreach ( KeyValuePair<DatabaseEntry, DatabaseEntry> p in dbc )
Console.WriteLine( "{0}::{1}",
decode.GetString( p.Key.Data ), decode.GetString( p.Value.Data ) );
}
db.Close();
Console.WriteLine( "db closed" );
}
catch ( Exception ex ) {
Console.WriteLine( ex.Message );
}
Console.ReadLine();
}
开发者ID:borntolead,项目名称:a2hat,代码行数:47,代码来源:Program.cs
示例6: Config
private void Config(HashDatabaseConfig cfg) {
base.Config(cfg);
/*
* Database.Config calls set_flags, but that does not get the Hash
* specific flags. No harm in calling it again.
*/
db.set_flags(cfg.flags);
if (cfg.BlobDir != null && cfg.Env == null)
db.set_blob_dir(cfg.BlobDir);
if (cfg.blobThresholdIsSet)
db.set_blob_threshold(cfg.BlobThreshold, 0);
if (cfg.HashFunction != null)
HashFunction = cfg.HashFunction;
// The duplicate comparison function cannot change.
if (cfg.DuplicateCompare != null)
DupCompare = cfg.DuplicateCompare;
if (cfg.fillFactorIsSet)
db.set_h_ffactor(cfg.FillFactor);
if (cfg.nelemIsSet)
db.set_h_nelem(cfg.TableSize);
if (cfg.HashComparison != null)
Compare = cfg.HashComparison;
if (cfg.partitionIsSet) {
nparts = cfg.NParts;
Partition = cfg.Partition;
if (Partition == null)
doPartitionRef = null;
else
doPartitionRef = new BDB_PartitionDelegate(doPartition);
partitionKeys = cfg.PartitionKeys;
IntPtr[] ptrs = null;
if (partitionKeys != null) {
int size = (int)nparts - 1;
ptrs = new IntPtr[size];
for (int i = 0; i < size; i++) {
ptrs[i] = DBT.getCPtr(
DatabaseEntry.getDBT(partitionKeys[i])).Handle;
}
}
db.set_partition(nparts, ptrs, doPartitionRef);
}
}
开发者ID:rohitlodha,项目名称:DenverDB,代码行数:46,代码来源:HashDatabase.cs
示例7: Config
private void Config(HashDatabaseConfig cfg) {
base.Config(cfg);
/*
* Database.Config calls set_flags, but that doesn't get the Hash
* specific flags. No harm in calling it again.
*/
db.set_flags(cfg.flags);
if (cfg.HashFunction != null)
HashFunction = cfg.HashFunction;
// The duplicate comparison function cannot change.
if (cfg.DuplicateCompare != null)
DupCompare = cfg.DuplicateCompare;
if (cfg.fillFactorIsSet)
db.set_h_ffactor(cfg.FillFactor);
if (cfg.nelemIsSet)
db.set_h_nelem(cfg.TableSize);
if (cfg.HashComparison != null)
Compare = cfg.HashComparison;
}
开发者ID:gildafnai82,项目名称:craq,代码行数:21,代码来源:HashDatabase.cs
示例8: Config
public static void Config(XmlElement xmlElement,
ref HashDatabaseConfig hashDBConfig, bool compulsory)
{
uint fillFactor = new uint();
uint numElements = new uint();
DatabaseConfig dbConfig = hashDBConfig;
Config(xmlElement, ref dbConfig, compulsory);
// Configure specific fields/properties of Hash db
Configuration.ConfigCreatePolicy(xmlElement,
"Creation", ref hashDBConfig.Creation,
compulsory);
Configuration.ConfigDuplicatesPolicy(xmlElement,
"Duplicates", ref hashDBConfig.Duplicates,
compulsory);
if (Configuration.ConfigUint(xmlElement, "FillFactor",
ref fillFactor, compulsory))
hashDBConfig.FillFactor = fillFactor;
if (Configuration.ConfigUint(xmlElement, "NumElements",
ref numElements, compulsory))
hashDBConfig.TableSize = numElements;
}
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:22,代码来源:HashDatabaseConfigTest.cs
示例9: Open
/// <summary>
/// Instantiate a new HashDatabase object and open the database
/// represented by <paramref name="Filename"/>.
/// </summary>
/// <remarks>
/// <para>
/// If <paramref name="Filename"/> is null, the database is strictly
/// temporary and cannot be opened by any other thread of control, thus
/// the database can only be accessed by sharing the single database
/// object that created it, in circumstances where doing so is safe.
/// </para>
/// <para>
/// If <paramref name="txn"/> is null, but
/// <see cref="DatabaseConfig.AutoCommit"/> is set, the operation will
/// be implicitly transaction protected. Note that transactionally
/// protected operations on a datbase object requires the object itself
/// be transactionally protected during its open. Also note that the
/// transaction must be committed before the object is closed.
/// </para>
/// </remarks>
/// <param name="Filename">
/// The name of an underlying file that will be used to back the
/// database. In-memory databases never intended to be preserved on disk
/// may be created by setting this parameter to null.
/// </param>
/// <param name="cfg">The database's configuration</param>
/// <param name="txn">
/// If the operation is part of an application-specified transaction,
/// <paramref name="txn"/> is a Transaction object returned from
/// <see cref="DatabaseEnvironment.BeginTransaction"/>; if
/// the operation is part of a Berkeley DB Concurrent Data Store group,
/// <paramref name="txn"/> is a handle returned from
/// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null.
/// </param>
/// <returns>A new, open database object</returns>
public static HashDatabase Open(
string Filename, HashDatabaseConfig cfg, Transaction txn)
{
return Open(Filename, null, cfg, txn);
}
开发者ID:jamiekeefer,项目名称:gldcoin,代码行数:40,代码来源:HashDatabase.cs
示例10: TestHashFunction
public void TestHashFunction()
{
testName = "TestHashFunction";
SetUpTest(true);
string dbFileName = testHome + "/" + testName + ".db";
string dbSecFileName = testHome + "/" +
testName + "_sec.db";
// Open a primary hash database.
HashDatabaseConfig dbConfig =
new HashDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
HashDatabase hashDB = HashDatabase.Open(
dbFileName, dbConfig);
/*
* Define hash function and open a secondary
* hash database.
*/
SecondaryHashDatabaseConfig secDBConfig =
new SecondaryHashDatabaseConfig(hashDB, null);
secDBConfig.HashFunction =
new HashFunctionDelegate(HashFunction);
secDBConfig.Creation = CreatePolicy.IF_NEEDED;
SecondaryHashDatabase secDB =
SecondaryHashDatabase.Open(dbSecFileName,
secDBConfig);
/*
* Confirm the hash function defined in the configuration.
* Call the hash function and the one from secondary
* database. If they return the same value, then the hash
* function is configured successfully.
*/
uint data = secDB.HashFunction(BitConverter.GetBytes(1));
Assert.AreEqual(0, data);
// Close all.
secDB.Close();
hashDB.Close();
}
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:41,代码来源:SecondaryHashDatabaseTest.cs
示例11: TestInsertToLoc
public void TestInsertToLoc()
{
HashDatabase db;
HashDatabaseConfig dbConfig;
HashCursor cursor;
DatabaseEntry data;
KeyValuePair<DatabaseEntry, DatabaseEntry> pair;
string dbFileName;
testName = "TestInsertToLoc";
SetUpTest(true);
dbFileName = testHome + "/" + testName + ".db";
// Open database and cursor.
dbConfig = new HashDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
/*
* The database should be set to be unsorted to
* insert before/after a certain record.
*/
dbConfig.Duplicates = DuplicatesPolicy.UNSORTED;
db = HashDatabase.Open(dbFileName, dbConfig);
cursor = db.Cursor();
// Add record("key", "data") into database.
AddOneByCursor(cursor);
/*
* Insert the new record("key","data1") after the
* record("key", "data").
*/
data = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data1"));
cursor.Insert(data, Cursor.InsertLocation.AFTER);
/*
* Move the cursor to the record("key", "data") and
* confirm that the next record is the one just inserted.
*/
pair = new KeyValuePair<DatabaseEntry, DatabaseEntry>(
new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")),
new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data")));
Assert.IsTrue(cursor.Move(pair, true));
Assert.IsTrue(cursor.MoveNext());
Assert.AreEqual(ASCIIEncoding.ASCII.GetBytes("key"),
cursor.Current.Key.Data);
Assert.AreEqual(ASCIIEncoding.ASCII.GetBytes("data1"),
cursor.Current.Value.Data);
try {
try {
cursor.Insert(data,
Cursor.InsertLocation.FIRST);
throw new TestException();
} catch (ArgumentException) { }
try
{
cursor.Insert(data,
Cursor.InsertLocation.LAST);
throw new TestException();
} catch (ArgumentException) { }
} finally {
cursor.Close();
db.Close();
}
}
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:66,代码来源:HashCursorTest.cs
示例12: TestHashComparison
public void TestHashComparison()
{
testName = "TestHashComparison";
testHome = testFixtureHome + "/" + testName;
string dbFileName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
HashDatabaseConfig dbConfig = new HashDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.HashComparison = new EntryComparisonDelegate(EntryComparison);
HashDatabase db = HashDatabase.Open(dbFileName,dbConfig);
int ret;
/*
* Comparison gets the value that lowest byte of the
* former dbt minus that of the latter one.
*/
ret = db.Compare(new DatabaseEntry(BitConverter.GetBytes(2)),
new DatabaseEntry(BitConverter.GetBytes(2)));
Assert.AreEqual(0, ret);
ret = db.Compare(new DatabaseEntry(BitConverter.GetBytes(256)),
new DatabaseEntry(BitConverter.GetBytes(1)));
Assert.Greater(0, ret);
db.Close();
}
开发者ID:gildafnai82,项目名称:craq,代码行数:27,代码来源:HashDatabaseTest.cs
示例13: TestAddUnique
public void TestAddUnique()
{
HashDatabase db;
HashCursor cursor;
KeyValuePair<DatabaseEntry, DatabaseEntry> pair;
testName = "TestAddUnique";
SetUpTest(true);
// Open a database and cursor.
HashDatabaseConfig dbConfig = new HashDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
/*
* To put no duplicate data, the database should be
* set to be sorted.
*/
dbConfig.Duplicates = DuplicatesPolicy.SORTED;
db = HashDatabase.Open(
testHome + "/" + testName + ".db", dbConfig);
cursor = db.Cursor();
// Add record("key", "data") into database.
AddOneByCursor(cursor);
/*
* Fail to add duplicate record("key","data").
*/
pair = new KeyValuePair<DatabaseEntry, DatabaseEntry>(
new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("key")),
new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("data")));
try
{
cursor.AddUnique(pair);
}
catch (KeyExistException)
{
}
finally
{
cursor.Close();
db.Close();
}
}
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:44,代码来源:HashCursorTest.cs
示例14: TestConfig
public void TestConfig()
{
testName = "TestConfig";
testHome = testFixtureHome + "/" + testName;
string dbFileName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
XmlElement xmlElem = Configuration.TestSetUp(
testFixtureName, testName);
// Open a primary btree database.
HashDatabaseConfig hashDBConfig =
new HashDatabaseConfig();
hashDBConfig.Creation = CreatePolicy.IF_NEEDED;
HashDatabase hashDB = HashDatabase.Open(
dbFileName, hashDBConfig);
SecondaryHashDatabaseConfig secDBConfig =
new SecondaryHashDatabaseConfig(hashDB, null);
Config(xmlElem, ref secDBConfig, true);
Confirm(xmlElem, secDBConfig, true);
// Close the primary btree database.
hashDB.Close();
}
开发者ID:gildafnai82,项目名称:craq,代码行数:25,代码来源:SecondaryHashDatabaseConfigTest.cs
示例15: TestOpenNewHashDB
public void TestOpenNewHashDB()
{
testName = "TestOpenNewHashDB";
testHome = testFixtureHome + "/" + testName;
string dbFileName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
XmlElement xmlElem = Configuration.TestSetUp(testFixtureName, testName);
HashDatabaseConfig hashConfig = new HashDatabaseConfig();
HashDatabaseConfigTest.Config(xmlElem, ref hashConfig, true);
HashDatabase hashDB = HashDatabase.Open(dbFileName, hashConfig);
Confirm(xmlElem, hashDB, true);
hashDB.Close();
}
开发者ID:gildafnai82,项目名称:craq,代码行数:15,代码来源:HashDatabaseTest.cs
示例16: TestPutNoDuplicate
public void TestPutNoDuplicate()
{
testName = "TestPutNoDuplicate";
testHome = testFixtureHome + "/" + testName;
string dbFileName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
HashDatabaseConfig hashConfig =
new HashDatabaseConfig();
hashConfig.Creation = CreatePolicy.ALWAYS;
hashConfig.Duplicates = DuplicatesPolicy.SORTED;
hashConfig.TableSize = 20;
HashDatabase hashDB = HashDatabase.Open(dbFileName, hashConfig);
DatabaseEntry key, data;
for (int i = 1; i <= 10; i++)
{
key = new DatabaseEntry(BitConverter.GetBytes(i));
data = new DatabaseEntry(BitConverter.GetBytes(i));
hashDB.PutNoDuplicate(key, data);
}
Assert.IsTrue(hashDB.Exists(
new DatabaseEntry(BitConverter.GetBytes((int)5))));
hashDB.Close();
}
开发者ID:gildafnai82,项目名称:craq,代码行数:28,代码来源:HashDatabaseTest.cs
示例17: TestOpenExistingHashDB
public void TestOpenExistingHashDB()
{
testName = "TestOpenExistingHashDB";
testHome = testFixtureHome + "/" + testName;
string dbFileName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
HashDatabaseConfig hashConfig =
new HashDatabaseConfig();
hashConfig.Creation = CreatePolicy.ALWAYS;
HashDatabase hashDB = HashDatabase.Open(dbFileName, hashConfig);
hashDB.Close();
DatabaseConfig dbConfig = new DatabaseConfig();
Database db = Database.Open(dbFileName, dbConfig);
Assert.AreEqual(db.Type, DatabaseType.HASH);
db.Close();
}
开发者ID:gildafnai82,项目名称:craq,代码行数:19,代码来源:HashDatabaseTest.cs
示例18: TestKeyExistException
public void TestKeyExistException()
{
testName = "TestKeyExistException";
testHome = testFixtureHome + "/" + testName;
string dbFileName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
HashDatabaseConfig hashConfig = new HashDatabaseConfig();
hashConfig.Creation = CreatePolicy.ALWAYS;
hashConfig.Duplicates = DuplicatesPolicy.SORTED;
HashDatabase hashDB = HashDatabase.Open(dbFileName, hashConfig);
// Put the same record into db twice.
DatabaseEntry key, data;
key = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("1"));
data = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("1"));
try
{
hashDB.PutNoDuplicate(key, data);
hashDB.PutNoDuplicate(key, data);
}
catch (KeyExistException)
{
throw new ExpectedTestException();
}
finally
{
hashDB.Close();
}
}
开发者ID:gildafnai82,项目名称:craq,代码行数:31,代码来源:HashDatabaseTest.cs
示例19: TestHashFunction
public void TestHashFunction()
{
testName = "TestHashFunction";
testHome = testFixtureHome + "/" + testName;
string dbFileName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
HashDatabaseConfig dbConfig = new HashDatabaseConfig();
dbConfig.Creation = CreatePolicy.IF_NEEDED;
dbConfig.HashFunction = new HashFunctionDelegate(HashFunction);
HashDatabase db = HashDatabase.Open(dbFileName, dbConfig);
// Hash function will change the lowest byte to 0;
uint data = db.HashFunction(BitConverter.GetBytes(1));
Assert.AreEqual(0, data);
db.Close();
}
开发者ID:gildafnai82,项目名称:craq,代码行数:17,代码来源:HashDatabaseTest.cs
示例20: StatsInTxn
public void StatsInTxn(string home, string name, bool ifIsolation)
{
DatabaseEnvironmentConfig envConfig =
new DatabaseEnvironmentConfig();
EnvConfigCase1(envConfig);
DatabaseEnvironment env = DatabaseEnvironment.Open(home, envConfig);
Transaction openTxn = env.BeginTransaction();
HashDatabaseConfig dbConfig = new HashDatabaseConfig();
ConfigCase1(dbConfig);
dbConfig.Env = env;
HashDatabase db = HashDatabase.Open(name + ".db", dbConfig, openTxn);
openTxn.Commit();
Transaction statsTxn = env.BeginTransaction();
HashStats stats;
HashStats fastStats;
if (ifIsolation == false)
{
stats = db.Stats(statsTxn);
fastStats = db.Stats(statsTxn);
}
else
{
stats = db.Stats(statsTxn, Isolation.DEGREE_ONE);
fastStats = db.Stats(statsTxn, Isolation.DEGREE_ONE);
}
ConfirmStatsPart1Case1(stats);
// Put 100 records into the database.
PutRecordCase1(db, statsTxn);
if (ifIsolation == false)
stats = db.Stats(statsTxn);
else
stats = db.Stats(statsTxn, Isolation.DEGREE_TWO);
ConfirmStatsPart2Case1(stats);
// Delete some data to get some free pages.
byte[] bigArray = new byte[262144];
db.Delete(new DatabaseEntry(bigArray), statsTxn);
if (ifIsolation == false)
stats = db.Stats(statsTxn);
else
stats = db.Stats(statsTxn, Isolation.DEGREE_THREE);
ConfirmStatsPart3Case1(stats);
statsTxn.Commit();
db.Close();
env.Close();
}
开发者ID:gildafnai82,项目名称:craq,代码行数:52,代码来源:HashDatabaseTest.cs
注:本文中的BerkeleyDB.HashDatabaseConfig类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论