Ejemplo n.º 1
0
        public void murmur_128(string text, uint seed, ulong hashA, ulong hashB)
        {
            ulong a, b;

            Murmur3.Hash128(Encoding.ASCII.GetBytes(text), seed, out a, out b);
            Assert.Equal(hashA, a);
            Assert.Equal(hashB, b);
        }
Ejemplo n.º 2
0
        public void identifier_hash_collision_test()
        {
            var seed = 777u;
            var ids  = _identifiers.Value;

            Console.WriteLine($"Total Identifier Count: {ids.Length}");
            Console.WriteLine($"Avg. Identifier Length: {ids.Average(n => n.Length)}");
            Console.WriteLine($"Max. Identifier Length: {ids.Max(n => n.Length)}");

            Test("Murmur3 32bit", ids, id => Murmur3.Hash32(Encoding.ASCII.GetBytes(id), seed));
            Test("Murmur3 16bit", ids, id => To16Bit(Murmur3.Hash32(Encoding.ASCII.GetBytes(id), seed)));
        }
Ejemplo n.º 3
0
        UInt64 totalProcessedReferences; //Total processed (met the hashing criteria) references

        #endregion Fields

        #region Constructors

        public SHARDSGhostCache(UInt32 cacheBlockSize, UInt64 maxCacheSizeBytes, bool noisyOutput)
        {
            Debug.Assert(maxCacheSizeBytes % cacheBlockSize == 0);
            UInt64 num_blocks_req = maxCacheSizeBytes / cacheBlockSize;
            //if (num_blocks_req > Int32.MaxValue)
            //{
            //    Console.WriteLine("StackDepthGhostCache FAILED to initialize; {0} blocks of size {1} == {2} bytes total is too large",
            //        num_blocks_req, cacheBlockSize, maxCacheSizeBytes);
            //    Debug.Assert(0 == 1);
            //}

            //this.totalAvailCacheBlocks = (Int32)num_blocks_req;
            this.totalAvailCacheBlocks = (Int64)num_blocks_req;

            //set the sampling parameters
            this.modulusP = 16777216; //2^24, as specified in the paper
            this.modulusPPower = 24; // power of the modulus (for efficient reuse distance scaling)
            this.thresholdT = 167772; // yields sampling rate of 0.01
            this.samplingRateR = (double)this.thresholdT / (double)this.modulusP; //just in case we need the sampling rate in a local variable
            this.Murmur3HashFunction = new Murmur3();

            this.distanceTree = new SortedList<UInt64, GhostCacheElement>(new ReverseComparer());
            this.hashTableLookup = new Dictionary<UInt64, GhostCacheElement>();
            this.refreshCounter = 0;

            this.cacheBlockSize = cacheBlockSize;
            this.maxCacheSizeBytes = maxCacheSizeBytes;
            this.totalCacheReferences = 0;
            this.totalProcessedReferences = 0;
            this.reuseAccessHistogram = new UInt32[(Int64)num_blocks_req];

            //Initialize counters to 0
            for (Int64 i = 0; i < this.totalAvailCacheBlocks; i++)
            {
                this.reuseAccessHistogram[i] = 0;
            }
            //Array.Clear(this.reuseAccessHistogram, 0, (Int32)num_blocks_req);

            this.noisyOutput = noisyOutput;
        }
Ejemplo n.º 4
0
        public static byte[] MurmurHash(this string data)
        {
            var hasher = new Murmur3();

            return(hasher.ComputeHash(Encoding.Unicode.GetBytes(data)));
        }
Ejemplo n.º 5
0
 public void murmur_32(string text, uint seed, uint hash)
 {
     Assert.Equal(hash, Murmur3.Hash32(Encoding.ASCII.GetBytes(text), seed));
 }