/// <summary>
        /// Produces a copy of this list in which the item order has been randomized.
        /// </summary>
        /// <returns>List containing items in random order.</returns>
        public PFKeyValueList <K, V> Randomize()
        {
            PFKeyValueList <K, V> randomizedList = new PFKeyValueList <K, V>();
            PFKeyValueListSorted <int, stKeyValuePair <K, V> > sortList = new PFKeyValueListSorted <int, stKeyValuePair <K, V> >();
            RandomNumber rnd = new RandomNumber();
            int          min = 0;
            int          max = 200000000;

            for (int i = 0; i < this.Count; i++)
            {
                stKeyValuePair <K, V> item = this[i];
                int key = rnd.GenerateRandomNumber(min, max);
                sortList.Add(key, item);
            }

            IEnumerator <KeyValuePair <int, stKeyValuePair <K, V> > > enumerator = sortList.GetEnumerator();

            while (enumerator.MoveNext())
            {
                // Get current key value pair
                stKeyValuePair <int, stKeyValuePair <K, V> > keyValuePair = new stKeyValuePair <int, stKeyValuePair <K, V> >(enumerator.Current.Key, enumerator.Current.Value);
                randomizedList.Add(keyValuePair.Value);
            }



            return(randomizedList);
        }
Beispiel #2
0
        /// <summary>
        /// Merges current list with the list specified in the parameter.
        /// </summary>
        /// <param name="list">List to merge with.</param>
        /// <returns>Merged list.</returns>
        public PFKeyValueListSorted <K, V> Merge(PFKeyValueListSorted <K, V> list)
        {
            PFKeyValueListSorted <K, V> mergedList = new PFKeyValueListSorted <K, V>();

            if (list == null)
            {
                return(mergedList);
            }

            IEnumerator <KeyValuePair <K, V> > enumerator = this.GetEnumerator();

            while (enumerator.MoveNext())
            {
                // Get current key value pair
                stKeyValuePair <K, V> keyValuePair = new stKeyValuePair <K, V>(enumerator.Current.Key, enumerator.Current.Value);
                mergedList.Add(keyValuePair.Key, keyValuePair.Value);
            }


            IEnumerator <KeyValuePair <K, V> > enumList = list.GetEnumerator();

            while (enumList.MoveNext())
            {
                // Get current key value pair
                stKeyValuePair <K, V> keyValuePair = new stKeyValuePair <K, V>(enumList.Current.Key, enumList.Current.Value);
                mergedList.Add(keyValuePair.Key, keyValuePair.Value);
            }

            return(mergedList);
        }
Beispiel #3
0
        /// <summary>
        /// Routine that concatenates two or more lists into one list.
        /// </summary>
        /// <param name="lists">List of list objects to be concatenated.</param>
        /// <returns>Concatenated list.</returns>
        public static PFKeyValueListSorted <K, V> ConcatenateLists(PFList <PFKeyValueListSorted <K, V> > lists)
        {
            PFKeyValueListSorted <K, V> concatenatedList = new PFKeyValueListSorted <K, V>();

            if (lists == null)
            {
                return(concatenatedList);
            }

            for (int listInx = 0; listInx < lists.Count; listInx++)
            {
                PFKeyValueListSorted <K, V> tempList = lists[listInx];
                if (tempList != null)
                {
                    IEnumerator <KeyValuePair <K, V> > enumerator = tempList.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        // Get current key value pair
                        stKeyValuePair <K, V> keyValuePair = new stKeyValuePair <K, V>(enumerator.Current.Key, enumerator.Current.Value);
                        concatenatedList.Add(keyValuePair.Key, keyValuePair.Value);
                    }
                }
            }

            return(concatenatedList);
        }
Beispiel #4
0
        /// <summary>
        /// Converts PFKeyValueList object to PFKeyValueListSorted object.
        /// </summary>
        /// <param name="kvlist"></param>
        /// <returns>PFKeyValueListSorted object.</returns>
        public static PFKeyValueListSorted <K, V> ConvertPFKeyValueListToSortedList(PFKeyValueList <K, V> kvlist)
        {
            PFKeyValueListSorted <K, V> kvlistSorted = new PFKeyValueListSorted <K, V>();

            kvlist.SetToBOF();
            stKeyValuePair <K, V> stKeyValuePair = kvlist.FirstItem;

            while (!kvlist.EOF)
            {
                kvlistSorted.Add(stKeyValuePair.Key, stKeyValuePair.Value);
                stKeyValuePair = kvlist.NextItem;
            }
            return(kvlistSorted);
        }
Beispiel #5
0
        /// <summary>
        /// Copies current list to a new list.
        /// </summary>
        /// <returns>Copy of list.</returns>
        public PFKeyValueListSorted <K, V> Copy()
        {
            PFKeyValueListSorted <K, V> newList = new PFKeyValueListSorted <K, V>();

            IEnumerator <KeyValuePair <K, V> > enumerator = this.GetEnumerator();

            while (enumerator.MoveNext())
            {
                // Get current key value pair
                stKeyValuePair <K, V> keyValuePair = new stKeyValuePair <K, V>(enumerator.Current.Key, enumerator.Current.Value);
                newList.Add(keyValuePair.Key, keyValuePair.Value);
            }

            return(newList);
        }
Beispiel #6
0
        /// <summary>
        /// Merges current list with the array of lists specified in the parameter.
        /// </summary>
        /// <param name="lists">Lists to merge with.</param>
        /// <returns>Merged list.</returns>
        public PFKeyValueListSorted <K, V> Merge(PFKeyValueListSorted <K, V>[] lists)
        {
            PFKeyValueListSorted <K, V> mergedList = new PFKeyValueListSorted <K, V>();

            if (lists == null)
            {
                return(mergedList);
            }

            IEnumerator <KeyValuePair <K, V> > enumerator = this.GetEnumerator();

            while (enumerator.MoveNext())
            {
                // Get current key value pair
                stKeyValuePair <K, V> keyValuePair = new stKeyValuePair <K, V>(enumerator.Current.Key, enumerator.Current.Value);
                mergedList.Add(keyValuePair.Key, keyValuePair.Value);
            }


            for (int listInx = 0; listInx < lists.Length; listInx++)
            {
                PFKeyValueListSorted <K, V> tempList = lists[listInx];
                if (tempList != null)
                {
                    IEnumerator <KeyValuePair <K, V> > enumTempList = tempList.GetEnumerator();
                    while (enumTempList.MoveNext())
                    {
                        // Get current key value pair
                        stKeyValuePair <K, V> keyValuePair = new stKeyValuePair <K, V>(enumTempList.Current.Key, enumTempList.Current.Value);
                        mergedList.Add(keyValuePair.Key, keyValuePair.Value);
                    }
                }
            }

            return(mergedList);
        }