/*
 * @FileName: HashCodeExtension.cs
 * @Date: 2024-04-20 20:06:15
 * @LastEditTime: 2024-04-21 13:57:57
 * @Description: 定义Hash扩展方法
 */

using JNGame.Math;

namespace JNGame.Util
{
    /// <summary>
    /// 扩展基础类型(包括定点数)的哈希计算
    /// </summary>
    public static class HashCodeExtension
    {
        public static int GetHash(this byte val, ref int idx)
        {
            return val;
        }

        public static int GetHash(this short val, ref int idx)
        {
            return val;
        }

        public static int GetHash(this int val, ref int idx)
        {
            return val;
        }
        public static int GetHash(this long val, ref int idx)
        {
            return (int)val;
        }

        public static int GetHash(this sbyte val, ref int idx)
        {
            return val;
        }

        public static int GetHash(this ushort val, ref int idx)
        {
            return val;
        }

        public static int GetHash(this uint val, ref int idx)
        {
            return (int)val;
        }

        public static int GetHash(this ulong val, ref int idx)
        {
            return (int)val;
        }

        public static int GetHash(this bool val, ref int idx)
        {
            return val ? 1 : 0;
        }

        public static int GetHash(this string val, ref int idx)
        {
            return val?.GetHashCode() ?? 0;
        }

        public static int GetHash(this LFloat val, ref int idx)
        {
            return PrimerLUT.GetPrimer(val.rawValue);
        }

        public static int GetHash(this LVector2 val, ref int idx)
        {
            return PrimerLUT.GetPrimer(val.RawX) + PrimerLUT.GetPrimer(val.RawY) * 17;
        }

        public static int GetHash(this LVector2Int val, ref int idx)
        {
            return PrimerLUT.GetPrimer(val.x) + PrimerLUT.GetPrimer(val.y) * 17;
        }

        public static int GetHash(this LVector3 val, ref int idx)
        {
            return PrimerLUT.GetPrimer(val.RawX)
                   + PrimerLUT.GetPrimer(val.RawY) * 31
                   + PrimerLUT.GetPrimer(val.RawZ) * 37;
        }

        public static int GetHash(this LVector3Int val, ref int idx)
        {
            return PrimerLUT.GetPrimer(val.x)
                   + PrimerLUT.GetPrimer(val.y) * 31
                   + PrimerLUT.GetPrimer(val.z) * 37;
        }
    }
}