public void Add(byte[] element) { foreach (uint i in seeds.Select(s => Murmur32.Hash(element))) { bits.Set((int)(i % (uint)bits.Length), true); } }
public override int GetHashCode() { unchecked { return((int)Murmur32.Hash(_bytes)); } }
public void Murmur3_32(string source, uint expected) { var hash = Murmur32.Hash(source, s_seed); var expectedBytes = BitConverter.GetBytes(expected); Assert.IsTrue(hash.SequenceEqual(expectedBytes), $"{BitConverter.ToUInt32(hash)} != {expected}"); }
public override Key Transform(string key) { using (var byteKey = base.Transform(key)) { var hash = Murmur32.ComputeHash(byteKey.Array, 0, byteKey.Length); var array = allocator.Take(4); NetworkOrderConverter.EncodeUInt32(hash, array, 0); return(new Key(allocator, array, 4)); } }
/// <summary> /// Sends a mesh Handshake through the specified channel. /// </summary> /// <param name="channel">The channel to send the packet to.</param> internal static void SendMeshHandshake(this Connection channel) { // Acquire and set the handhshake packet var packet = MeshHandshake.Acquire(); packet.Key = Murmur32.GetHash(Service.Mesh.Cluster); packet.Identity = new GossipMember(Service.Mesh.BroadcastEndpoint); // Send the handshake packet channel.Send(packet); }
public override Key Transform(string key) { using (var tmp = base.Transform(key)) { var retval = new Key(allocator, 4); var hash = Murmur32.ComputeHash(tmp.Array, 0, tmp.Length); NetworkOrderConverter.EncodeUInt32(hash, retval.Array, 0); return(retval); } }
public bool Check(byte[] element) { foreach (uint i in seeds.Select(s => Murmur32.Hash(element, s))) { if (!bits.Get((int)(i % (uint)bits.Length))) { return(false); } } return(true); }
public void TestMurmur32() { byte[] source = Encoding.ASCII.GetBytes( "asdçflkjasçfjaçrlgjaçorigjkljbçladkfjgsaºperouiwa89tuhyjkvsldkfjçaoigfjsadfjkhsdkgjhdlkgjhdkfjbnsdflçkgsriaugfukasyfgskaruyfgsaekufygvsanfbvsdj,fhgwukaygsja,fvkusayfguwayfgsnvfuksaygfkuybhsngfukayeghsmafbsjkfgwlauifgjkshfbilçehrkluayh"); var murmurTest = Murmur32.Hash(source, 144); //var murmurTarget = 1471353736; //obtained with http://murmurhash.shorelabs.com, MurmurHash3 32bit x86 var murmurTarget = murmurTest; for (int i = 0; i < 10000; i++) { murmurTest = Murmur32.Hash(source, 144); Assert.IsTrue(murmurTest == murmurTarget); } }
/// <summary> /// Handles the command. /// </summary> /// <param name="channel">The channel sending the command.</param> /// <param name="command">The command received.</param> private static void OnHandshake(Connection channel, MeshHandshake handshake) { // Deserialize the handshake var endpoint = handshake.Identity.EndPoint; var id = endpoint.ToIdentifier(); // Set the identifier of the channel channel.MeshIdentifier = id; // Validate the credentials if (!(Murmur32.GetHash(Service.Mesh.Cluster) == handshake.Key)) { throw new UnauthorizedAccessException("Cluster access was not authorized."); } // Check if we're trying to connect to ourselves if (Service.Mesh.Identifier == id) { // It's ourselves, remove from tracking //var ep = channel.RemoteEndPoint as IPEndPoint; var port = ((IPEndPoint)Service.Mesh.Binding.EndPoint).Port; var ep = new IPEndPoint(channel.RemoteEndPoint.Address, port); if (ep != null) { Service.Mesh.Members.ForgetPeer(ep); } channel.Close(); return; } // Attempt to register MeshMember node; if (Service.Mesh.Members.TryRegister(endpoint, channel, out node)) { // Send ACK first channel.SendMeshHandshakeAck(); // Send an event since we're connected to the node Service.InvokeNodeConnect(new ClusterEventArgs(node)); } else { channel.Close(); } }
private Cluster FindClusterForKey(byte[] key, bool canCreate) { var hash = Murmur32.Hash(key); lock (LockObject) { if (_clusters.ContainsKey(hash)) { return(_clusters[hash]); } if (canCreate) { var cluster = new Cluster(hash, this.Path); _clusters[hash] = cluster; return(cluster); } } return(null); }
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { if (logEvent == null) { throw new ArgumentNullException(nameof(logEvent)); } if (propertyFactory == null) { throw new ArgumentNullException(nameof(propertyFactory)); } Murmur32 murmur = MurmurHash.Create32(); byte[] bytes = Encoding.UTF8.GetBytes(logEvent.MessageTemplate.Text); byte[] hash = murmur.ComputeHash(bytes); string hexadecimalHash = BitConverter.ToString(hash).Replace("-", ""); LogEventProperty eventId = propertyFactory.CreateProperty("EventType", hexadecimalHash); logEvent.AddPropertyIfAbsent(eventId); }
/// <summary> /// Gets the digest for this version. /// </summary> /// <returns></returns> public int Digest() { // Construct the string list var entities = new SortedSet <string>(); lock (this.Vector) { entities.Add(this.NodeId + ":" + this.Version); foreach (var kvp in this.Vector) { entities.Add(kvp.Key + ":" + kvp.Value); } } // Compute the hash int hash = 0; foreach (var kvp in entities) { hash ^= Murmur32.GetHash(kvp); } return(hash); }
public static uint ComputeHash32(this Murmur32 murmur, byte[] data) { var hash32 = murmur.ComputeHash(data); return(BitConverter.ToUInt32(hash32, 0)); }
public void TestGetHashSize() { Murmur32 murmur3 = new Murmur32(1); murmur3.HashSize.Should().Be(32); }