Esempio n. 1
0
        /***** Other Operations *****/

        public void CopyTo(DataType[] array, int arrayIndex)
        {
            RedBlackEnumerator <KeyType, DataType> enumerator = GetNodeEnumerator();

            while (enumerator.HasMoreElements())
            {
                array[arrayIndex++] = enumerator.NextElement().Data;
            }
        }
Esempio n. 2
0
        public void CopyTo(KeyValuePair <KeyType, DataType>[] array, int arrayIndex)
        {
            RedBlackEnumerator <KeyType, DataType> enumerator = GetNodeEnumerator();

            while (enumerator.HasMoreElements())
            {
                RedBlackNode <KeyType, DataType> node = enumerator.NextElement();
                array[arrayIndex++] = new KeyValuePair <KeyType, DataType>(node.Key, node.Data);
            }
        }
        public DataType SelectRandomItem(RandomSearchQuality quality)
        {
            if (quality == RandomSearchQuality.Fast)
            {
                double position;
                return(SelectWeightedItem(.5, out position).Data);
            }
            else
            {
                int chosen = randgen.Next(Count);
                RedBlackEnumerator <double, DataType> enumerator = GetNodeEnumerator();
                while (enumerator.HasMoreElements())
                {
                    RedBlackNode <double, DataType> node = enumerator.NextElement();
                    if (chosen-- == 0)
                    {
                        return(node.Data);
                    }
                }

                return(default(DataType));
            }
        }
        // Select a codelet by carefully respecting salience
        public DataType SelectExactItem()
        {
            double salienceToGet = randgen.NextDouble() * salienceSum;
            double salienceSoFar = 0;

            RedBlackEnumerator <double, DataType> enumerator = GetNodeEnumerator();

            while (enumerator.HasMoreElements())
            {
                RedBlackNode <double, DataType> node = enumerator.NextElement();
                salienceSoFar += node.Key;
                if (salienceSoFar >= salienceToGet)
                {
                    return(node.Data);
                }
            }

            // Salience calculation failure!
            Console.WriteLine("WARNING: Salience miscalculation!  Max is " + salienceSoFar.ToString() + " not " + salienceSum.ToString());
            salienceSum = salienceSoFar;
            // Try again!
            return(SelectExactItem());
        }
Esempio n. 5
0
 public DataOnly(RedBlackNode <KeyType, DataType> tnode, bool ascending)
 {
     enumerator = new RedBlackEnumerator <KeyType, DataType>(tnode, ascending);
 }