Пример #1
0
        //private static bool TEST_ACTIVE = true;

        //private static void TestRequestQueue()
        //{
        //    RequestQueue<string> strQueue = new RequestQueue<string>(8);
        //    long beginTicks = DateTime.Now.Ticks;
        //    TEST_ACTIVE = true;

        //    for (int i = 0; i < 8; i++)
        //    {
        //        Task.Factory.StartNew(TestEnqueue, strQueue);
        //    }
        //    Task.Factory.StartNew(TestDequeue, strQueue);

        //    while (DateTime.Now.Ticks - beginTicks < 1 * 10000000) ;
        //    TEST_ACTIVE = false;
        //}

        //private static Action<object> TestEnqueue = (object obj) =>
        //{
        //    RequestQueue<string> strQueue = obj as RequestQueue<string>;
        //    Random rand = new Random();
        //    while (TEST_ACTIVE)
        //    {
        //        int pk = rand.Next(0, 8);
        //        strQueue.Enqueue("123", pk);
        //    }
        //};

        //private static Action<object> TestDequeue = (object obj) =>
        //{
        //    RequestQueue<string> strQueue = obj as RequestQueue<string>;
        //    Random rand = new Random();
        //    string value = null;
        //    while (TEST_ACTIVE)
        //    {
        //        int pk = rand.Next(0, 8);
        //        if (strQueue.TryDequeue(out value))
        //        {
        //            Debug.Assert(value != null);
        //        }
        //    }
        //};

        private static void ZipfTest()
        {
            Dictionary <int, int> dict = new Dictionary <int, int>();
            Zipf zipf = new Zipf(100000, 0.8, false);

            for (int i = 0; i < 200000; i++)
            {
                int key = zipf.Next();
                if (dict.ContainsKey(key))
                {
                    dict[key]++;
                }
                else
                {
                    dict[key] = 1;
                }
            }

            List <KeyValuePair <int, int> > myList = dict.ToList();

            myList.Sort(
                delegate(KeyValuePair <int, int> pair1,
                         KeyValuePair <int, int> pair2)
            {
                return(pair2.Value.CompareTo(pair1.Value));
            }
                );

            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(myList[i].Key + " " + myList[i].Value);
            }
        }