Пример #1
0
        public static MeasureResults MeasureSeriesSearch(StructureType types, int start, int count, int step, int control)
        {
            // validate types
            types &= SortedDictionaryMask;

            // initialize result sets
            Tuple <long, long>[] rbTreeResults        = new Tuple <long, long> [count];
            Tuple <long, long>[] vebResults           = new Tuple <long, long> [count];
            Tuple <long, long>[] dphResults           = new Tuple <long, long> [count];
            Tuple <long, long>[] xfastDPHResults      = new Tuple <long, long> [count];
            Tuple <long, long>[] yfastDPHResults      = new Tuple <long, long> [count];
            Tuple <long, long>[] xfastStandardResults = new Tuple <long, long> [count];
            Tuple <long, long>[] yfastStandardResults = new Tuple <long, long> [count];

            // calc the ranges
            int maxval   = 2 * Math.Max((int)BitHacks.RoundToPower((uint)(start + (count - 1) * step)), control);
            int width    = BitHacks.Power2MSB((uint)maxval);
            int positive = (int)(0.9 * control);
            int negative = control - positive;

            // run benchmarks
            int i = 0;

            foreach (var size in Enumerable.Range(0, count).Select(x => start + (x * step)))
            {
                uint[]         searchSet = new uint[control];
                HashSet <uint> itemSet   = GenerateRandomSet(size, maxval);
                uint[]         itemArray = itemSet.ToArray();
                int            j         = 0;
                for (; j < positive; j++)
                {
                    searchSet[j] = itemArray[random.Next(itemArray.Length)];
                }
                while (j < searchSet.Length)
                {
                    uint next = (uint)random.Next(maxval);
                    if (!itemSet.Contains(next))
                    {
                        searchSet[j] = next;
                        j++;
                    }
                }

                if (types.HasFlag(StructureType.RBTree))
                {
                    var dict = new FromMono.SortedDictionary <uint, uint>();
                    Fill(itemArray, itemArray, dict);
                    rbTreeResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict));
                }
                if (types.HasFlag(StructureType.VEB))
                {
                    var dict = new VEBTree <uint>(width);
                    Fill(itemArray, itemArray, dict);
                    vebResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict));
                }
                if (types.HasFlag(StructureType.DPH))
                {
                    var dict = new HashTable <uint>();
                    Fill(itemArray, itemArray, dict);
                    dphResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict));
                }
                if (types.HasFlag(StructureType.XTrieDPH))
                {
                    var dict = new XFastTrie <uint>(width);
                    Fill(itemArray, itemArray, dict);
                    xfastDPHResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict));
                }
                if (types.HasFlag(StructureType.YTrieDPH))
                {
                    var dict = new YFastTrie <uint>(width);
                    Fill(itemArray, itemArray, dict);
                    yfastDPHResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict));
                }
                if (types.HasFlag(StructureType.XTrieStandard))
                {
                    var dict = XFastTrie <uint> .FromDictionary <Dictionary <uint, XFastNode> >(width);

                    Fill(itemArray, itemArray, dict);
                    xfastStandardResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict));
                }
                if (types.HasFlag(StructureType.YTrieStandard))
                {
                    var dict = YFastTrie <uint> .FromDictionary <Dictionary <uint, XFastNode> >(width);

                    Fill(itemArray, itemArray, dict);
                    yfastStandardResults[i] = Tuple.Create((long)size, MeasureSearch(searchSet, dict));
                }
                i++;
            }

            // dump the results
            MeasureResults results = new MeasureResults(types, maxval);

            results.SetResults(StructureType.RBTree, rbTreeResults);
            results.SetResults(StructureType.VEB, vebResults);
            results.SetResults(StructureType.DPH, dphResults);
            results.SetResults(StructureType.XTrieDPH, xfastDPHResults);
            results.SetResults(StructureType.YTrieDPH, yfastDPHResults);
            results.SetResults(StructureType.XTrieStandard, xfastStandardResults);
            results.SetResults(StructureType.YTrieStandard, yfastStandardResults);
            return(results);
        }
