コード例 #1
0
        private void InitializeViaNikseBmp(NikseBitmap nbmp)
        {
            Width   = nbmp.Width;
            Height  = nbmp.Height;
            _colors = new byte[Width * Height];
            var numberOfColoredPixels = 0;

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    var alpha = nbmp.GetAlpha(x, y);
                    if (alpha < 100)
                    {
                        _colors[Width * y + x] = 0;
                    }
                    else
                    {
                        _colors[Width * y + x] = 1;
                        numberOfColoredPixels++;
                    }
                }
            }
            NumberOfColoredPixels = numberOfColoredPixels;
            Hash = MurMurHash3.Hash(_colors);
        }
コード例 #2
0
        private uint GetHashVersion()
        {
            using (var stream = new MemoryStream())
            {
                var writer = new StreamWriter(stream);

                foreach (var candidate in SerializableMemberCandidates.OrderBy(item => item.Name))
                {
                    writer.Write(candidate.Name);
                    writer.Write(VersionStreamSeparator);
                    writer.Write(candidate.Type.GetPrettyName());
                    writer.Write(VersionStreamSeparator);
                }

                foreach (var enumValue in EnumValues)
                {
                    writer.Write(enumValue);
                    writer.Write(VersionStreamSeparator);
                }

                writer.Flush();
                stream.Position = 0;
                return(MurMurHash3.Hash(stream));
            }
        }
コード例 #3
0
        public void PerformingAHash_AreDifferentValues(string text1, string text2)
        {
            // to exercise all cases of chunking the stream
            var firstHash  = MurMurHash3.Hash(text1);
            var secondHash = MurMurHash3.Hash(text2);

            Assert.AreNotEqual(firstHash, secondHash);
        }
コード例 #4
0
ファイル: BinaryOcrBitmap.cs プロジェクト: qyqx/subtitleedit
 public BinaryOcrBitmap(int width, int height)
 {
     Width   = width;
     Height  = height;
     _colors = new byte[Width * Height];
     Hash    = MurMurHash3.Hash(_colors);
     CalcuateNumberOfColoredPixels();
 }
コード例 #5
0
        public void PerformingAHash_SmallValueTests(string text)
        {
            // to exercise all cases of chunking the stream
            var initialHash = MurMurHash3.Hash(text);
            var secondHash  = MurMurHash3.Hash(text);

            Assert.AreEqual(initialHash, secondHash);
        }
コード例 #6
0
 /// <summary>
 /// Utility function that returns an integer checksum of a string.
 /// Used to compare file bodies to know whether they've been hotloaded
 /// or not.
 /// </summary>
 public static int Checksum(string body)
 {
     byte[] input = System.Text.Encoding.UTF8.GetBytes(body);
     using (MemoryStream stream = new MemoryStream(input)) {
         int hash = MurMurHash3.Hash(stream);
         return(hash);
     }
 }
コード例 #7
0
 public void Murmur3Tests()
 {
     Assert.AreEqual(455139366U, MurMurHash3.Hash(GetBytes("asdf")));
     Assert.AreEqual(3902511862U, MurMurHash3.Hash(GetBytes("abcde")));
     Assert.AreEqual(1635893381U, MurMurHash3.Hash(GetBytes("abcdef")));
     Assert.AreEqual(2285673222U, MurMurHash3.Hash(GetBytes("abcdefg")));
     Assert.AreEqual(774705101U, MurMurHash3.Hash(GetBytes("hello world!")));
 }
コード例 #8
0
ファイル: MurMurHash3UnitTest.cs プロジェクト: justmine66/MDA
        public void TestGetMurMurHash3Hash()
        {
            var hash1 = MurMurHash3.Hash("fasdfsafsafsaf");
            var hash2 = MurMurHash3.Hash("afasdfsafsafsaf");
            var hash3 = MurMurHash3.Hash("afasdfsafsafsaf");

            Assert.NotEqual(hash1, hash2);
            Assert.Equal(hash2, hash3);
        }
