public void NullComparerHash_EqualsDefaultMurmer3Hash() { var comparer = ComparerBuilder.For <int>().Null(); var objectHash = comparer.GetHashCode(0); Assert.Equal(Murmur3Hash.Create().HashCode, objectHash); }
public void Hash_MatchesWellKnownValue() { var input = 0x64636261; // "abcd" in UTF-8 var hash = Murmur3Hash.Create(0); hash.Combine(input); Assert.Equal(1139631978, hash.HashCode); }
/// <inheritdoc /> protected override int DoGetHashCode(T obj) { unchecked { var ret = Murmur3Hash.Create(SourceGetHashCode(obj)); ret.Combine(_secondSourceGetHashCode(obj)); return(ret.HashCode); } }
/// <inheritdoc /> protected override int DoGetHashCode(IEnumerable <T> obj) { var ret = Murmur3Hash.Create(); foreach (var item in obj) { ret.Combine(Source.GetHashCode(item !)); } return(ret.HashCode); }
public void hash_different_string_should_return_different_result() { var text1 = "$1"; var text2 = "$2"; var hashFunc = new Murmur3Hash(); var hashBytes1 = hashFunc.ComputeHash(Encoding.Unicode.GetBytes(text1)); var hashBytes2 = hashFunc.ComputeHash(Encoding.Unicode.GetBytes(text2)); Assert.NotEqual(hashBytes1.ToHex(), hashBytes2.ToHex()); }
public void hash_the_same_string_should_return_the_same_result() { var text = "!@#$@DSFSDAFS@#$@DSFA@#$"; var hashFunc = new Murmur3Hash(); var hashBytes1 = hashFunc.ComputeHash(Encoding.Unicode.GetBytes(text)); var hashBytes2 = hashFunc.ComputeHash(Encoding.Unicode.GetBytes(text)); var str1 = hashBytes1.ToHex(); var str2 = hashBytes2.ToHex(); Assert.Equal(str1, str2); }
public void hash_the_same_string_multiple_times_should_return_the_same_result() { var text = "!@#$@DSFSDAFS@#$@DSFA@#$"; var hashFunc = new Murmur3Hash(); var hashBytes1 = hashFunc.ComputeHash(Encoding.Unicode.GetBytes(text)); for (int i = 0; i < 100000; i++) { var comparedHashBytes = hashFunc.ComputeHash(Encoding.Unicode.GetBytes(text)); Assert.Equal(hashBytes1.ToHex(), comparedHashBytes.ToHex()); } }
private ProcessInfoFactory() { _cachedKeys = new Dictionary <string, string>(300); _hashAlgorithm = new Murmur3Hash(); }
private static void CreateTrainingData() { var mongoClient = new MongoClient("mongodb://localhost:27017"); var database = mongoClient.GetDatabase("active_app_record"); var collection = database.GetCollection <AppUsageRecord>("daily_records"); var records = collection.Find(Builders <AppUsageRecord> .Filter.Empty).ToList(); var trainingDataCollection = database.GetCollection <ProcessInfoLabeledItem>("training_data"); string userInput; var hashAlgorithm = new Murmur3Hash(); foreach (var appUsageRecord in records) { foreach (var processInfo in appUsageRecord.ActiveApps) { var trainingItem = new ProcessInfoLabeledItem { Title = processInfo.Value.MainWindowTitle, Process = processInfo.Value.ProcessName }; trainingItem.GenerateId(hashAlgorithm); var persistentItem = trainingDataCollection.Find(Builders <ProcessInfoLabeledItem> .Filter.Eq(f => f.Id, trainingItem.Id)).FirstOrDefault(); if (persistentItem != null) { continue; } Console.WriteLine($"Is Title [{processInfo.Value.MainWindowTitle}] in process [{processInfo.Value.ProcessName}] good or bad? n-(Neural), g-(Good), b-(Bad):"); userInput = Console.ReadLine().Trim().ToLower(); if (userInput != "b" && userInput != "n") { trainingItem.Category = Karma.Good; } else if (userInput == "n") { trainingItem.Category = Karma.Neutral; } else { trainingItem.Category = Karma.Bad; } if (persistentItem == null) { Console.WriteLine($"Inserted item with category {trainingItem.Category.ToString()}"); trainingDataCollection.InsertOne(trainingItem); } else { Console.WriteLine($"Updated item with category {trainingItem.Category.ToString()}"); trainingDataCollection.ReplaceOne(Builders <ProcessInfoLabeledItem> .Filter.Eq(f => f.Id, trainingItem.Id), trainingItem); }; } } }