本文整理汇总了C#中BigInteger.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.GetHashCode方法的具体用法?C# BigInteger.GetHashCode怎么用?C# BigInteger.GetHashCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BigInteger
的用法示例。
在下文中一共展示了BigInteger.GetHashCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: __hash__
public static int __hash__(BigInteger self) {
#if CLR4 // TODO: we might need our own hash code implementation. This avoids assertion failure.
if (self == -2147483648) {
return -2147483648;
}
#endif
// check if it's in the Int64 or UInt64 range, and use the built-in hashcode for that instead
// this ensures that objects added to dictionaries as (U)Int64 can be looked up with Python longs
Int64 i64;
if (self.AsInt64(out i64)) {
return Int64Ops.__hash__(i64);
} else {
UInt64 u64;
if (self.AsUInt64(out u64)) {
return UInt64Ops.__hash__(u64);
}
}
// Call the DLR's BigInteger hash function, which will return an int32 representation of
// b if b is within the int32 range. We use that as an optimization for hashing, and
// assert the assumption below.
int hash = self.GetHashCode();
#if DEBUG
int i;
if (self.AsInt32(out i)) {
Debug.Assert(i == hash, String.Format("hash({0}) == {1}", i, hash));
}
#endif
return hash;
}
示例2: VerifyComparison
private static void VerifyComparison(BigInteger x, bool IsXNegative, BigInteger y, bool IsYNegative, int expectedResult)
{
bool expectedEquals = 0 == expectedResult;
bool expectedLessThan = expectedResult < 0;
bool expectedGreaterThan = expectedResult > 0;
if (IsXNegative == true)
{
x = x * -1;
}
if (IsYNegative == true)
{
y = y * -1;
}
Assert.Equal(expectedEquals, x == y);
Assert.Equal(expectedEquals, y == x);
Assert.Equal(!expectedEquals, x != y);
Assert.Equal(!expectedEquals, y != x);
Assert.Equal(expectedEquals, x.Equals(y));
Assert.Equal(expectedEquals, y.Equals(x));
Assert.Equal(expectedEquals, x.Equals((Object)y));
Assert.Equal(expectedEquals, y.Equals((Object)x));
VerifyCompareResult(expectedResult, x.CompareTo(y), "x.CompareTo(y)");
VerifyCompareResult(-expectedResult, y.CompareTo(x), "y.CompareTo(x)");
if (expectedEquals)
{
Assert.Equal(x.GetHashCode(), y.GetHashCode());
Assert.Equal(x.ToString(), y.ToString());
}
Assert.Equal(x.GetHashCode(), x.GetHashCode());
Assert.Equal(y.GetHashCode(), y.GetHashCode());
Assert.Equal(expectedLessThan, x < y);
Assert.Equal(expectedGreaterThan, y < x);
Assert.Equal(expectedGreaterThan, x > y);
Assert.Equal(expectedLessThan, y > x);
Assert.Equal(expectedLessThan || expectedEquals, x <= y);
Assert.Equal(expectedGreaterThan || expectedEquals, y <= x);
Assert.Equal(expectedGreaterThan || expectedEquals, x >= y);
Assert.Equal(expectedLessThan || expectedEquals, y >= x);
}
示例3: __hash__
public static int __hash__(BigInteger self) {
#if CLR4 // TODO: we might need our own hash code implementation. This avoids assertion failure.
if (self == -2147483648) {
return -2147483648;
}
#endif
// Call the DLR's BigInteger hash function, which will return an int32 representation of
// b if b is within the int32 range. We use that as an optimization for hashing, and
// assert the assumption below.
int hash = self.GetHashCode();
#if DEBUG
int i;
if (self.AsInt32(out i)) {
Debug.Assert(i == hash, String.Format("hash({0}) == {1}", i, hash));
}
#endif
return hash;
}
示例4: VerifyComparison
private static void VerifyComparison(BigInteger x, BigInteger y, int expectedResult)
{
bool expectedEquals = 0 == expectedResult;
bool expectedLessThan = expectedResult < 0;
bool expectedGreaterThan = expectedResult > 0;
Assert.Equal(expectedEquals, x == y);
Assert.Equal(expectedEquals, y == x);
Assert.Equal(!expectedEquals, x != y);
Assert.Equal(!expectedEquals, y != x);
Assert.Equal(expectedEquals, x.Equals(y));
Assert.Equal(expectedEquals, y.Equals(x));
Assert.Equal(expectedEquals, x.Equals((Object)y));
Assert.Equal(expectedEquals, y.Equals((Object)x));
VerifyCompareResult(expectedResult, x.CompareTo(y), "x.CompareTo(y)");
VerifyCompareResult(-expectedResult, y.CompareTo(x), "y.CompareTo(x)");
IComparable comparableX = x;
IComparable comparableY = y;
VerifyCompareResult(expectedResult, comparableX.CompareTo(y), "comparableX.CompareTo(y)");
VerifyCompareResult(-expectedResult, comparableY.CompareTo(x), "comparableY.CompareTo(x)");
VerifyCompareResult(expectedResult, BigInteger.Compare(x, y), "Compare(x,y)");
VerifyCompareResult(-expectedResult, BigInteger.Compare(y, x), "Compare(y,x)");
if (expectedEquals)
{
Assert.Equal(x.GetHashCode(), y.GetHashCode());
Assert.Equal(x.ToString(), y.ToString());
}
Assert.Equal(x.GetHashCode(), x.GetHashCode());
Assert.Equal(y.GetHashCode(), y.GetHashCode());
Assert.Equal(expectedLessThan, x < y);
Assert.Equal(expectedGreaterThan, y < x);
Assert.Equal(expectedGreaterThan, x > y);
Assert.Equal(expectedLessThan, y > x);
Assert.Equal(expectedLessThan || expectedEquals, x <= y);
Assert.Equal(expectedGreaterThan || expectedEquals, y <= x);
Assert.Equal(expectedGreaterThan || expectedEquals, x >= y);
Assert.Equal(expectedLessThan || expectedEquals, y >= x);
}
示例5: GetHashCodeTest
public void GetHashCodeTest()
{
BigInteger target = new BigInteger(); // TODO: Initialize to an appropriate value
int expected = 0; // TODO: Initialize to an appropriate value
int actual;
actual = target.GetHashCode();
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}