本文整理汇总了C#中Slice.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Slice.GetHashCode方法的具体用法?C# Slice.GetHashCode怎么用?C# Slice.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slice
的用法示例。
在下文中一共展示了Slice.GetHashCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGetHashCodeIsZeroForEmptySlice
public void TestGetHashCodeIsZeroForEmptySlice()
{
var s = new Slice<int>(new int[0]);
Assert.AreEqual(0, s.GetHashCode());
s = new Slice<int>(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
s = s.Slc(5, 5);
Assert.AreEqual(0, s.Len());
Assert.AreEqual(0, s.GetHashCode());
}
示例2: TestGetHashCodeIsCalculating
public void TestGetHashCodeIsCalculating()
{
var s = new Slice<int>(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
int hash1 = s.GetHashCode();
s = new Slice<int>(new[] { 1, 2, 3, 4, 5 });
int hash2 = s.GetHashCode();
Assert.AreNotEqual(0, hash1);
Assert.AreNotEqual(0, hash2);
Assert.AreNotEqual(hash1, hash2);
}
示例3: InsertAsync
public async Task InsertAsync([NotNull] IFdbTransaction trans, Slice key)
{
if (trans == null) throw new ArgumentNullException("trans");
if (await ContainsAsync(trans, key).ConfigureAwait(false))
{
return;
}
int keyHash = key.GetHashCode(); //TODO: proper hash function?
//Console.WriteLine("Inserting " + key + " with hash " + keyHash.ToString("x"));
for(int level = 0; level < MAX_LEVELS; level++)
{
var prevKey = await GetPreviousNodeAsync(trans, level, key);
if ((keyHash & ((1 << (level * LEVEL_FAN_POW)) - 1)) != 0)
{
//Console.WriteLine("> [" + level + "] Incrementing previous key: " + FdbKey.Dump(prevKey));
trans.AtomicAdd(this.Subspace.Partition(level, prevKey), EncodeCount(1));
}
else
{
//Console.WriteLine("> [" + level + "] inserting and updating previous key: " + FdbKey.Dump(prevKey));
// Insert into this level by looking at the count of the previous
// key in the level and recounting the next lower level to correct
// the counts
var prevCount = DecodeCount(await trans.GetAsync(this.Subspace.Pack(level, prevKey)).ConfigureAwait(false));
var newPrevCount = await SlowCountAsync(trans, level - 1, prevKey, key);
var count = checked((prevCount - newPrevCount) + 1);
// print "insert", key, "level", level, "count", count,
// "splits", prevKey, "oldC", prevCount, "newC", newPrevCount
trans.Set(this.Subspace.Pack(level, prevKey), EncodeCount(newPrevCount));
trans.Set(this.Subspace.Pack(level, key), EncodeCount(count));
}
}
}