예제 #1
0
        public static ushort EncToIdx(ulong encWord1, ulong encWord2, ulong encWord3)
        {
            uint hashcode1 = Hashing.Hashcode64(encWord1);
            uint hashcode2 = Hashing.Hashcode64(encWord2);
            uint hashcode3 = Hashing.Hashcode64(encWord3);
            uint idx       = (31 * 31 * hashcode1 + 31 * hashcode2 + hashcode3) % SIZE;

            if (encSymbs3 == null)
            {
                encSymbs3     = new ulong[3 * SIZE];
                encSymbsIdxs3 = new  ushort[SIZE];
            }

            ulong storedEnc1 = encSymbs3[3 * idx];
            ulong storedEnc2 = encSymbs3[3 * idx + 1];
            ulong storedEnc3 = encSymbs3[3 * idx + 2];

            if (storedEnc1 == encWord1 & storedEnc2 == encWord2 & storedEnc3 == encWord3)
            {
                return(encSymbsIdxs3[idx]);
            }

            byte[] bytes   = Decode(encWord1, encWord2, encWord3);
            ushort symbIdx = SymbObj.BytesToIdx(bytes);

            if (storedEnc1 == 0)
            {
                encSymbs3[3 * idx]     = encWord1;
                encSymbs3[3 * idx + 1] = encWord2;
                encSymbs3[3 * idx + 2] = encWord3;
                encSymbsIdxs3[idx]     = symbIdx;
            }

            return(symbIdx);
        }
예제 #2
0
        public static ushort EncToIdx(ulong encWord1, ulong encWord2)
        {
            uint hashcode1 = Hashing.Hashcode64(encWord1);
            uint hashcode2 = Hashing.Hashcode64(encWord2);
            uint idx       = (31 * hashcode1 + hashcode2) % SIZE;

            ulong storedEnc1 = encSymbs2[2 * idx];
            ulong storedEnc2 = encSymbs2[2 * idx + 1];

            if (storedEnc1 == encWord1 & storedEnc2 == encWord2)
            {
                return(encSymbsIdxs2[idx]);
            }

            byte[] bytes   = Decode(encWord1, encWord2);
            ushort symbIdx = SymbObj.BytesToIdx(bytes);

            if (storedEnc1 == 0)
            {
                encSymbs2[2 * idx]     = encWord1;
                encSymbs2[2 * idx + 1] = encWord2;
                encSymbsIdxs2[idx]     = symbIdx;
            }

            return(symbIdx);
        }
예제 #3
0
        public static ushort EncToIdx(ulong[] encWords, int count)
        {
            uint hashcode = Hashing.Hashcode64(encWords[0]);

            for (int i = 1; i < count; i++)
            {
                hashcode = 31 * hashcode + Hashing.Hashcode64(encWords[i]);
            }
            uint idx = hashcode % SIZE;

            if (encSymbs == null)
            {
                encSymbs     = new ulong[SIZE][];
                encSymbsIdxs = new ushort[SIZE];
            }

            ulong[] storedEncs = encSymbs[idx];
            if (storedEncs != null && storedEncs.Length == count && Array.IsPrefix(storedEncs, encWords))
            {
                return(encSymbsIdxs[idx]);
            }

            byte[] bytes   = Decode(encWords, count);
            ushort symbIdx = SymbObj.BytesToIdx(bytes);

            if (storedEncs == null)
            {
                encSymbs[idx]     = Array.Take(encWords, count);
                encSymbsIdxs[idx] = symbIdx;
            }

            return(symbIdx);
        }
예제 #4
0
        public static ushort EncToIdx(ulong encWord)
        {
            uint hashcode = Hashing.Hashcode64(encWord);
            uint idx      = hashcode % SIZE;

            ulong storedEnc = encSymbs1[idx];

            if (storedEnc == encWord)
            {
                return(encSymbsIdxs1[idx]);
            }

            byte[] bytes   = Decode(encWord);
            ushort symbIdx = SymbObj.BytesToIdx(bytes);

            if (storedEnc == 0)
            {
                encSymbs1[idx]     = encWord;
                encSymbsIdxs1[idx] = symbIdx;
            }

            return(symbIdx);
        }