internal uint ScopeId; // Scope ID (IPv6 only) public override unsafe int GetHashCode() { HashCode h = default; h.AddBytes(MemoryMarshal.CreateReadOnlySpan(ref Address[0], IsIPv6 ? IPv6AddressBytes : IPv4AddressBytes)); return(h.ToHashCode()); }
/// <inheritdoc/> protected override void AddToHashCode(ref HashCode hashCode, EmbeddedBytecodeInfo obj) { hashCode.Add(obj.X); hashCode.Add(obj.Y); hashCode.Add(obj.Z); hashCode.AddBytes(obj.Bytecode.AsSpan()); }
/// <inheritdoc/> protected override void AddToHashCode(ref HashCode hashCode, EmbeddedBytecodeInfo obj) { hashCode.Add(obj.HlslSource); hashCode.Add(obj.ShaderProfile); hashCode.Add(obj.CompileOptions); hashCode.AddBytes(obj.Bytecode.AsSpan()); }
/// <inheritdoc/> protected override void AddToHashCode(ref HashCode hashCode, EmbeddedBytecodeInfo obj) { hashCode.Add(obj.HlslSource); hashCode.Add(obj.ShaderProfile); hashCode.Add(obj.IsLinkingSupported); hashCode.AddBytes(obj.Bytecode.AsSpan()); }
internal uint ScopeId; // Scope ID (IPv6 only) public override unsafe int GetHashCode() { HashCode h = default; fixed(byte *ptr = Address) { h.AddBytes(new ReadOnlySpan <byte>(ptr, IsIPv6 ? IPv6AddressBytes : IPv4AddressBytes)); } return(h.ToHashCode()); }
public override int GetHashCode() { // Lazily compute and store the hash code if it hasn't yet been computed. if (_hashcode == null) { HashCode hc = default; hc.AddBytes(MemoryMarshal.AsBytes <ulong>(_blocks)); hc.Add(Length); _hashcode = hc.ToHashCode(); } return(_hashcode.GetValueOrDefault()); }
static void Populate(ref HashCode hc) { hc.AddBytes(new byte[0]); hc.AddBytes(new byte[] { 1 }); hc.AddBytes(new byte[] { 1, 2 }); hc.AddBytes(new byte[] { 1, 2, 3 }); hc.AddBytes(new byte[] { 1, 2, 3, 4 }); hc.AddBytes(new byte[] { 1, 2, 3, 4, 5 }); hc.AddBytes(Enumerable.Range(0, 10_000).Select(i => (byte)i).ToArray()); }
public static void HashCode_AddBytes_AllValuesHashed() { // This code depends on HashCode having a private _length field that maps to the number // of Int32 values Add'd, as well as exactly how AddBytes partitions the incoming bytes. // If the implementation changes, this test may need to be updated accordingly. FieldInfo lengthField = typeof(HashCode).GetField("_length", BindingFlags.Instance | BindingFlags.NonPublic); int expectedLength = 0; HashCode hc = default; for (int i = 1; i < 100; i++) { hc.AddBytes(Enumerable.Range(1, i).Select(i => (byte)i).ToArray()); expectedLength += Math.DivRem(i, 4, out int remainder) + remainder; Assert.Equal(expectedLength, (int)(uint)lengthField.GetValue(hc)); } }
public static int GetKeyEncodingHashCode(ReadOnlySpan <byte> encoding) { HashCode hash = default; #if NETCOREAPP hash.AddBytes(encoding); #else while (encoding.Length >= sizeof(int)) { hash.Add(MemoryMarshal.Read <int>(encoding)); encoding = encoding.Slice(sizeof(int)); } foreach (byte b in encoding) { hash.Add(b); } #endif return(hash.ToHashCode()); }