Exemplo n.º 1
0
 public ExistenceStatCollector(string memberName, Configuration configuration, out bool cancel)
 {
     MemberName     = memberName;
     _byteConverter = ByteConverterHelpers.GetByteConverter <T>();
     _murmurHash    = MurmurHash.Create128(managed: true, preference: AlgorithmPreference.X64);
     cancel         = false;
 }
Exemplo n.º 2
0
        public void Save(Stream destination, Skeleton skeleton, bool leaveOpen = false)
        {
            if (skeleton != null)
            {
                mBinding?.Unbind(skeleton);
            }

            // Force modern format if we are saving motions individually
            if (!Format.IsModern())
            {
                Format = BinaryFormat.F2nd;
            }

            if (!string.IsNullOrEmpty(Name))
            {
                Id = MurmurHash.Calculate(Name);
            }

            foreach (var boneInfo in BoneInfos.Where(boneInfo => !string.IsNullOrEmpty(boneInfo.Name)))
            {
                boneInfo.Id = MurmurHash.Calculate(boneInfo.Name);
            }

            Save(destination, leaveOpen);
        }
Exemplo n.º 3
0
        protected internal static int CalculateEmptyHashCode()
        {
            int hash = MurmurHash.Initialize(InitialHash);

            hash = MurmurHash.Finish(hash, 0);
            return(hash);
        }
Exemplo n.º 4
0
        private uint GetHashCode(string str)
        {
            var hash32 = MurmurHash.Create32();
            var bytes  = hash32.ComputeHash(Encoding.UTF32.GetBytes(str));

            return(BitConverter.ToUInt32(bytes));
        }
Exemplo n.º 5
0
        public static string GetHashAsString(string key)
        {
            try
            {
                if (String.IsNullOrEmpty(key))
                {
                    throw new Exception("Incorrect key");
                }

                HashAlgorithm murmur128 = MurmurHash.Create128(0, true, AlgorithmPreference.X86);
                var           hash      = murmur128.ComputeHash(Encoding.ASCII.GetBytes(key));

                if (hash.Length < 16)
                {
                    throw new Exception("Hash Length must be more than 16 byte");
                }

                var builder = new StringBuilder(16);
                for (int i = 0; i < hash.Length; i++)
                {
                    builder.Append(hash[i].ToString("x2"));
                }

                return(builder.ToString().ToUpper());
            }
            catch { throw; }
        }
        public override int GetHashCode()
        {
            int hash = MurmurHash.Initialize();

            hash = MurmurHash.Update(hash, (int)(ActionType));
            return(MurmurHash.Finish(hash, 1));
        }
Exemplo n.º 7
0
        /// <summary>
        /// This method converts the given array of time series values (array of double precision
        /// floats) to a BLOB (byte array).  It also sets the computes the checksum from the resultant
        /// BLOB, and then sets the Checksum and ValueBlob properties of the given ITimeSeriesTrace
        /// object accordingly.
        /// </summary>
        /// <param name="valueArray">The array of time series values to convert into a BLOB</param>
        /// <param name="compressionCode">a generation number that indicates what compression technique to use</param>
        /// <param name="traceObject">object whose TraceNumber property will be used to compute the checksum,
        /// and whose properties will be assigned by this method</param>
        /// <returns>The BLOB that is created from valueArray</returns>
        public static unsafe byte[] ConvertArrayToBlobRegular(
            double[] valueArray, int compressionCode, ITimeSeriesTrace traceObject)
        {
            // The number of bytes required for the BLOB
            int nBin = traceObject.TimeStepCount * sizeof(double);

            // Allocate an array for the BLOB
            Byte[] blobData = new Byte[nBin];
            // Copy the array of doubles that was passed to the method into the byte array.
            // The byte array becomes the BLOB.
            Buffer.BlockCopy(valueArray, 0, blobData, 0, nBin);

            // Compute the checksum using the uncompressed BLOB.  During development, it was
            // demonstrated that the checksum would be computed faster on the compressed BLOB.
            // However, this could make it difficult to upgrade the compression algorithm in the
            // future, because the checksum value would be dependent on the compression algorithm.
            Byte[]  checksum = ComputeTraceChecksum(traceObject.TraceNumber, blobData);
            Boolean checksumChanged
                = (MurmurHash.ByteArraysAreEqual(traceObject.Checksum, checksum) == false);

            // If the checksum did not change, then we will not assign any properties to the traceObject.
            // The result will be that we will return the original ValueBlob.  If the checksum did change,
            // then we compute a new compressed ValueBlob and assign the new values.
            if (checksumChanged)
            {
                traceObject.Checksum = checksum;
                // the BLOB is stored in a compressed form, so our last step is to compress it
                traceObject.ValueBlob = CompressBlob(blobData, compressionCode);
            }
            return(traceObject.ValueBlob);
        }
