Added FisheryLib.Collections.FishTable and Mono.Cecil extension methods
A bit of refactoring has been done too
This commit is contained in:
@@ -7,24 +7,23 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace FisheryLib;
|
||||
|
||||
public static class HashCode
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int Get<T>([AllowNull] T obj)
|
||||
=> FunctionPointers.GetHashCode<T>.Default(obj!);
|
||||
public static unsafe int Get<T>([AllowNull] T obj) => FunctionPointers.GetHashCode<T>.Default(obj!);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int Get<T>([AllowNull] ref T obj)
|
||||
=> FunctionPointers.GetHashCodeByRef<T>.Default(ref obj!);
|
||||
public static unsafe int Get<T>([AllowNull] ref T obj) => FunctionPointers.GetHashCodeByRef<T>.Default(ref obj!);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Combine<T_first, T_second>(T_first first, T_second second)
|
||||
//where T_first : notnull where T_second : notnull
|
||||
=> Combine(Get(first), Get(second));
|
||||
|
||||
// https://stackoverflow.com/questions/1646807/quick-and-simple-hash-code-combinations/34006336#34006336
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Combine(int first, int second)
|
||||
=> unchecked((1009 * 9176) + first).CombineWith(second); //https://stackoverflow.com/questions/1646807/quick-and-simple-hash-code-combinations/34006336#34006336
|
||||
public static int Combine(int first, int second) => unchecked((1009 * 9176) + first).CombineWith(second);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Combine<T_first, T_second, T_third>(T_first first, T_second second, T_third third)
|
||||
@@ -32,11 +31,11 @@ public static class HashCode
|
||||
=> Combine(first, second).CombineWith(third);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Combine(int first, int second, int third)
|
||||
=> Combine(first, second).CombineWith(third);
|
||||
public static int Combine(int first, int second, int third) => Combine(first, second).CombineWith(third);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Combine<T_first, T_second, T_third, T_fourth>(T_first first, T_second second, T_third third, T_fourth fourth)
|
||||
public static int Combine<T_first, T_second, T_third, T_fourth>(T_first first, T_second second, T_third third,
|
||||
T_fourth fourth)
|
||||
//where T_first : notnull where T_second : notnull where T_third : notnull where T_fourth : notnull
|
||||
=> Combine(first, second, third).CombineWith(fourth);
|
||||
|
||||
@@ -45,11 +44,10 @@ public static class HashCode
|
||||
=> Combine(first, second, third).CombineWith(fourth);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int CombineWith(this int first, int second)
|
||||
=> unchecked((first * 9176) + second);
|
||||
internal static int CombineWith(this int first, int second) => unchecked((first * 9176) + second);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int CombineWith<T>(this int first, T second)
|
||||
internal static int CombineWith<T>(this int first, T second)
|
||||
//where T : notnull
|
||||
=> unchecked((first * 9176) + Get(second));
|
||||
}
|
||||
Reference in New Issue
Block a user