示例#1
0
        public LargeArray <T> Clone()
        {
            var cloned = new LargeArray <T>(mCount);

            cloned.CopyFrom(this, 0, 0, mCount);
            return(cloned);
        }
示例#2
0
        public long CopyTo(long fromPos, ref LargeArray <T> to, long toPos, long count)
        {
            if (to == null)
            {
                throw new ArgumentNullException("to");
            }
            if (fromPos < 0 || mCount < fromPos + count)
            {
                throw new ArgumentOutOfRangeException("fromPos");
            }
            if (toPos < 0 || to.LongLength < toPos + count)
            {
                throw new ArgumentOutOfRangeException("toPos");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            for (long remain = count; 0 < remain;)
            {
                int fragmentCount = ARRAY_FRAGMENT_LENGTH_NUM;
                if (remain < fragmentCount)
                {
                    fragmentCount = (int)remain;
                }

                var fragment = new T[fragmentCount];
                CopyTo(fromPos, ref fragment, 0, fragmentCount);
                to.CopyFrom(fragment, 0, toPos, fragmentCount);

                fromPos += fragmentCount;
                toPos   += fragmentCount;
                remain  -= fragmentCount;
            }

            return(count);
        }
示例#3
0
        public static LargeArray <T> GetLargeArrayFragment(List <T[]> from, long startPos, long count)
        {
            if (startPos < 0)
            {
                throw new ArgumentOutOfRangeException("startPos");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            var r = new LargeArray <T>(count);

            long accPos = 0;
            long toPos  = 0;

            foreach (var item in from)
            {
                // 例1:
                // startPos = 10
                // bytes = 10
                // itemLen=8のとき、
                // 1個目のitemは accPos=0, itemLen=8  → スキップ。
                // 2個目のitemは accPos=8, itemLen=8  → fromPos=2, toPos = 0, copyCount=6
                // 3個目のitemは accPos=16, itemLen=8 → fromPos=0, toPos = 6, copyCount=4

                if (accPos + item.Length <= startPos)
                {
                    // まだ最初の取得位置よりも前。
                    accPos += item.Length;
                    continue;
                }

                // ちょうど取得データが有る場所に来た。
                int fromPos   = (int)(startPos - accPos);
                int copyCount = item.Length;
                if (startPos + count < fromPos + item.Length)
                {
                    copyCount = (int)((startPos + count) - fromPos);
                }
                if (0 < copyCount)
                {
                    r.CopyFrom(item, fromPos, toPos, copyCount);
                    toPos += copyCount;
                }
                else
                {
                    // 最後のコピーデータよりも後の位置に来た。
                    break;
                }
            }

            if (toPos < count)
            {
                // toPos個しか取得できなかったので戻り配列rのサイズを変更する。
                var tmp = new LargeArray <T>(toPos);
                tmp.CopyFrom(r, 0, 0, toPos);
                r = tmp;
            }

            return(r);
        }