Exemplo n.º 8
0
        public void PushRecords(IEnumerable <DatasourceRecord> records)
        {
            //TODO: determine how the queues will be named
            var sender = _factory.CreateMessageSender(_config.ReceiverQueue.QueueName);

            var recList = records.ToList(); //avoid reenumerations

            using (var ms = _recordSerializer.Serialize(recList))
            {
                string hashString;

                using (var hasher = MurmurHash.Create128())
                {
                    var hash = hasher.ComputeHash(ms);
                    hashString = Encoding.UTF8.GetString(hash);
                }
                ms.Position = 0;

                var msg = new BrokeredMessage(ms, false)
                {
                    MessageId = hashString
                };

                var sw = new Stopwatch();
                sw.Start();
                sender.Send(msg);
                sw.Stop();

                Log.DebugFormat("Pushed {0} records to topic/queue in {1}ms", recList.Count, sw.ElapsedMilliseconds);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Get computed shard index
        /// </summary>
        /// <param name="key">Sharded identifier</param>
        /// <param name="buckets">Total number of shards</param>
        /// <returns>Index of a shard that is tied to the key</returns>
        public Int32 GetShard(String key, Int32 buckets)
        {
            var murmur128 = MurmurHash.Create32(managed: false);

            var data = murmur128.ComputeHash(Encoding.ASCII.GetBytes(key));

            return(JumpConsistentHash(BitConverter.ToUInt32(data, 0), buckets));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Constructs a <see cref="StringId"/> by hashing a string value.
        /// </summary>
        /// <param name="str">The string value.</param>
        public StringId(string str)
        {
            // string_id values are just Murmur3_32 hashes
            var murmur32 = MurmurHash.Create32(managed: false);
            var hash     = murmur32.ComputeHash(Encoding.UTF8.GetBytes(str));

            Value = (uint)((hash[3] << 24) | (hash[2] << 16) | (hash[1] << 8) | hash[0]);
        }
Exemplo n.º 11
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var bytes     = Encoding.UTF8.GetBytes(logEvent.MessageTemplate.Text);
            var hash      = MurmurHash.ByteHash(bytes);
            var eventType = propertyFactory.CreateProperty("EventType", hash.ToString("x8"));

            logEvent.AddPropertyIfAbsent(eventType);
        }
Exemplo n.º 12
0
        public override int GetHashCode()
        {
            int hash = MurmurHash.Initialize();

            hash = MurmurHash.Update(hash, (int)(GetActionType()));
            hash = MurmurHash.Update(hash, channel);
            return(MurmurHash.Finish(hash, 2));
        }
Exemplo n.º 13
0
        public override int GetHashCode()
        {
            int hash = MurmurHash.Initialize(7);

            hash = MurmurHash.Update(hash, configs.GetHashCode());
            hash = MurmurHash.Finish(hash, 1);
            return(hash);
        }
        static string CalculatePartitionKey(int packetId)
        {
            const int PartitionCountModulusMask = 0xF;

            byte[] hash = MurmurHash.Create32(0, true).ComputeHash(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(packetId))); // hash of big-endian value representation

            return(PartitionKeys[hash[3] & PartitionCountModulusMask]);
        }
Exemplo n.º 15
0
        public static byte[] GetMurmurHashBytes(string str)
        {
            var hash = MurmurHash.Create32();

            var bytes = hash.ComputeHash(Encoding.UTF8.GetBytes(str));

            return(bytes);
        }
Exemplo n.º 16
0
        public override int GetHashCode()
        {
            int hash = MurmurHash.Initialize();

            hash = MurmurHash.Update(hash, offset);
            hash = MurmurHash.Update(hash, action);
            return(MurmurHash.Finish(hash, 2));
        }
Exemplo n.º 17
0
        protected internal static int CalculateHashCode(PredictionContext parent, int returnState)
        {
            int hash = MurmurHash.Initialize(INITIAL_HASH);

            hash = MurmurHash.Update(hash, parent);
            hash = MurmurHash.Update(hash, returnState);
            hash = MurmurHash.Finish(hash, 2);
            return(hash);
        }
 public static byte[] CreateHash(byte[] input)
 {
     if (input == null)
     {
         return(null);
     }
     using HashAlgorithm murmur128 = MurmurHash.Create128();
     return(murmur128.ComputeHash(input));
 }
Exemplo n.º 19
0
        /// <summary>
        /// MurmurHash
        /// </summary>
        /// <param name="k"></param>
        /// <returns></returns>
        public static byte[] ComputeMurmur(string k)
        {
            Murmur128 murmur = MurmurHash.Create128((uint)Environment.TickCount);

            byte[] digest = murmur.ComputeHash(Encoding.UTF8.GetBytes(k));
            murmur.Clear();
            murmur.Dispose();
            return(digest);
        }
Exemplo n.º 20
0
        public override int GetHashCode()
        {
            int hash = MurmurHash.Initialize();

            hash = MurmurHash.Update(hash, (int)(GetActionType()));
            hash = MurmurHash.Update(hash, ruleIndex);
            hash = MurmurHash.Update(hash, actionIndex);
            return(MurmurHash.Finish(hash, 3));
        }
Exemplo n.º 21
0
        public override int GetHashCode()
        {
            int hash = MurmurHash.Initialize();

            hash = MurmurHash.Update(hash, name);
            hash = MurmurHash.Update(hash, GetArgType());
            hash = MurmurHash.Finish(hash, 2);
            return(hash);
        }
Exemplo n.º 22
0
        public int Hash(string input)
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException("HashServiceImpl disposed");
            }

            return(MurmurHash.StringHash(input));
        }
