Пример #1
0
        /// <summary>
        /// Opens a file containing one string per line, hashes each string, and adds each pair to a lookup table.
        /// </summary>
        private static Dictionary <uint, string> MakeHashLookupTableFromFile(string path, FoxHash.Type hashType)
        {
            ConcurrentDictionary <uint, string> table = new ConcurrentDictionary <uint, string>();

            // Read file
            List <string> stringLiterals = new List <string>();

            using (StreamReader file = new StreamReader(path))
            {
                // TODO multi-thread
                string line;
                while ((line = file.ReadLine()) != null)
                {
                    stringLiterals.Add(line);
                }
            }

            // Hash entries
            Parallel.ForEach(stringLiterals, (string entry) =>
            {
                if (hashType == FoxHash.Type.StrCode32)
                {
                    uint hash = HashManager.StrCode32(entry);
                    table.TryAdd(hash, entry);
                }
                else
                {
                    uint hash = HashManager.PathCode32(entry);
                    table.TryAdd(hash, entry);
                }
            });

            return(new Dictionary <uint, string>(table));
        }
Пример #2
0
        public void ReadXml(XmlReader reader, string label)
        {
            string value = reader[label];

            if (uint.TryParse(value, out uint maybeHash))
            {
                HashValue = maybeHash;
            }
            else
            {
                StringLiteral = value;

                if (this.type == Type.StrCode32)
                {
                    HashValue = HashManager.StrCode32(StringLiteral);
                }
                else
                {
                    HashValue = HashManager.PathCode32(StringLiteral);
                }
            }
        }