using System; using System.Collections.Generic; namespace ScreenConnect; public readonly struct HashCode { public static HashCode Seed; public int Value { get; } private HashCode(int value) { Value = value; } public static implicit operator uint(HashCode @this) { return (uint)@this.Value; } public static implicit operator int(HashCode @this) { return @this.Value; } public static implicit operator HashCode(int @this) { return new HashCode(@this); } public static int And(int hashCode1, int hashCode2) { return 31 * hashCode1 + hashCode2; } public HashCode Normalize() { return Value.Pipe(BitConverter.GetBytes).Pipe(Singleton.Instance.ComputeMD5Hash).Pipe((byte[] it) => BitConverter.ToInt32(it, 0)); } public HashCode And(int hashCode) { return And(this, hashCode); } public HashCode And(T? @object) { if (@object != null) { return And(@object.GetHashCode()); } return this; } public HashCode And(T? @object, IEqualityComparer equalityComparer) { if (@object != null) { return And(equalityComparer.GetHashCode(@object)); } return this; } public HashCode AndStable(string? s) { HashCode result = this; if (s != null) { for (int i = 0; i < s.Length; i++) { result = And(s[i]); } } return result; } public HashCode AndArray(T[]? objects) { HashCode result = this; if (objects != null) { foreach (T val in objects) { result = result.And(val); } } return result; } public HashCode AndList(IList? objects) { HashCode result = this; if (objects != null) { for (int i = 0; i < objects.Count; i++) { result = result.And(objects[i]); } } return result; } public HashCode AndEnumerable(IEnumerable? objects) { HashCode result = this; if (objects != null) { foreach (T @object in objects) { result = result.And(@object); } } return result; } public HashCode AndDictionary(IDictionary? map) where TKey : notnull { HashCode result = this; TKey key; TValue value; if (map is Dictionary dictionary) { foreach (KeyValuePair item in dictionary) { Extensions.Deconstruct(item, out key, out value); TKey val = key; TValue val2 = value; result = result.And(val).And(val2); } } else if (map != null) { foreach (KeyValuePair item2 in map) { Extensions.Deconstruct(item2, out key, out value); TKey val3 = key; TValue val4 = value; result = result.And(val3).And(val4); } } return result; } }