Jurassic.Library.SparseArray.CopyTo C# (CSharp) Method

CopyTo() public method

Copies the elements of the given sparse array to this sparse array, starting at a particular index. Existing values are overwritten.
public CopyTo ( SparseArray source, uint start ) : void
source SparseArray The sparse array to copy.
start uint The zero-based index at which copying begins.
return void
        public void CopyTo(SparseArray source, uint start)
        {
            var originalStart = start;
            foreach (var sourceRange in source.Ranges)
            {
                int sourceOffset = 0;
                start = originalStart + sourceRange.StartIndex;
                do
                {
                    // Get a reference to the array to copy to.
                    object[] dest = FindOrCreateArray(start, writeAccess: true);
                    int destOffset = (int)(start & NodeMask);

                    // Copy as much as possible.
                    int copyLength = Math.Min(sourceRange.Length - sourceOffset, dest.Length - destOffset);
                    Array.Copy(sourceRange.Array, sourceOffset, dest, destOffset, copyLength);

                    start += (uint)copyLength;
                    sourceOffset += copyLength;
                } while (sourceOffset < sourceRange.Length);
            }
        }

Same methods

SparseArray::CopyTo ( object source, uint start, int length ) : void

Usage Example

コード例 #1
0
ファイル: SparseArray.cs プロジェクト: vipwan/CommunityServer
 /// <summary>
 /// Creates a sparse array from the given dense array.
 /// </summary>
 /// <param name="array"> The array to copy items from. </param>
 /// <param name="length"> The number of items to copy. </param>
 /// <returns> A new sparse array containing the items from the given array. </returns>
 public static SparseArray FromDenseArray(object[] array, int length)
 {
     if (array == null)
         throw new ArgumentNullException("array");
     if (length > array.Length)
         throw new ArgumentOutOfRangeException("length");
     var result = new SparseArray();
     result.CopyTo(array, 0, length);
     return result;
 }
All Usage Examples Of Jurassic.Library.SparseArray::CopyTo