コード例 #9
0
ファイル: DomainCommands.cs プロジェクト: justmine66/MDA
 protected DomainCommand(
     string aggregateRootId,
     Type aggregateRootType,
     int version = 0) : this()
 {
     Version           = version;
     AggregateRootId   = aggregateRootId;
     AggregateRootType = aggregateRootType;
     PartitionKey      = MurMurHash3.Hash(aggregateRootType.FullName);
     Version           = version;
 }
コード例 #10
0
ファイル: DomainCommands.cs プロジェクト: justmine66/MDA
        protected void Initialize()
        {
            if (AggregateRootType == null || _initialized)
            {
                return;
            }

            Topic        = AggregateRootType.FullName;
            PartitionKey = MurMurHash3.Hash(AggregateRootType.FullName);

            _initialized = true;
        }
コード例 #11
0
        public void PerformingAHash_YieldsAStaticHashValue()
        {
            var text = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
                            standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book
                            It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It
                            was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with
                            desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";

            var initialHash = MurMurHash3.Hash(text);
            var secondHash  = MurMurHash3.Hash(text);

            Assert.AreEqual(initialHash, secondHash);
        }
コード例 #12
0
ファイル: BinaryOcrBitmap.cs プロジェクト: qyqx/subtitleedit
 private void InitializeViaNikseBmp(NikseBitmap nbmp)
 {
     Width   = nbmp.Width;
     Height  = nbmp.Height;
     _colors = new byte[Width * Height];
     for (int y = 0; y < Height; y++)
     {
         for (int x = 0; x < Width; x++)
         {
             this.SetPixel(x, y, nbmp.GetPixel(x, y));
         }
     }
     Hash = MurMurHash3.Hash(_colors);
     CalcuateNumberOfColoredPixels();
 }
コード例 #13
0
ファイル: BCSVParse.cs プロジェクト: McSpazzy/Switch-Toolbox
        private static void CheckHash(string hashStr)
        {
            uint hash = Crc32.Compute(hashStr);

            if (!hashes.ContainsKey(hash))
            {
                hashes.Add(hash, hashStr);
            }

            uint mmhash = MurMurHash3.Hash(hashStr);

            if (!mmhashes.ContainsKey(mmhash))
            {
                mmhashes.Add(mmhash, hashStr);
            }
        }
コード例 #14
0
        public void Add(String key, T o)
        {
            var bucket = Math.Abs(MurMurHash3.Hash(new MemoryStream(Encoding.UTF8.GetBytes(key)))) % Buckets;

            if (bucket != 0 && bucket != 1)
            {
                throw new Exception("temp exception hit ...");
            }
            List <T> vals = null;

            if (!objs.TryGetValue(bucket, out vals))
            {
                objs[bucket] = vals = new List <T>();
            }
            vals.Add(o);
        }
コード例 #15
0
ファイル: PluginManager.cs プロジェクト: ZHJEE/OpenTAP
        private static ResultParameter GetVersionResultParameter(Assembly assembly)
        {
            string hash = " - ";

            using (var file = new FileStream(assembly.Location, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4 * 4096))
            {
                byte[] hashValue = BitConverter.GetBytes(MurMurHash3.Hash(file));

                for (int i = 0; i < 4; i++)
                {
                    hash += String.Format("{0:x2}", hashValue[i]);
                }
            }

            System.Reflection.AssemblyName name = assembly.GetName();
            return(new ResultParameter("Version", name.Name, name.Version.ToString() + hash));
        }
コード例 #16
0
        public void TestMurmur3()
        {
            var rnd = new Random(100);

            byte[] buffer = new byte[100];


            for (int i = 0; i < 10; i++)
            {
                rnd.NextBytes(buffer);
                var hello = MurMurHash3.Hash(buffer);
                Assert.AreEqual(getMurMur(i), hello);
            }

            var test2 = MurMurHash3.Hash("H3wlo World4!!!!");

            Assert.AreEqual(1251584510, test2);
        }
