/// <summary>
 /// Sort elements in an Array object, using the Order
 /// delegate to determine how items should be sorted.
 /// </summary>
 /// <param name="table">Array to be sorted</param>
 /// <param name="sortHandler">Delegate to manage
 /// sort order.</param>
 public void Sort(Array table, Order sortHandler)
 {
     if(sortHandler == null)
         throw new ArgumentNullException();
     
     bool nothingSwapped = false;
     int pass = 1;
     while(nothingSwapped == false)
     {
         nothingSwapped = true;
         for(int index = 0; index < table.Length - pass; ++index)
         {
             // Use an Order delegate to determine the sort order.
             if(sortHandler(table.GetValue(index),
                 table.GetValue(index + 1)) == false)
             {
                 nothingSwapped = false;
                 object temp = table.GetValue(index);
                 table.SetValue(table.GetValue(index + 1), index);
                 table.SetValue(temp, index + 1);
             }
         }
         ++pass;
     }
 }
Example #2
0
 public static void swapTo(float input, Array dest, int pos)
 {
     byte[] tmpIn = BitConverter.GetBytes(input);
      dest.SetValue(tmpIn[3], pos);
      dest.SetValue(tmpIn[2], pos + 1);
      dest.SetValue(tmpIn[1], pos + 2);
      dest.SetValue(tmpIn[0], pos + 3);
 }
 public static void Shuffle(this Random rng, Array array)
 {
     int n = array.Length;
     while (n > 1) {
         int k = rng.Next (n--);
         object temp = array.GetValue (n);
         array.SetValue (array.GetValue (k), n);
         array.SetValue (temp, k);
     }
 }
Example #4
0
        protected override void SortGenericArray(Array items, int left, int right)
        {
            int lo = left;
            int hi = right;

            if (lo >= hi)
            {
                return;
            }

            int mid = (lo + hi) / 2;

            // Partition the items into two lists and Sort them recursively
            SortGenericArray(items, lo, mid);
            SortGenericArray(items, mid + 1, hi);

            // Merge the two sorted lists
            int end_lo = mid;
            int start_hi = mid + 1;

            while ((lo <= end_lo) && (start_hi <= hi))
            {

                if (this.comparer.Compare(items.GetValue(lo), items.GetValue(start_hi)) < 0)
                {
                    lo++;
                }
                else
                {
                    /*
                  *  items[lo] >= items[start_hi]
                  *  The next element comes from the second items,
                  *  move the items[start_hi] element into the next
                  *  position and shuffle all the other elements up.
                  */
                    object T = items.GetValue(start_hi);

                    for (int k = start_hi - 1; k >= lo; k--)
                    {
                        items.SetValue(items.GetValue(k), k + 1);
                    }

                    items.SetValue(T, lo);
                    lo++;
                    end_lo++;
                    start_hi++;
                }
            }
        }
