示例#1
0
        public void GlobalSetup()
        {
            var path = Path.GetDirectoryName(typeof(StringHash).GetTypeInfo().Assembly.Location);

            path = Path.Combine(path, "Files", "JEOPARDY_CSV.csv");

            List <byte[]> list = new();

            using var reader = new StreamReader(path);
            using var csv    = new CsvReader(reader, CultureInfo.InvariantCulture);
            csv.Read();
            csv.ReadHeader();
            StringBuilder stringBuilder = new StringBuilder();

            while (csv.Read())
            {
                var str = csv.GetField <string>(6);
                stringBuilder.Append(" " + str);
                list.Add(Encoding.UTF8.GetBytes(str));
            }
            _sentences = list.ToArray();
            _longText  = Encoding.UTF8.GetBytes(stringBuilder.ToString());

            list.Clear();
            path = Path.GetDirectoryName(typeof(StringHash).GetTypeInfo().Assembly.Location);
            using var streamReader = new StreamReader(new FileStream(Path.Combine(path, "Files", "words.txt"), FileMode.Open));
            while (!streamReader.EndOfStream)
            {
                list.Add(Encoding.UTF8.GetBytes(streamReader.ReadLine() ?? ""));
            }

            _words = list.ToArray();

            _sha1 = System.Data.HashFunction.HashAlgorithm.HashAlgorithmWrapperFactory.Instance.Create(
                new HashAlgorithmWrapperConfig()
            {
                InstanceFactory = SHA1.Create
            });
            _md5 = System.Data.HashFunction.HashAlgorithm.HashAlgorithmWrapperFactory.Instance.Create(
                new HashAlgorithmWrapperConfig()
            {
                InstanceFactory = MD5.Create
            });
            _sha512 = System.Data.HashFunction.HashAlgorithm.HashAlgorithmWrapperFactory.Instance.Create(
                new HashAlgorithmWrapperConfig()
            {
                InstanceFactory = SHA512.Create
            });

            _blake2   = System.Data.HashFunction.Blake2.Blake2BFactory.Instance.Create();
            _city     = System.Data.HashFunction.CityHash.CityHashFactory.Instance.Create();
            _fnv1     = System.Data.HashFunction.FNV.FNV1Factory.Instance.Create();
            _fnv1A    = System.Data.HashFunction.FNV.FNV1aFactory.Instance.Create();
            _jenkins3 = System.Data.HashFunction.Jenkins.JenkinsLookup3Factory.Instance.Create();
            _murmur3  = System.Data.HashFunction.MurmurHash.MurmurHash3Factory.Instance.Create();
            _pearson  = System.Data.HashFunction.Pearson.PearsonFactory.Instance.Create();
            _xxHash   = System.Data.HashFunction.xxHash.xxHashFactory.Instance.Create();
        }