コード例 #17
0
        public HttpPackageRepository(string url)
        {
            url = url.Trim();
            if (Regex.IsMatch(url, "http(s)?://"))
            {
                this.Url = url;
            }
            else
            {
                this.Url = "http://" + url;
            }

            // Trim end to fix redirection. E.g. 'packages.opentap.io/' redirects to 'packages.opentap.io'.
            this.Url   = this.Url.TrimEnd('/');
            defaultUrl = this.Url;
            this.Url   = CheckUrlRedirect(this.Url);

            // Get the users Uniquely generated id
            var id = GetUserId();

            string installDir = ExecutorClient.ExeDir;

            UpdateId = String.Format("{0:X8}{1:X8}", MurMurHash3.Hash(id), MurMurHash3.Hash(installDir));
        }
コード例 #18
0
ファイル: MyMurmurHash3.cs プロジェクト: simonep77/bdo
 uint IHashAlgo.Hash(byte[] data)
 {
     return(MurMurHash3.Hash(data));
 }
コード例 #19
0
 private void UpdateHash()
 {
     hashCode = MurMurHash3.Hash(type, targetMask);
 }
コード例 #20
0
        static void Main(string[] args)
        {
            try
            {
                var s2 = Stopwatch.StartNew();
                for (int i = 0; i < 1000000; i++)
                {
                    var stream = new MemoryStream(Encoding.UTF8.GetBytes("this is a blooming small test"));
                    var z22    = MurMurHash3.Hash(stream);
//                    var mm1 = z22 % 100;
                }
                s2.Stop();
                var q24 = s2.ElapsedMilliseconds;

                Container c   = null;
                var       reg = new MyRegistry(args.Any() == false ? "appsettings.json" : args[0]);
                c = new Container(reg);
                reg.For <IContainer>().Use(c);


                var databasePath = reg.DataDirectory;

                var db = new SQLiteConnection(databasePath + "\\client.mdb");

                db.CreateTable <ClientWithBucket>();

                bool clearBucketState = false;
                if (clearBucketState)
                {
                    db.Delete <ClientWithBucket>("IFuzzyMatcher");
                }

                var clientFactory = new ClientFactory(c);

                var bucketMax = clientFactory.GetClientBuckets <IFuzzyMatcher>().Max();
                var bucketMin = clientFactory.GetClientBuckets <IFuzzyMatcher>().Min();

                if (bucketMin != 0)
                {
                    throw new Exception($"Minimum bucket is not zero it is - {bucketMin} - should be zero");
                }

                if (db.Find <ClientWithBucket>("IFuzzyMatcher") == null)
                {
                    db.Insert(new ClientWithBucket {
                        BucketCount = bucketMax, ClientName = "IFuzzyMatcher"
                    });
                }
                else
                {
                    var ppp = db.Find <ClientWithBucket>("IFuzzyMatcher");
                    if (ppp.BucketCount != bucketMax)
                    {
                        throw new Exception($"We have (dynamic) bucketMax for 'IFuzzyMatcher = {bucketMax} - but last recorded run bucketMax was - {ppp.BucketCount}... cannot continue - need to match bucketCount - or rebuild");
                    }
                }

                var multiplexer = new Multiplexer <FuzzyWordEntry>(bucketMax + 1 /*number of buckets*/);

                CsvReader rdr     = new CsvReader(new StreamReader(@"C:\home\colin\as\input\Retail-Large.csv"));
                var       records = rdr.GetRecords <Retail>();
                records.Take(100000)
                .Do(x => multiplexer.Add(x.Name, new FuzzyWordEntry {
                    DocId = Int32.Parse(x.Id), Phrase = x.Name
                }));

                List <Task> tasks = new List <Task>();
                multiplexer.GetBuckets().Do(x =>
                {
                    tasks.Add(new Task(() => clientFactory.GetClient <IFuzzyMatcher>(x.Item1).AddEntry(x.Item2)));
                    tasks.Last().Start();
                });

                Task.WaitAll(tasks.ToArray());

                foreach (var bucket in clientFactory.GetClientBuckets <IFuzzyMatcher>())
                {
                    var z = clientFactory.GetClient <IFuzzyMatcher>(bucket);

                    if (false)
                    {
                    }
                    else
                    {
                        var q = z.FuzzyQuery(new List <string>(new[]
                                                               { "aleshia tomkiewicz", "daniel towers", "morna dick", "colin dick" }));

                        foreach (var g in q)
                        {
                            Console.WriteLine(g.Query);
                            foreach (var n in g.Detail)
                            {
                                Console.WriteLine($"            {n.Candidate} - {n.Score} - {n.PhraseId}");
                            }
                        }
                    }
                }
                Console.ReadLine();
                L.CloseLog();
            }
            catch (Exception e)
            {
                L.Exception(e);
            }
        }
