Esempio n. 1
0
        public static void DefaultMemoryHashCode()
        {
            ReadOnlyMemory <int> memory = default;

            Assert.Equal(0, memory.GetHashCode());
            ReadOnlyMemory <int> memory2 = default;

            Assert.Equal(memory2.GetHashCode(), memory.GetHashCode());
        }
Esempio n. 2
0
        public static void SameObjectsHaveSameHashCodes()
        {
            int[] a     = { 91, 92, 93, 94, 95 };
            var   left  = new ReadOnlyMemory <int>(a, 2, 3);
            var   right = new ReadOnlyMemory <int>(a, 2, 3);

            int[] b         = { 1, 2, 3, 4, 5 };
            var   different = new ReadOnlyMemory <int>(b, 2, 3);

            Assert.Equal(left.GetHashCode(), right.GetHashCode());
            Assert.NotEqual(left.GetHashCode(), different.GetHashCode());
        }
Esempio n. 3
0
        public static void HashCodesDifferentForSameContent()
        {
            var left  = new ReadOnlyMemory <int>(new int[] { 0, 1, 2 }, 1, 1);
            var right = new ReadOnlyMemory <int>(new int[] { 0, 1, 2 }, 1, 1);

            Assert.NotEqual(left.GetHashCode(), right.GetHashCode());
        }
Esempio n. 4
0
        public static void HashCodeIncludesBase()
        {
            int[] a     = { 91, 92, 93, 94, 95 };
            var   left  = new ReadOnlyMemory <int>(a, 1, 3);
            var   right = new ReadOnlyMemory <int>(a, 2, 3);

            Assert.NotEqual(left.GetHashCode(), right.GetHashCode());
        }
Esempio n. 5
0
        public override int GetHashCode()
        {
            int hashCode = -1183445958;

            hashCode = hashCode * -1521134295 + Type.GetHashCode();
            hashCode = hashCode * -1521134295 + Data.GetHashCode();
            return(hashCode);
        }
Esempio n. 6
0
        public static void EmptyMemoryHashCodeNotUnified()
        {
            var left  = new ReadOnlyMemory <int>(new int[0]);
            var right = new ReadOnlyMemory <int>(new int[0]);

            ReadOnlyMemory <int> memoryFromNonEmptyArrayButWithZeroLength = new Memory <int>(new int[1] {
                123
            }).Slice(0, 0);

            Assert.NotEqual(left.GetHashCode(), right.GetHashCode());
            Assert.NotEqual(left.GetHashCode(), memoryFromNonEmptyArrayButWithZeroLength.GetHashCode());
            Assert.NotEqual(right.GetHashCode(), memoryFromNonEmptyArrayButWithZeroLength.GetHashCode());

            // Empty property hashcode is equal
            left  = ReadOnlyMemory <int> .Empty;
            right = ReadOnlyMemory <int> .Empty;

            Assert.Equal(left.GetHashCode(), right.GetHashCode());
        }
Esempio n. 7
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = m_Origin.GetHashCode();
         hashCode = (hashCode * 397) ^ m_EndIndex;
         hashCode = (hashCode * 397) ^ m_StartIndex;
         return(hashCode);
     }
 }
Esempio n. 8
0
        public static void HashCodesForImplicitCastsAreEqual()
        {
            byte[] bytes          = new byte[10];
            var    memory         = new Memory <byte>(bytes);
            var    readOnlyMemory = new ReadOnlyMemory <byte>(bytes);
            ReadOnlyMemory <byte> implicitReadOnlyMemory      = memory;
            Memory <byte>         implicitMemoryArray         = bytes;
            ReadOnlyMemory <byte> implicitReadOnlyMemoryArray = bytes;

            Assert.Equal(readOnlyMemory.GetHashCode(), memory.GetHashCode());
            Assert.Equal(implicitReadOnlyMemory.GetHashCode(), memory.GetHashCode());
            Assert.Equal(implicitMemoryArray.GetHashCode(), memory.GetHashCode());
            Assert.Equal(implicitReadOnlyMemoryArray.GetHashCode(), memory.GetHashCode());
        }
Esempio n. 9
0
        public bool TryGetValue(ReadOnlyMemory <byte> key, out JwtProperty value)
        {
            var hashCode = key.GetHashCode();
            var span     = key.Span;

            for (int i = 0; i < _properties.Count; i++)
            {
                var current = _properties[i];
                if (current.HashCode == hashCode && current.Property.Utf8Name.SequenceEqual(span))
                {
                    value = current.Property;
                    return(true);
                }
            }

            value = default;
            return(false);
        }
Esempio n. 10
0
 public override int GetHashCode()
 {
     unchecked {
         int hashCode = EventNumber.GetHashCode();
         hashCode = (hashCode * 397) ^ LogPosition.GetHashCode();
         hashCode = (hashCode * 397) ^ CorrelationId.GetHashCode();
         hashCode = (hashCode * 397) ^ EventId.GetHashCode();
         hashCode = (hashCode * 397) ^ TransactionPosition.GetHashCode();
         hashCode = (hashCode * 397) ^ TransactionOffset;
         hashCode = (hashCode * 397) ^ EventStreamId.GetHashCode();
         hashCode = (hashCode * 397) ^ ExpectedVersion.GetHashCode();
         hashCode = (hashCode * 397) ^ TimeStamp.GetHashCode();
         hashCode = (hashCode * 397) ^ Flags.GetHashCode();
         hashCode = (hashCode * 397) ^ EventType.GetHashCode();
         hashCode = (hashCode * 397) ^ Data.GetHashCode();
         hashCode = (hashCode * 397) ^ Metadata.GetHashCode();
         return(hashCode);
     }
 }
Esempio n. 11
0
        public override int GetHashCode()
        {
            unchecked {
                int result = LogPosition.GetHashCode();
                result = (result * 397) ^ Flags.GetHashCode();
                result = (result * 397) ^ TransactionPosition.GetHashCode();
                result = (result * 397) ^ TransactionOffset;
                result = (result * 397) ^ ExpectedVersion.GetHashCode();
                result = (result * 397) ^ EventStreamId.GetHashCode();

                result = (result * 397) ^ EventId.GetHashCode();
                result = (result * 397) ^ CorrelationId.GetHashCode();
                result = (result * 397) ^ TimeStamp.GetHashCode();
                result = (result * 397) ^ EventType.GetHashCode();
                result = (result * 397) ^ Data.GetHashCode();
                result = (result * 397) ^ Metadata.GetHashCode();
                return(result);
            }
        }
Esempio n. 12
0
 public override int GetHashCode()
 {
     return(_bytes.GetHashCode());
 }
 public override int GetHashCode()
 {
     return(_value.GetHashCode());
 }
Esempio n. 14
0
 public override int GetHashCode()
 {
     return(Memory.GetHashCode());
 }
Esempio n. 15
0
 public override int GetHashCode() => Fen.GetHashCode();
Esempio n. 16
0
 public override int GetHashCode()
 {
     return(Name.GetHashCode());
 }