public FileListManager(string path) { var lines = File.ReadAllLines(path); var absoluteCache = new HashSet <string>(); var directoryCache = new HashSet <string>(); var nameCache = new HashSet <string>(); foreach (var line in lines) { var absolute = line.Trim().UnixPath(false); var directory = Path.GetDirectoryName(absolute).UnixPath(true); var name = Path.GetFileName(absolute); if (absoluteCache.Add(absolute)) { AbsoluteHashes[FNV.FNV1aUI64(absolute.ToSpan())] = absolute; } if (directoryCache.Add(directory)) { DirectoryHashes[FNV.FNV1aUI64(directory.ToSpan())] = directory; } if (nameCache.Add(name)) { NameHashes[FNV.FNV1aUI64(name.ToSpan())] = name; } } // memory efficiency! absoluteCache.Clear(); directoryCache.Clear(); nameCache.Clear(); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true); }
public void Initialize() { hashedList = new List <M3Hash>(); using (var sr = new StreamReader("hash.txt")) { while (!sr.EndOfStream) { string s = sr.ReadLine(); Array.Resize(ref hashList, hashList.Length + 1); hashList[hashList.Length - 1] = s; } } for (var i = 0; i < hashList.Length; i++) { var hash = hashList[i]; byte[] stringbytes = Encoding.ASCII.GetBytes(hash); M3Hash hashItem = new M3Hash(); hashItem.name = hash; hashItem.hash = FNV.Hash32(stringbytes, 0, stringbytes.Length); hashedList.Add(hashItem); } }
static void BucketTest(HashFunction hf) { GetRandomKey[] keyfunc = { new GetRandomKey(HashFunction.GetUniformKey), new GetRandomKey(HashFunction.GetTextKey), new GetRandomKey(HashFunction.GetSparseKey), }; Console.WriteLine("\r\n{0}", hf); Console.WriteLine("\r\n Uniform keys Text keys Sparse keys"); Console.WriteLine("\r\nBits Lower Upper Lower Upper Lower Upper"); for (int bits = 1; bits <= 16; bits++) { Console.Write("{0,2} ", bits); foreach (GetRandomKey getKey in keyfunc) { Console.Write(" "); uint mask = (1U << bits) - 1U; int E = 100; for (int lsb = 0; lsb < 32; lsb += 32 - bits) { if (hf is FNV) { if (lsb == 0) { hf = new FNV(bits); } else { hf = new FNV(); } } int[] buckets = new int[1 << bits]; int n = E * buckets.Length; for (int i = 0; i < n; i++) { byte[] key = getKey(); uint hash = hf.ComputeHash(key); uint bucket = (hash >> lsb) & mask; buckets[bucket]++; } double X = 0.0; double p; for (int i = 0; i < buckets.Length; i++) { double err = buckets[i] - E; X += err * err / E; p = buckets[i] / (double)n; } p = ChiSq(X, buckets.Length - 1); Console.Write(" {0:0.000}", p); } } Console.WriteLine(); } }
public void Initialize() { hashedList = new List <M3Hash>(); for (var i = 0; i < hashList.Length; i++) { var hash = hashList[i]; byte[] stringbytes = Encoding.ASCII.GetBytes(hash); M3Hash hashItem = new M3Hash(); hashItem.name = hash; hashItem.hash = FNV.Hash32(stringbytes, 0, stringbytes.Length); hashedList.Add(hashItem); } }
public void Serialize(DataStorage.FileHeader header, Stream output) { if (header.Version == 2) { this.NameHash = FNV.Hash64(this.Name); this.DataHash = FNV.Hash64(this.Data, 0, this.Data.Length); output.WriteValueU64(this.NameHash); output.WriteValueU64(this.DataHash); } output.WriteStringU16(this.Name); output.WriteValueS32(this.Data.Length); output.Write(this.Data, 0, this.Data.Length); }
private static void LoadVO(string file, ICollection <ExtractableItem> items, IEnumerable <string> audioEvents) { if (!file.EndsWith(".pck")) { return; } string filename = Path.GetFileName(file); // A temporary way to distinguish VO banks and SFX banks if (!filename.Contains("_")) { return; } string locale = filename.Substring(0, filename.IndexOf("_", StringComparison.InvariantCulture)); Dictionary <ulong, string> mappings = new (); foreach (var audioEvent in audioEvents) { if (audioEvent.StartsWith("VO_")) { mappings[FNV.Hash64($"{locale}\\{audioEvent}".ToLowerInvariant())] = audioEvent; } } try { PckFile64 package = new (file); List <ArchiveEntry> entries = package.GetEntries(); foreach (ArchiveEntry archiveEntry in entries) { string name = mappings.ContainsKey(archiveEntry.ID) ? mappings[archiveEntry.ID] : archiveEntry.Name; items.Add(new ExtractableItem(archiveEntry, name)); } } catch (Exception exception) { Console.Error.WriteLine(exception); throw new Exception($"An error has ocurred while opening {file}, no files will be loaded from this archive!"); } }
static void testCustomInput(string input) { Console.WriteLine("Testing FNV1-Hash with string \"" + input + "\""); Console.WriteLine(FNV.fnv1_32Hash(stringToByteArray(input))); Console.WriteLine("Testing FNV1A-Hash with string \"" + input + "\""); Console.WriteLine(FNV.fnv1A_32Hash(stringToByteArray(input))); Console.WriteLine("Testing FNV0-Hash with string \"" + input + "\""); Console.WriteLine(FNV.fnv0_32Hash(stringToByteArray(input)) + '\n'); Console.WriteLine("Testing CRC-Hash with string \"" + input + "\""); Console.WriteLine(CRC.crc_32Hash(stringToByteArray(input))); Console.WriteLine("Testing CRC-B-Hash with string \"" + input + "\""); Console.WriteLine(CRC.crcB_32Hash(stringToByteArray(input)) + '\n'); Console.WriteLine("Testing Adler-Hash with string \"" + input + "\""); Console.WriteLine(Adler.adler_32Hash(stringToByteArray(input)) + '\n'); Console.WriteLine("Testing MD2-Hash with string \"" + input + "\""); Console.WriteLine(MD.md2_128Hash(stringToByteArray(input))); Console.WriteLine("Testing MD4-Hash with string \"" + input + "\""); Console.WriteLine(MD.md4_128Hash(stringToByteArray(input))); Console.WriteLine("Testing MD5-Hash with string \"" + input + "\""); Console.WriteLine(MD.md5_128Hash(stringToByteArray(input))); Console.WriteLine("Testing SHA0-Hash with string \"" + input + "\""); Console.WriteLine(SHA.sha0_160Hash(stringToByteArray(input)) + '\n'); Console.WriteLine("Testing SHA1-Hash with string \"" + input + "\""); Console.WriteLine(SHA.sha1_160Hash(stringToByteArray(input)) + '\n'); Console.WriteLine("Testing SHA2-Hash with string \"" + input + "\""); Console.WriteLine(SHA.sha2_224Hash(stringToByteArray(input))); }
public static ulong CalculateHash(string directoryPath) => FNV.FNV1a_64(directoryPath.ToLower().Trim('/') + "++");
public void TestFNV1() { Assert.Equal("8C974AE0", FNV.fnv1_32Hash(stringToByteArray("HelloKitty"))); }
public void TestFNV1A() { Assert.Equal("2C934346", FNV.fnv1A_32Hash(stringToByteArray("HelloKitty"))); }
public void TestFNV0() { Assert.Equal("6077D641", FNV.fnv0_32Hash(stringToByteArray("HelloKitty"))); }
public async Task <IKeyValueEntity> GetKeyAsync(string key) { var proxy = ServiceProxy.Create <IServiceFabricDictionary>(FNV.Hash64(key), this.uri); return(await proxy.GetKeyAsync(key)); }
public async Task DeleteKeyAsync(string key) { var proxy = ServiceProxy.Create <IServiceFabricDictionary>(FNV.Hash64(key), this.uri); await proxy.DeleteKeyAsync(key); }
public async Task AddKeyAsync(string key, string value) { var proxy = ServiceProxy.Create <IServiceFabricDictionary>(FNV.Hash64(key), this.uri); await proxy.AddKeyAsync(key, value); }
public static ulong CalculateHash(string filePath) => FNV.FNV1a_64(filePath.ToLower() + "++");