示例#1
0
        public void GuidHashMap_TryFindByHash_ShouldOk()
        {
            var guidHashMap = new GuidHashMap();
            var now         = new DateTime(2000, 1, 1);

            for (int i = 0; i < 10; i++)
            {
                guidHashMap.Add(Guid.NewGuid(), now.AddSeconds(1));
            }

            var hashKeys = guidHashMap.Items.Keys.ToList();

            foreach (var hashKey in hashKeys)
            {
                var display = guidHashMap.TryFindByHash(hashKey).Hash;
                display.Log();
            }
        }
示例#2
0
        public void GuidHashMap_TryFindAllByShortHash_ShouldOk()
        {
            var guidHashMap = new GuidHashMap();
            var now         = new DateTime(2000, 1, 1);

            for (int i = 0; i < 1000; i++)
            {
                guidHashMap.Add(Guid.NewGuid(), now.AddSeconds(1));
            }

            var hashKeys   = guidHashMap.Items.Keys.ToList();
            var countGroup = new Dictionary <int, int>();

            foreach (var hashKey in hashKeys)
            {
                var shortKey = hashKey.Substring(0, 4);
                var length   = guidHashMap.TryFindAllByShortHash(shortKey).Length;
                if (length > 1)
                {
                    //var display = shortKey + " Find Count: " + length;
                    //display.Log();
                    if (!countGroup.ContainsKey(length))
                    {
                        countGroup[length] = 1;
                    }
                    else
                    {
                        countGroup[length] = countGroup[length] + 1;
                    }
                }
            }

            foreach (var i in countGroup)
            {
                string.Format("find {0} total: {1}", i.Key, i.Value).Log();
            }
        }