コード例 #21
0
        private int GetCacheKey(string aggregateRootId, Type aggregateRootType)
        {
            var fullName = string.Format(CacheKeyMask, aggregateRootType.FullName, aggregateRootId);

            return(MurMurHash3.Hash(fullName));
        }
コード例 #22
0
 private int Hash(string key)
 {
     return(MurMurHash3.Hash(key));
 }
コード例 #23
0
ファイル: MyMurmurHash3.cs プロジェクト: simonep77/bdo
 uint IHashAlgo.Hash(string data)
 {
     return(MurMurHash3.Hash(Encoding.UTF8.GetBytes(data)));
 }
コード例 #24
0
        protected RootParsingObject CreateJson(MarketInfo market_info)
        {
            //var market_info = new MarketInfo();
            var root     = new RootParsingObject();
            var listings = new List <Listing>();

            //market_info.ftpFolder = AfewStoreParser.NAME;
            //market_info.website = AfewStoreParser.SITEURL;
            //market_info.currency = AfewStoreParser.CURRENCY;
            //market_info.start_parse_date = DateTime.Now;
            //market_info.end_parse_date = DateTime.Now;
            //market_info.delivery_to_usa = AfewStoreParser.DELIVERY_TO_USA;
            //market_info.photo_parameters.is_watermark_image = false;
            //market_info.photo_parameters.background_color = "white";
            //market_info.currently_language = "en";

            int i = 0;

            foreach (var sneaker in catalog.sneakers)
            {
                var listing = new Listing();

                //id murmurhash
                Encoding encoding = new UTF8Encoding();
                if (sneaker.link != null)
                {
                    byte[] input = encoding.GetBytes(sneaker.link);
                    using (MemoryStream stream = new MemoryStream(input))
                    {
                        listing.id = MurMurHash3.Hash(stream);
                        if (listing.id < 0)
                        {
                            listing.id = listing.id * -1;
                        }
                    }
                }
                else
                {
                    byte[] input = encoding.GetBytes(sneaker.title);
                    using (MemoryStream stream = new MemoryStream(input))
                    {
                        listing.id = MurMurHash3.Hash(stream);
                        if (listing.id < 0)
                        {
                            listing.id = listing.id * -1;
                        }
                    }
                }


                listing.url        = sneaker.link;
                listing.sku        = sneaker.sku;
                listing.title      = sneaker.title;
                listing.brand      = sneaker.brand;
                listing.colorbrand = sneaker.color;
                listing.category   = Helper.ConvertCategoryRusToEng(sneaker.category);
                //if (String.IsNullOrWhiteSpace(listing.category)) Program.Logger.Warn("Wrong category: " + sneaker.category + " sku: " +sneaker.sku);
                listing.sex       = Helper.ConvertSexRusToEng(sneaker.sex);
                listing.price     = sneaker.price;
                listing.old_price = sneaker.oldPrice;
                listing.images    = sneaker.images;
                listing.sizes     = Helper.GetSizeListUs(sneaker.sizes);
                i++;
                listing.position = i;

                listings.Add(listing);
            }

            root.market_info = market_info;
            root.listings    = listings;

            return(root);
            //throw new NotImplementedException();
        }
コード例 #25
0
 /// <summary>
 /// Utility function that returns an integer checksum of a stream.
 /// Used to compare file bodies to know whether they've been hotloaded
 /// or not.
 /// </summary>
 public static int Checksum(Stream stream)
 {
     return(MurMurHash3.Hash(stream));
 }