本文整理汇总了C#中System.Guid.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Guid.GetHashCode方法的具体用法?C# Guid.GetHashCode怎么用?C# Guid.GetHashCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Guid
的用法示例。
在下文中一共展示了Guid.GetHashCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PosTest2
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest2: Calling GetHashCode multiple times should return the same hash value");
try
{
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
TestLibrary.Generator.GetBytes(-55, bytes);
Guid guid = new Guid(bytes);
int hashCode1 = guid.GetHashCode();
int hashCode2 = guid.GetHashCode();
if (hashCode1 != hashCode2)
{
TestLibrary.TestFramework.LogError("002.1", "Calling GetHashCode multiple times does not return the same hash value");
TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLES] hashCode1 = " + hashCode1 + ", hashCode2 = " + hashCode2);
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例2: GivenAnImageObject_ThenItIsHashCodeIsEqualToItsId
public void GivenAnImageObject_ThenItIsHashCodeIsEqualToItsId()
{
var id = new Guid();
var img = new Media {Id= id};
Assert.That(img.GetHashCode(), Is.EqualTo(id.GetHashCode()));
}
示例3: CPSProject
public CPSProject(
VisualStudioProjectTracker projectTracker,
Func<ProjectId, IVsReportExternalErrors> reportExternalErrorCreatorOpt,
string projectDisplayName,
string projectFilePath,
IVsHierarchy hierarchy,
string language,
Guid projectGuid,
string commandLineForOptions,
IServiceProvider serviceProvider,
VisualStudioWorkspaceImpl visualStudioWorkspaceOpt,
HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt,
ICommandLineParserService commandLineParserServiceOpt)
: base(projectTracker, reportExternalErrorCreatorOpt, projectDisplayName, projectFilePath,
hierarchy, language, projectGuid, serviceProvider, visualStudioWorkspaceOpt, hostDiagnosticUpdateSourceOpt, commandLineParserServiceOpt)
{
// Initialize the options.
SetCommandLineArguments(commandLineForOptions);
// We need to ensure that the bin output path for the project has been initialized before we hookup the project with the project tracker.
// If we were unable to set the output path from SetCommandLineArguments (due to null output file name or directory in the given commandLineForOptions),
// we set a default unique output path.
if (this.TryGetBinOutputPath() == null)
{
var uniqueDefaultOutputPath = PathUtilities.CombinePathsUnchecked(Path.GetTempPath(), projectDisplayName + projectGuid.GetHashCode().ToString());
SetOutputPathAndRelatedData(objOutputPath: uniqueDefaultOutputPath, hasSameBinAndObjOutputPaths: true);
}
Contract.ThrowIfNull(this.TryGetBinOutputPath());
// Now hook up the project to the project tracker.
projectTracker.AddProject(this);
_lastDesignTimeBuildSucceeded = true;
}
示例4: BlockchainKey
public BlockchainKey(Guid guid, UInt256 rootBlockHash)
{
this._guid = guid;
this._rootBlockHash = rootBlockHash;
this.hashCode = guid.GetHashCode() ^ rootBlockHash.GetHashCode();
}
示例5: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1: GetHashCode should return the same value for two equal instances");
try
{
byte[] bytes = new byte[c_SIZE_OF_ARRAY];
TestLibrary.Generator.GetBytes(-55, bytes);
Guid guid1 = new Guid(bytes);
Guid guid2 = new Guid(bytes);
int hashCode1 = guid1.GetHashCode();
int hashCode2 = guid2.GetHashCode();
if (hashCode1 != hashCode2)
{
TestLibrary.TestFramework.LogError("001.1", "GetHashCode does not return the same value for two equal instances");
TestLibrary.TestFramework.LogInformation("WARNING [LOCAL VARIABLES] hashCode1 = " + hashCode1 + ", hashCode2 = " + hashCode2);
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例6: Test
public bool Test(Guid guid) {
var hash1 = guid.GetHashCode();
var hash2 = Hash(guid);
var bits = Enumerable.Range(1, hashCount)
.Select(i => (uint)DoubleHashToBitNumber(hash1, hash2, i))
.Distinct();
return bits.All(bitSet.Contains);
}
示例7: getInitVector
/// <summary>
/// 获得一次初始向量用于加密
/// </summary>
/// <param name="n">长度</param>
/// <returns>初始向量字符串</returns>
public static string getInitVector(int n)
{
StringBuilder buf = new StringBuilder();
var guid = new Guid();
Random rnd = new Random(guid.GetHashCode());
for (int i = 0; i < n; i++)
{
buf.Append(arrChar[rnd.Next(0, arrChar.Length)].ToString());
}
return buf.ToString();
}
示例8: SetAndTest
public bool SetAndTest(Guid guid) {
var hash1 = guid.GetHashCode();
var hash2 = Hash(guid);
var bits = Enumerable.Range(1, hashCount)
.Select(i => (uint)DoubleHashToBitNumber(hash1, hash2, i))
.Distinct();
bool result = false;
foreach (var bit in bits) {
result |= bitSet.TrySet(bit);
}
return result;
}
示例9: Heartbeat
public void Heartbeat(Guid origin, int processId)
{
lock (startedProcesses)
{
var process = startedProcesses.Where(x => x.ProcessId == processId).SingleOrDefault();
if (process != null)
process.RegisterHeartbeat(origin);
else
{
var processName = origin.GetHashCode();
var proc = SkynetProcess.FromId(processId, processName.ToString());
startedProcesses.Add(proc);
proc.RegisterHeartbeat(origin);
}
}
}
示例10: Value_type_Guid
public void Value_type_Guid()
{
var helper = new IdHelperForValueType<Guid>();
var guid1 = new Guid("005faa88-a529-4065-9d04-72a96316988b");
var guid2 = new Guid("64b9dd7a-f46e-448b-b6e5-ddd3f83ec508");
Assert.AreEqual(false, helper.IsNull(Guid.Empty));
Assert.AreEqual(true, helper.IsDefaultValue(Guid.Empty));
Assert.AreEqual(false, helper.IsDefaultValue(guid1));
Assert.AreEqual(true, helper.AreEqual(Guid.Empty, Guid.Empty));
Assert.AreEqual(true, helper.AreEqual(guid1, guid1));
Assert.AreEqual(-1, helper.Compare(Guid.Empty, guid1));
Assert.AreEqual(+1, helper.Compare(guid2, Guid.Empty));
Assert.That(helper.Compare(Guid.Empty, Guid.Empty), Is.EqualTo(0));
Assert.AreEqual(0, helper.Compare(guid2, guid2));
Assert.AreEqual(Guid.Empty.GetHashCode(), helper.GetHashCode(Guid.Empty));
Assert.AreEqual(guid1.GetHashCode(), helper.GetHashCode(guid1));
}
示例11: getBucket
private Bucket getBucket(Guid key)
{
var idx = Math.Abs(key.GetHashCode() % m_BucketCount); //todo IMPORTANT!!!!! replace with more efficient Bucket determination call from NFX.IntMath
return m_Buckets[idx];
}
示例12: GetMergedHashCode
/// <summary>
/// Gets a hashcode value based on the combination of the message's ID and RebroadcastID
/// </summary>
/// <param name="MessageID">The Message ID</param>
/// <param name="BroadcastID">The Message Broadcast ID</param>
/// <returns>The hashcode value</returns>
private static int GetMergedHashCode(Guid MessageID, Guid BroadcastID)
{
byte[] composite = new byte[256];
MessageID.ToByteArray().CopyTo(composite, 0);
BroadcastID.ToByteArray().CopyTo(composite, 128);
//merge composite into a single guid by calculating hash
//always create a brand new hash algorithm for use in a muli-threaded environment
System.Security.Cryptography.HashAlgorithm hashAlg = System.Security.Cryptography.MD5.Create();
Guid newUnique = new Guid( hashAlg.ComputeHash(composite));
hashAlg = null;
//return the new Guid's hashcode
return newUnique.GetHashCode();
}
示例13: TestEquals
public static void TestEquals(Guid guid1, object obj, bool expected)
{
if (obj is Guid)
{
Guid guid2 = (Guid)obj;
Assert.Equal(expected, guid1.Equals(guid2));
Assert.Equal(expected, guid1 == guid2);
Assert.Equal(!expected, guid1 != guid2);
Assert.Equal(expected, guid1.GetHashCode().Equals(guid2.GetHashCode()));
}
Assert.Equal(expected, guid1.Equals(obj));
}
示例14: GetHashCode
public int GetHashCode(object x)
{
Guid value = new Guid(x.ToString());
return value.GetHashCode();
}
示例15: EncodeSessionID
/// <summary>
/// Override to encode session ID GUID into string representation
/// </summary>
protected virtual string EncodeSessionID(Guid id)
{
ulong csum = ((ulong)id.GetHashCode() << 32) | (uint)ExternalRandomGenerator.Instance.NextRandomInteger;
var encoded = new ELink(csum, id.ToByteArray());
return encoded.Link;
}