Exemplo n.º 1
0
            public Preparation(int count)
            {
                // Although this appears to be "random", it is always seeded with the same value, so it always produces the same
                // sequence of keys (with uniform distribution). The perf test will use the same set of keys and therefore the
                // same code paths every time it is run. I.E. This is the most convenient way to generate a large set of test keys.
                ParkAndMiller random = new ParkAndMiller(Seed);

                insertKeys = new int[count];
                AVLTreeList <int> used = new AVLTreeList <int>((uint)count, AllocationMode.DynamicDiscard);

                for (int i = 0; i < count; i++)
                {
                    do
                    {
                        insertKeys[i] = random.Next();
                    } while (used.ContainsKey(insertKeys[i]));
                    used.Add(insertKeys[i]);
                }
                deleteKeys = new int[count];
                for (int i = 0; i < count; i++)
                {
                    int key2;
                    int j = 0;
                    do
                    {
                        j++;
                        deleteKeys[i] = j < 100 ? random.Next() : Int32.MinValue;
                    } while (!used.NearestGreaterOrEqual(deleteKeys[i], out key2));
                    used.Remove(key2);
                }
            }
Exemplo n.º 2
0
            public Preparation(int count)
            {
                // Although this appears to be "random", it is always seeded with the same value, so it always produces the same
                // sequence of keys (with uniform distribution). The perf test will use the same set of keys and therefore the
                // same code paths every time it is run. I.E. This is the most convenient way to generate a large set of test keys.
                ParkAndMiller random = new ParkAndMiller(Seed);

                inserts = new STuple <int, int, int> [count];
                int[] xExtents = new int[count];
                deletes = new int[count];
                int xExtent = 0;

                for (int i = 0; i < count; i++)
                {
                    int xStart  = random.Next() % Math.Max(1, xExtent);
                    int xLength = random.Next() % 100 + 1;
                    int yLength = random.Next() % 100 + 1;
                    inserts[i]  = new STuple <int, int, int>(xStart, xLength, yLength);
                    xExtent    += xLength;
                    xExtents[i] = xExtent;
                }
                for (int i = 0; i < count; i++)
                {
                    deletes[i] = random.Next() % xExtents[count - 1 - i];
                }
            }
Exemplo n.º 3
0
        public int Next()
        {
            int S;
            int lo;
            int hi;

#if DEBUG
            if (CheckParkAndMiller_DBG)
            {
                if (!Checked_DBG)
                {
                    Checked_DBG = true;

                    ParkAndMiller State_DBG = new ParkAndMiller(1);
                    int           Value_DBG = -1;
                    for (int Counter_DBG = 1; Counter_DBG <= 10000; Counter_DBG++)
                    {
                        Value_DBG = State_DBG.Next();
                    }
                    if (Value_DBG != 1043618065)
                    {
                        Debug.Assert(false);
                        throw new InvalidOperationException();
                    }
                }
            }
#endif

            S = this.seed;

#if DEBUG
            if ((S < Minimum) || (S > Maximum))
            {
                // seed is out of range
                Debug.Assert(false);
                throw new InvalidOperationException();
            }
#endif
            hi = S / Q;
            lo = S % Q;
            S  = A * lo - R * hi;
            if (S <= 0)
            {
                S += M;
            }

#if DEBUG
            if ((S < Minimum) || (S > Maximum))
            {
                // seed exceeded range
                Debug.Assert(false);
                throw new InvalidOperationException();
            }
#endif

            this.seed = S;
            return(S);
        }
Exemplo n.º 4
0
 private static void LoadTree(IRangeMap <int> tree, int count, ref ParkAndMiller random)
 {
     for (int i = 0; i < count; i++)
     {
         int start = random.Next() % Math.Max(1, tree.GetExtent());
         tree.NearestLessOrEqual(start, out start);
         int xLength = random.Next() % 100 + 1;
         tree.Insert(start, xLength, random.Next());
     }
 }
Exemplo n.º 5
0
        private static void UnloadTree(IRangeMap <int> tree, int?count, ref ParkAndMiller random)
        {
            int i = 0;

            while ((count.HasValue && (i < count.Value)) || (!count.HasValue && (tree.Count != 0)))
            {
                int start = random.Next() % tree.GetExtent();
                tree.NearestLessOrEqual(start, out start);
                tree.Delete(start);
                i++;
            }
        }
Exemplo n.º 6
0
        private static void UnloadTree(IMultiRankMap <int, int> tree, int?count, ref ParkAndMiller random)
        {
            int i = 0;

            while ((count.HasValue && (i < count.Value)) || (!count.HasValue && (tree.Count != 0)))
            {
                int rank = random.Next() % unchecked ((int)tree.RankCount);
                int key  = tree.GetKeyByRank(rank);
                tree.Remove(key);
                i++;
            }
        }
