Hash() public static method

public static Hash ( string text, uint hashOffset ) : uint
text string
hashOffset uint
return uint
Esempio n. 1
0
        public int[] FindMulti(string filename)
        {
            var  matches  = new List <int>();
            uint hash     = CommonMethods.Hash(filename, 0);
            uint hashA    = CommonMethods.Hash(filename, 0x100);
            uint hashB    = CommonMethods.Hash(filename, 0x200);
            uint capacity = checked ((uint)entries.LongLength);
            uint start    = hash % capacity;
            uint index    = start;

            do
            {
                // Stop on invalid entry
                if (!entries[index].IsValid)
                {
                    break;
                }

                if (entries[index].Test(hashA, hashB))
                {
                    matches.Add(entries[index].Block);
                }

                // If we find an invalid entry, then we end the research
                if (++index >= capacity)
                {
                    index = 0;
                }
            }while (index != start);

            return(matches.ToArray());
        }
Esempio n. 2
0
        private static uint ComputeSeed(string filename)
        {
            // Calculate the seed based on the file name and not the full path.
            // I really don't know why but it worked with the full path for a lot of files…
            // But now it's fixed at least
            int index = filename.LastIndexOf('\\');

            return(CommonMethods.Hash(index >= 0 ? filename.Substring(index + 1) : filename, 0x300));
        }
Esempio n. 3
0
        public int Find(string filename, int lcid)
        {
            uint?neutralEntryIndex = null;
            uint?firstEntryIndex   = null;

            uint hash     = CommonMethods.Hash(filename, 0);
            uint hashA    = CommonMethods.Hash(filename, 0x100);
            uint hashB    = CommonMethods.Hash(filename, 0x200);
            uint capacity = checked ((uint)entries.LongLength);
            uint start    = hash % capacity;
            uint index    = start;

            do
            {
                // Stop on invalid entry
                if (!entries[index].IsValid)
                {
                    break;
                }

                if (entries[index].Test(hashA, hashB))
                {
                    if (entries[index].Locale == lcid)
                    {
                        return(entries[index].Block);
                    }
                    else if (entries[index].Locale == 0)
                    {
                        neutralEntryIndex = index;
                    }
                    else if (firstEntryIndex == null)
                    {
                        firstEntryIndex = index;
                    }
                }

                if (++index >= capacity)
                {
                    index = 0;
                }
            }while (index != start);

            return(neutralEntryIndex != null ?
                   entries[neutralEntryIndex.Value].Block :
                   firstEntryIndex != null && lcid == 0 ?
                   entries[firstEntryIndex.Value].Block :
                   -1);
        }