Пример #2
0
        public static MeasureResults MeasureSeriesDelete(StructureType types, int start, int count, int step)
        {
            // validate types
            types &= DictionaryMask;

            // initialize result sets
            Tuple <long, long>[] rbTreeResults        = new Tuple <long, long> [count];
            Tuple <long, long>[] vebResults           = new Tuple <long, long> [count];
            Tuple <long, long>[] dphResults           = new Tuple <long, long> [count];
            Tuple <long, long>[] xfastDPHResults      = new Tuple <long, long> [count];
            Tuple <long, long>[] yfastDPHResults      = new Tuple <long, long> [count];
            Tuple <long, long>[] xfastStandardResults = new Tuple <long, long> [count];
            Tuple <long, long>[] yfastStandardResults = new Tuple <long, long> [count];

            // calc the ranges
            int maxval = 2 * (int)BitHacks.RoundToPower((uint)(start + (count - 1) * step));
            int width  = BitHacks.Power2MSB((uint)maxval);

            // run benchmarks
            int i = 0;

            foreach (var size in Enumerable.Range(0, count).Select(x => start + (x * step)))
            {
                var itemSet = GenerateRandomSet(size, maxval).ToArray();
                var delSet  = itemSet.ToArray();
                Shuffle(delSet);

                if (types.HasFlag(StructureType.RBTree))
                {
                    var dict = new FromMono.SortedDictionary <uint, uint>();
                    Fill(delSet, delSet, dict);
                    rbTreeResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict));
                }
                if (types.HasFlag(StructureType.VEB))
                {
                    var dict = new VEBTree <uint>(width);
                    Fill(delSet, delSet, dict);
                    vebResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict));
                }
                if (types.HasFlag(StructureType.DPH))
                {
                    var dict = new HashTable <uint>();
                    Fill(delSet, delSet, dict);
                    dphResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict));
                }
                if (types.HasFlag(StructureType.XTrieDPH))
                {
                    var dict = new XFastTrie <uint>(width);
                    Fill(delSet, delSet, dict);
                    xfastDPHResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict));
                }
                if (types.HasFlag(StructureType.YTrieDPH))
                {
                    var dict = new YFastTrie <uint>(width);
                    Fill(delSet, delSet, dict);
                    yfastDPHResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict));
                }
                if (types.HasFlag(StructureType.XTrieStandard))
                {
                    var dict = XFastTrie <uint> .FromDictionary <Dictionary <uint, XFastNode> >(width);

                    Fill(delSet, delSet, dict);
                    xfastStandardResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict));
                }
                if (types.HasFlag(StructureType.YTrieStandard))
                {
                    var dict = YFastTrie <uint> .FromDictionary <Dictionary <uint, XFastNode> >(width);

                    Fill(delSet, delSet, dict);
                    yfastStandardResults[i] = Tuple.Create((long)size, MeasureDelete(delSet, dict));
                }
                i++;
            }

            // dump the results
            MeasureResults results = new MeasureResults(types, maxval);

            results.SetResults(StructureType.RBTree, rbTreeResults);
            results.SetResults(StructureType.VEB, vebResults);
            results.SetResults(StructureType.DPH, dphResults);
            results.SetResults(StructureType.XTrieDPH, xfastDPHResults);
            results.SetResults(StructureType.YTrieDPH, yfastDPHResults);
            results.SetResults(StructureType.XTrieStandard, xfastStandardResults);
            results.SetResults(StructureType.YTrieStandard, yfastStandardResults);
            return(results);
        }
Пример #3
0
 public static YFastTrie <T> FromDictionary <TDict>(int width) where TDict : IDictionary <uint, XFastNode>, new()
 {
     return(new YFastTrie <T>(XFastTrie <RBTree> .FromDictionary <TDict>(width)));
 }