Example #5
0
        public Palette(int randomSeed, int colorX, int colorY)
        {
            _random = new Random(randomSeed);
            ColorList = new List<PaletteColor>();

            Bitmap bmp;
            try
            {
                bmp = Properties.Resources.ColourPalette;
                _colorArr = Array.CreateInstance(typeof(Color), bmp.Height / colorX);

                var y = colorY;
                var ind = 0;
                while (y < bmp.Height)
                {
                    var clr = bmp.GetPixel(colorY, y);
                    y += colorX;

                    _colorArr.SetValue(clr, ind);
                    ind++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
		public void CopyTo(Array array, int index){
			IEnumerator tablecell = this.GetEnumerator();
			while(tablecell.MoveNext()){
				index = index + 1;
				array.SetValue(tablecell.Current, index);
			}
		}
 public void CopyTo(Array array, int index)
 {
     foreach (object item in this)
     {
         array.SetValue(item, index++);
     }
 }
 void ICollection.CopyTo(Array array, int index)
 {
     foreach (DesignSurface surface in this)
     {
         array.SetValue(surface, index++);
     }
 }
 public void CopyTo(Array array, int index)
 {
     foreach (MethodData data in this)
     {
         array.SetValue(data, index++);
     }
 }
        private void fillHeftArray(int spaceDimension, int histogramResolution, Array array, Array heftArray)
        {
            int cellNO = (int)Math.Pow(histogramResolution, spaceDimension);
            int[] outerIndicesArray = new int[spaceDimension];
            int[] innerIndicesArray = new int[spaceDimension];
            int[] windowIndicesArray = new int[spaceDimension];
            for (int outerCellIdx = 0; outerCellIdx < cellNO; outerCellIdx++)
            {
                transformator.transformCellIdxToIndicesArray(histogramResolution, outerIndicesArray, outerCellIdx);

                for (int innerCellIdx = outerCellIdx; innerCellIdx < cellNO; innerCellIdx++)
                {
                    transformator.transformCellIdxToIndicesArray(histogramResolution, innerIndicesArray, innerCellIdx);
                    int[] heftArrayIndeces;
                    int cellPoints;
                    bool validHeftArrayIndeces = transformator.mergeIndicesArrays(spaceDimension, outerIndicesArray,
                        innerIndicesArray, out heftArrayIndeces, out cellPoints);
                    if (validHeftArrayIndeces)
                    {
                        int cellValue = 0;
                        for (int windowIdx = outerCellIdx; windowIdx <= innerCellIdx; windowIdx++)
                        {
                            transformator.transformCellIdxToIndicesArray(histogramResolution, windowIndicesArray, windowIdx);
                            bool validSummableArrayIndeces = transformator.validateIndicesArrays(spaceDimension,
                                outerIndicesArray, innerIndicesArray, windowIndicesArray);
                            if (validSummableArrayIndeces)
                            {
                                cellValue += (int)array.GetValue(windowIndicesArray);
                            }
                        }
                        heftArray.SetValue(cellValue, heftArrayIndeces);
                    }
                }
            }
        }
		public virtual void CopyTo(Array array, int index)
		{
			foreach (object k in keys)
			{
				array.SetValue(hash[k], index++);
			}
		}
Example #12
0
        /// <summary>
        /// Modifies the specified array by applying the specified function to each element.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="func">object delegate(object o){}</param>
        /// <returns></returns>
        public static void ForEach(Array a, ForEachFunction func)
        {
            long[] ix = new long[a.Rank];
            //Init index
            for (int i = 0; i < ix.Length; i++) ix[i] = a.GetLowerBound(i);

            //Loop through all items
            for (long i = 0; i < a.LongLength; i++)
            {
                a.SetValue(func(a.GetValue(ix)), ix);

                //Increment ix, the index
                for (int j = 0; j < ix.Length; j++)
                {
                    if (ix[j] < a.GetUpperBound(j))
                    {
                        ix[j]++;
                        break; //We're done incrementing.
                    }
                    else
                    {
                        //Ok, reset this one and increment the next.
                        ix[j] = a.GetLowerBound(j);
                        //If this is the last dimension, assert
                        //that we are at the last element
                        if (j == ix.Length - 1)
                        {
                            if (i < a.LongLength - 1) throw new Exception();
                        }
                        continue;
                    }
                }
            }
            return;
        }
 void ICollection.CopyTo(Array dest, int index)
 {
     int count = this.Count;
     for (int i = 0; i < count; i++)
     {
         dest.SetValue(this[i], index++);
     }
 }
 void ICollection.CopyTo(Array myArr, int index)
 {
     foreach (BlockHistoryObject bho in _collectionArray)
     {
         myArr.SetValue(bho, index);
         index++;
     }
 }
        protected override void SortGenericArray(Array items, int left, int right)
        {
            int j;
            int limit = items.Length;
            int st = -1;

            while (st < limit)
            {
                bool flipped = false;
                st++;
                limit--;

                for (j = st; j < limit; j++)
                {
                    if (this.comparer.Compare(items.GetValue(j), items.GetValue(j + 1)) > 0)
                    {
                        object T = items.GetValue(j);
                        items.SetValue(items.GetValue(j + 1), j);
                        items.SetValue(T,j + 1);
                        flipped = true;

                    }
                } // end for

                if (!flipped)
                {
                    return;
                }

                for (j = limit; --j >= st; )
                {
                    if (this.comparer.Compare(items.GetValue(j), items.GetValue(j + 1)) > 0)
                    {
                        object T = items.GetValue(j);
                        items.SetValue(items.GetValue(j + 1), j);
                        items.SetValue(T, j + 1);
                        flipped = true;
                    }
                }

                if (!flipped)
                {
                    return;
                }
            }
        }
 void ICollection.CopyTo(Array array, int index)
 {
     IEnumerator enumerator = ((IEnumerable) this).GetEnumerator();
     while (enumerator.MoveNext())
     {
         array.SetValue(enumerator.Current, index++);
     }
 }
 public virtual void CopyTo(Array array, int index)
 {
     int cElem = this._obj.Length;
     for (int i = 0; i < cElem; ++i)
     {
         array.SetValue(this[i], i + index);
     }
 }
 public void CopyTo(Array array, int index)
 {
     IEnumerator enumerator = this.GetEnumerator();
     while (enumerator.MoveNext())
     {
         array.SetValue(enumerator.Current, index++);
     }
 }
 public override void CopyTo(Array array, int index)
 {
     if (array == null) throw new ArgumentNullException("array");
     for (var i = 0; i < _parameters.Count; i++)
     {
         array.SetValue(_parameters[i], index + i);
     }
 }
Example #20
0
 internal static void CopyTo(this Dictionary<object, object>.ValueCollection source, Array a, int index)
 {
     int arrayIndex = index;
     foreach (object value in source)
     {
         a.SetValue(value, arrayIndex++);
     }
 }
		public void CopyTo(Array array, int index)
		{
			int i = index;
			foreach(MethodInfo mi in this)
			{
				array.SetValue(mi,i++);	
			}
		}
Example #22
0
 public RawAnalysisReport(NCCReporter.LMLoggers.LognLM ctrllog)
     : base(ctrllog)
 {
     selectedReportSections = Array.CreateInstance(typeof(bool), System.Enum.GetValues(typeof(RawReportSections)).Length);
     foreach (ValueType v in System.Enum.GetValues(typeof(RawReportSections)))
     {
         selectedReportSections.SetValue(true, (int)v);
     }
 }
Example #23
0
 public override void CopyTo(Array array, int arrayIndex) {
     if (hasNullKey) {
         base.CopyTo(array, arrayIndex + 1);
         array.SetValue(new DictionaryEntry(null, valueOfNullKey), arrayIndex);
     }
     else {
         base.CopyTo(array, arrayIndex);            
     }
 }
 public virtual void CopyTo(Array array, int index)
 {
     IDictionaryEnumerator enumerator1 = this.ObjectTable.GetEnumerator();
     int num1 = index;
     while (enumerator1.MoveNext())
     {
         array.SetValue(enumerator1.Key, num1++);
     }
 }
Example #25
0
        protected override void SortGenericArray(Array items, int left, int right)
        {
            bool flipped = false;
            int gap, top;
            int i, j;

            gap = items.Length;
            do
            {
                gap = (int)((float)gap / SHRINKFACTOR);

                switch (gap)
                {
                    case 0: /* the smallest gap is 1 - bubble Sort */
                        gap = 1;
                        break;
                    case 9: /* this is what makes this Combsort11 */
                    case 10:
                        gap = 11;
                        break;
                    default: break;
                }

                flipped = false;
                top = items.Length - gap;

                for (i = 0; i < top; i++)
                {

                    j = i + gap;

                    if (this.comparer.Compare(items.GetValue(i), items.GetValue(j)) > 0)
                    {
                        object T = items.GetValue(i);
                        items.SetValue(items.GetValue(j), i);
                        items.SetValue(T, j);
                        flipped = true;
                    }
                }
            } while (flipped || (gap > 1));
            /* like the bubble and shell sorts we check for items clean pass */
        }
 public virtual void CopyTo(Array array, int index)
 {
     for (int i = 0; i < this._keys.Length; i++)
     {
         array.SetValue(this.GetMessageValue(i), (int) (index + i));
     }
     if (this._dict != null)
     {
         this._dict.CopyTo(array, index + this._keys.Length);
     }
 }
Example #27
0
        public void Sirala(Array dizi)
        {
            for (int i = 0; i < dizi.Length - 1; i++)
            {
                for (int j = 0; j < dizi.Length - i - 1; j++)
                {
                    object x = dizi.GetValue(j); // dizi[j]
                    object y = dizi.GetValue(j+1); // dizi[j+1]

                    if (Karsilastir(x, y))
                    {
                        object z = x;
                        x = y;
                        y = z;

                        dizi.SetValue(x, j); // dizi[j] = x;
                        dizi.SetValue(y, j+1); // dizi[j+1] = y;
                    }
                }
            }
        }
 public void CopyTo(Array array, int index)
 {
     if (array == null)
     {
         throw new ArgumentNullException("array");
     }
     IEnumerator enumerator = this.GetEnumerator();
     while (enumerator.MoveNext())
     {
         array.SetValue(enumerator.Current, index++);
     }
 }
Example #29
0
        protected override void SortGenericArray(Array items, int left, int right)
        {
            int h = 1;
            int length = items.Length;

            // find the largest h value possible
            while ((h * 3 + 1) < length)
            {
                h = 3 * h + 1;
            }

            // while h remains larger than 0
            while (h > 0)
            {

                // for each set of elements (there are h sets)
                for (int i = h - 1; i < length; i++)
                {
                    // pick the last element in the set
                    object B = items.GetValue(i);
                    int j = i;

                    // compare the element at B to the one before it in the set
                    // if they are out of order continue this loop, moving
                    // elements "back" to make room for B to be inserted.
                    for (j = i; (j >= h) && (this.comparer.Compare(items.GetValue(j - h), B) > 0); j -= h)
                    {
                        items.SetValue(items.GetValue(j - h), j);
                    }

                    // insert B into the correct place
                    items.SetValue(B, j);

                } // end for

                // all sets h-sorted, now decrease set size
                h = h / 3;
            }
        }
 public void CopyTo(Array array, int arrayIndex)
 {
     if (array == null)
     {
         throw new ArgumentNullException("array");
     }
     int index = arrayIndex;
     for (int i = 0; i < this.Count; i++)
     {
         array.SetValue(this[i], index);
         index++;
     }
 }