Exemplo n.º 23
0
            /// <summary>
            /// The hash code is only a function of the
            /// <see cref="ATNState.stateNumber"/>
            /// and
            /// <see cref="ATNConfig.context"/>
            /// .
            /// </summary>
            public override int GetHashCode(ATNConfig o)
            {
                int hashCode = MurmurHash.Initialize(7);

                hashCode = MurmurHash.Update(hashCode, o.state.stateNumber);
                hashCode = MurmurHash.Update(hashCode, o.context);
                hashCode = MurmurHash.Finish(hashCode, 2);
                return(hashCode);
            }
Exemplo n.º 24
0
        protected internal static int CalculateHashCode(Antlr4.Runtime.Atn.PredictionContext parent, int returnState)
        {
            int hash = MurmurHash.Initialize(InitialHash);

            hash = MurmurHash.Update(hash, parent);
            hash = MurmurHash.Update(hash, returnState);
            hash = MurmurHash.Finish(hash, 2);
            return(hash);
        }
Exemplo n.º 25
0
        public ulong Hash(string key, uint seed)
        {
            Murmur128 murmur128 = MurmurHash.Create128(seed: seed, preference: AlgorithmPreference.X64);

            byte[] keyToBytes = Encoding.ASCII.GetBytes(key);
            byte[] seedResult = murmur128.ComputeHash(keyToBytes);

            return(BitConverter.ToUInt64(seedResult, 0));
        }
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            var murmur      = MurmurHash.Create32();
            var bytes       = Encoding.UTF8.GetBytes(logEvent.Message);
            var hash        = murmur.ComputeHash(bytes);
            var numericHash = BitConverter.ToUInt32(hash, 0);

            builder.Append($"{numericHash:x8}");
        }
Exemplo n.º 27
0
            public override int GetHashCode()
            {
                int hashCode = MurmurHash.Initialize();

                hashCode = MurmurHash.Update(hashCode, ruleIndex);
                hashCode = MurmurHash.Update(hashCode, predIndex);
                hashCode = MurmurHash.Update(hashCode, isCtxDependent ? 1 : 0);
                hashCode = MurmurHash.Finish(hashCode, 3);
                return(hashCode);
            }
Exemplo n.º 28
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var murmur      = MurmurHash.Create32();
            var bytes       = Encoding.UTF8.GetBytes(logEvent.MessageTemplate.Text);
            var hash        = murmur.ComputeHash(bytes);
            var numericHash = BitConverter.ToUInt32(hash, 0);
            var eventId     = propertyFactory.CreateProperty("HashTag", numericHash);

            logEvent.AddPropertyIfAbsent(eventId);
        }
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var murmurHash  = MurmurHash.Create32();
            var bytes       = Encoding.UTF8.GetBytes(logEvent.MessageTemplate.Text);
            var hash        = murmurHash.ComputeHash(bytes);
            var numericHash = BitConverter.ToUInt32(hash, 0);
            var messageTemplateHashProperty = propertyFactory.CreateProperty("MessageTemplateHash", numericHash.ToString("x8"));

            logEvent.AddPropertyIfAbsent(messageTemplateHashProperty);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Hashes event code based on message to group event types.
        /// </summary>
        /// <param name="messageTemplate">Message Template to hash.</param>
        /// <returns>The numeric hash (in hex) used to identify this event type.</returns>
        /// <remarks>Hashing done based on Murmur, compatible with Seq event identification.</remarks>
        public static string GetTemplateCode(this string messageTemplate)
        {
            using var murmur = MurmurHash.Create32();
            var bytes = Encoding.UTF8.GetBytes(messageTemplate
                                               ?? throw new ArgumentNullException(nameof(messageTemplate)));
            var hash        = murmur.ComputeHash(bytes);
            var numerichash = BitConverter.ToUInt32(hash, 0);

            return($"${numerichash:X}");
        }