Exemplo n.º 7
0
 private static void LoadTree(IMultiRankMap <int, int> tree, int count, ref ParkAndMiller random)
 {
     for (int i = 0; i < count; i++)
     {
         int key       = random.Next();
         int rankCount = random.Next() % 100 + 1;
         tree.TryAdd(key, key, rankCount);
     }
     if (tree.Count < .999 * count)
     {
         throw new InvalidOperationException("too many collisions - choose a better seed");
     }
 }
Exemplo n.º 8
0
        public override void TimedIteration()
        {
            // Although this appears to be "random", it is always seeded with the same value, so it always produces the same
            // sequence of keys (with uniform distribution). The perf test will use the same set of keys and therefore the
            // same code paths every time it is run. I.E. This is the most convenient way to generate a large set of test keys.
            ParkAndMiller random = new ParkAndMiller(Seed);

            LoadTree(tree, count, ref random);
            UnloadTree(tree, null, ref random);

            if (tree.Count != 0)
            {
                throw new InvalidOperationException();
            }
        }
Exemplo n.º 9
0
            public Preparation(int count)
            {
                // Although this appears to be "random", it is always seeded with the same value, so it always produces the same
                // sequence of keys (with uniform distribution). The perf test will use the same set of keys and therefore the
                // same code paths every time it is run. I.E. This is the most convenient way to generate a large set of test keys.
                ParkAndMiller random = new ParkAndMiller(Seed);

                keys    = new int[count];
                indices = new int[count];
                AVLTreeList <int> used = new AVLTreeList <int>((uint)count, AllocationMode.DynamicRetainFreelist);

                for (int i = 0; i < count; i++)
                {
                    do
                    {
                        keys[i] = random.Next();
                    } while (used.ContainsKey(keys[i]));
                    indices[i] = random.Next() % (i - count);
                }
            }
Exemplo n.º 10
0
        public override void UntimedPrepare()
        {
            // Although this appears to be "random", it is always seeded with the same value, so it always produces the same
            // sequence of keys (with uniform distribution). The perf test will use the same set of keys and therefore the
            // same code paths every time it is run. I.E. This is the most convenient way to generate a large set of test keys.
            ParkAndMiller random = new ParkAndMiller(Seed);

            tree = makeTree(count);

            if ((tree is IRankMap <int, int>) || (tree is IMultiRankMap <int, int>) || (tree is IOrderedMap <int, int>))
            {
                // keyed collection
                for (int i = 0; i < count; i++)
                {
                    int key = random.Next();
                    if (tree is IRankMap <int, int> )
                    {
                        if (!((IRankMap <int, int>)tree).TryAdd(key, random.Next()))
                        {
                            i--;
                        }
                    }
                    else if (tree is IMultiRankMap <int, int> )
                    {
                        if (!((IMultiRankMap <int, int>)tree).TryAdd(key, random.Next(), random.Next() % 10 + 1))
                        {
                            i--;
                        }
                    }
                    else if (tree is IOrderedMap <int, int> )
                    {
                        if (!((IOrderedMap <int, int>)tree).TryAdd(key, random.Next()))
                        {
                            i--;
                        }
                    }
                    else
                    {
                        Debug.Assert(false);
                        throw new ArgumentException();
                    }
                }
            }
            else if ((tree is IRange2Map <int>) || (tree is IRangeMap <int>))
            {
                // indexed collection
                for (int i = 0; i < count; i++)
                {
                    if (tree is IRange2Map <int> )
                    {
                        int extent = ((IRange2Map <int>)tree).GetExtent(Side.X);
                        int start  = extent != 0 ? random.Next() % (extent + 1) : 0;
                        ((IRange2Map <int>)tree).NearestLessOrEqual(start, Side.X, out start);
                        ((IRange2Map <int>)tree).Insert(start, Side.X, random.Next() % 10 + 1, random.Next() % 10 + 1, random.Next());
                    }
                    else if (tree is IRangeMap <int> )
                    {
                        int extent = ((IRangeMap <int>)tree).GetExtent();
                        int start  = extent != 0 ? random.Next() % (extent + 1) : 0;
                        ((IRangeMap <int>)tree).NearestLessOrEqual(start, out start);
                        ((IRangeMap <int>)tree).Insert(start, random.Next() % 10 + 1, random.Next());
                    }
                    else
                    {
                        Debug.Assert(false);
                        throw new ArgumentException();
                    }
                }
            }
            else
            {
                Debug.Assert(false);
                throw new ArgumentException();
            }
        }