예제 #1
0
파일: Stack.cs 프로젝트: voloda/corefx
        // Copies the stack into an array.
        /// <include file='doc\Stack.uex' path='docs/doc[@for="Stack.CopyTo"]/*' />
        public void CopyTo(T[] array, int arrayIndex)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            if (arrayIndex < 0 || arrayIndex > array.Length)
            {
                throw new ArgumentOutOfRangeException("arrayIndex", SR.ArgumentOutOfRange_NeedNonNegNum);
            }

            if (array.Length - arrayIndex < _size)
            {
                throw new ArgumentException(SR.Argument_InvalidOffLen);
            }

            if (array != _array)
            {
                int srcIndex = 0;
                int dstIndex = arrayIndex + _size;
                for (int i = 0; i < _size; i++)
                {
                    array[--dstIndex] = _array[srcIndex++];
                }
            }
            else
            {
                // Legacy fallback in case we ever end up copying within the same array.
                ArrayT <T> .Copy(_array, 0, array, arrayIndex, _size);

                Array.Reverse(array, arrayIndex, _size);
            }
        }
예제 #2
0
파일: Stack.cs 프로젝트: voloda/corefx
        // Removes all Objects from the Stack.
        /// <include file='doc\Stack.uex' path='docs/doc[@for="Stack.Clear"]/*' />
        public void Clear()
        {
            ArrayT <T> .Clear(_array, 0, _size); // Don't need to doc this but we clear the elements so that the gc can reclaim the references.

            _size = 0;
            _version++;
        }
예제 #3
0
        // Inserts the elements of the given collection at a given index. If
        // required, the capacity of the list is increased to twice the previous
        // capacity or the new size, whichever is larger.  Ranges may be added
        // to the end of the list by setting index to the List's size.
        //
        public void InsertRange(int index, IEnumerable <T> collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            if ((uint)index > (uint)_size)
            {
                throw new ArgumentOutOfRangeException("index");
            }
            Contract.EndContractBlock();

            ICollection <T> c = collection as ICollection <T>;

            if (c != null)
            {    // if collection is ICollection<T>
                int count = c.Count;
                if (count > 0)
                {
                    EnsureCapacity(_size + count);
                    if (index < _size)
                    {
                        ArrayT <T> .Copy(_items, index, _items, index + count, _size - index);
                    }

                    // If we're inserting a List into itself, we want to be able to deal with that.
                    if (this == c)
                    {
                        // Copy first part of _items to insert location
                        ArrayT <T> .Copy(_items, 0, _items, index, index);

                        // Copy last part of _items back to inserted location
                        ArrayT <T> .Copy(_items, index + count, _items, index * 2, _size - index);
                    }
                    else
                    {
                        T[] itemsToInsert = new T[count];
                        c.CopyTo(itemsToInsert, 0);
                        ArrayT <T> .Copy(itemsToInsert, 0, _items, index, count);
                    }
                    _size += count;
                }
            }
            else
            {
                using (IEnumerator <T> en = collection.GetEnumerator())
                {
                    while (en.MoveNext())
                    {
                        Insert(index++, en.Current);
                    }
                }
            }
            _version++;
        }
예제 #4
0
        // ToArray returns a new Object array containing the contents of the List.
        // This requires copying the List, which is an O(n) operation.
        public T[] ToArray()
        {
            Contract.Ensures(Contract.Result <T[]>() != null);
            Contract.Ensures(Contract.Result <T[]>().Length == Count);

            T[] array = new T[_size];
            ArrayT <T> .Copy(_items, 0, array, 0, _size);

            return(array);
        }
예제 #5
0
        public static void TransformationLoginData(byte[] data, UserInfo ui)
        {
            ArrayT <byte> t = new ArrayT <byte>();

            int[] _t = { };
            t.AddRange(data);
            byte[] t_data = { 0x00, 0x00 };
            Array.Copy(t.value, 5 - 1, t_data, 0, 2);
            short value = BitConverter.ToInt16(t_data, 0);
            char  v     = Convert.ToString(value, 2).Reverse <char>().ToArray()[8 - 1];

            if (v == '1')   //判断是否支持Can Use LOAD DATA LOCAL   0是不支持,1是支持
            {
                ui.LoadData = true;
            }
            else
            {
                ui.LoadData = false;
            }
            t.RemoveRange(0, 36);
            _t = t.ArraySeachint(0x00);
            byte[] username = t.Get(0, _t[0]);
            ui.username = (Encoding.Default.GetString(username));
            byte[] password = null;
            byte[] info     = null;
            //PassWord
            if (t.Get(_t[0] + 1) == 0x14)
            {
                password = t.Get(_t[0] + 2, 20);
                foreach (var item in password)
                {
                    string _titem = Convert.ToString(item, 16);
                    _titem       = _titem.Length == 1 ? "0" + _titem : _titem;
                    ui.password += _titem;
                }
            }
            else
            {
                ui.password = "******";
            }
            //Info
            if (ui.username.Length + 2 == t.Count() || ui.username.Length + 22 == t.Count() || ui.username.Length + 23 == t.Count())
            {
                ui.info = "NULL";
            }
            else if (password == null)
            {
                ui.info = Encoding.Default.GetString(t.Get(_t[1], _t[2] - _t[1]));
            }
            else
            {
                ui.info = Encoding.Default.GetString(t.Get(_t[0] + 22, _t[_t.Length - 1] - (_t[0] + 21)));
            }
            t = null;
        }
예제 #6
0
파일: Stack.cs 프로젝트: voloda/corefx
        // Pushes an item to the top of the stack.
        //
        /// <include file='doc\Stack.uex' path='docs/doc[@for="Stack.Push"]/*' />
        public void Push(T item)
        {
            if (_size == _array.Length)
            {
                T[] newArray = ArrayT <T> .Resize(_array, (_array.Length == 0)?DefaultCapacity : 2 *_array.Length, _size);

                _array = newArray;
            }
            _array[_size++] = item;
            _version++;
        }
예제 #7
0
        // Copies a section of this list to the given array at the given index.
        //
        // The method uses the Array.Copy method to copy the elements.
        //
        public void CopyTo(int index, T[] array, int arrayIndex, int count)
        {
            if (_size - index < count)
            {
                throw new ArgumentException();
            }
            Contract.EndContractBlock();

            // Delegate rest of error checking to Array.Copy.
            ArrayT <T> .Copy(_items, index, array, arrayIndex, count);
        }
예제 #8
0
파일: Stack.cs 프로젝트: voloda/corefx
        public void TrimExcess()
        {
            int threshold = (int)(((double)_array.Length) * 0.9);

            if (_size < threshold)
            {
                T[] newarray = ArrayT <T> .Resize(_array, _size, _size);

                _array = newarray;
                _version++;
            }
        }
예제 #9
0
 // Removes the element at the given index. The size of the list is
 // decreased by one.
 //
 public void RemoveAt(int index)
 {
     if ((uint)index >= (uint)_size)
     {
         throw new ArgumentOutOfRangeException("index");
     }
     Contract.EndContractBlock();
     _size--;
     if (index < _size)
     {
         ArrayT <T> .Copy(_items, index + 1, _items, index, _size - index);
     }
     _items[_size] = default(T);
     _version++;
 }
예제 #10
0
        void Resize()
        {
            int newSize = checked (_count * 2 + 1);

            int[]  newBuckets = new int[newSize];
            Slot[] newSlots   = ArrayT <Slot> .Resize(_slots, newSize, _count);

            for (int i = 0; i < _count; i++)
            {
                int bucket = newSlots[i].hashCode % newSize;
                newSlots[i].next   = newBuckets[bucket] - 1;
                newBuckets[bucket] = i + 1;
            }
            _buckets = newBuckets;
            _slots   = newSlots;
        }
예제 #11
0
        // This method removes all items which matches the predicate.
        // The complexity is O(n).
        public int RemoveAll(Predicate <T> match)
        {
            if (match == null)
            {
                throw new ArgumentNullException("match");
            }
            Contract.Ensures(Contract.Result <int>() >= 0);
            Contract.Ensures(Contract.Result <int>() <= Contract.OldValue(Count));
            Contract.EndContractBlock();

            int freeIndex = 0;   // the first free slot in items array

            // Find the first item which needs to be removed.
            while (freeIndex < _size && !match(_items[freeIndex]))
            {
                freeIndex++;
            }
            if (freeIndex >= _size)
            {
                return(0);
            }

            int current = freeIndex + 1;

            while (current < _size)
            {
                // Find the first item which needs to be kept.
                while (current < _size && match(_items[current]))
                {
                    current++;
                }

                if (current < _size)
                {
                    // copy item to the free slot.
                    _items[freeIndex++] = _items[current++];
                }
            }

            ArrayT <T> .Clear(_items, freeIndex, _size - freeIndex);

            int result = _size - freeIndex;

            _size = freeIndex;
            _version++;
            return(result);
        }
예제 #12
0
        // Removes all Objects from the queue.
        /// <include file='doc\Queue.uex' path='docs/doc[@for="Queue.Clear"]/*' />
        public void Clear()
        {
            if (_head < _tail)
            {
                ArrayT <T> .Clear(_array, _head, _size);
            }
            else
            {
                ArrayT <T> .Clear(_array, _head, _array.Length - _head);

                ArrayT <T> .Clear(_array, 0, _tail);
            }

            _head = 0;
            _tail = 0;
            _size = 0;
            _version++;
        }
예제 #13
0
        private static byte[] UrlDecodeInternal(byte[] bytes, int offset, int count)
        {
            if (!ValidateUrlEncodingParameters(bytes, offset, count))
            {
                return(null);
            }

            int decodedBytesCount = 0;

            byte[] decodedBytes = new byte[count];

            for (int i = 0; i < count; i++)
            {
                int  pos = offset + i;
                byte b   = bytes[pos];

                if (b == '+')
                {
                    b = (byte)' ';
                }
                else if (b == '%' && i < count - 2)
                {
                    int h1 = HexToInt((char)bytes[pos + 1]);
                    int h2 = HexToInt((char)bytes[pos + 2]);

                    if (h1 >= 0 && h2 >= 0)
                    {     // valid 2 hex chars
                        b  = (byte)((h1 << 4) | h2);
                        i += 2;
                    }
                }

                decodedBytes[decodedBytesCount++] = b;
            }

            if (decodedBytesCount < decodedBytes.Length)
            {
                decodedBytes = ArrayT <byte> .Resize(decodedBytes, decodedBytesCount, decodedBytesCount);
            }

            return(decodedBytes);
        }
예제 #14
0
 // Inserts an element into this list at a given index. The size of the list
 // is increased by one. If required, the capacity of the list is doubled
 // before inserting the new element.
 //
 public void Insert(int index, T item)
 {
     // Note that insertions at the end are legal.
     if ((uint)index > (uint)_size)
     {
         throw new ArgumentOutOfRangeException("index");
     }
     Contract.EndContractBlock();
     if (_size == _items.Length)
     {
         EnsureCapacity(_size + 1);
     }
     if (index < _size)
     {
         ArrayT <T> .Copy(_items, index, _items, index + 1, _size - index);
     }
     _items[index] = item;
     _size++;
     _version++;
 }
예제 #15
0
        // Iterates over the objects in the queue, returning an array of the
        // objects in the Queue, or an empty array if the queue is empty.
        // The order of elements in the array is first in to last in, the same
        // order produced by successive calls to Dequeue.
        /// <include file='doc\Queue.uex' path='docs/doc[@for="Queue.ToArray"]/*' />
        public T[] ToArray()
        {
            T[] arr = new T[_size];
            if (_size == 0)
            {
                return(arr);
            }

            if (_head < _tail)
            {
                ArrayT <T> .Copy(_array, _head, arr, 0, _size);
            }
            else
            {
                ArrayT <T> .Copy(_array, _head, arr, 0, _array.Length - _head);

                ArrayT <T> .Copy(_array, 0, arr, _array.Length - _head, _tail);
            }

            return(arr);
        }
예제 #16
0
        // PRIVATE Grows or shrinks the buffer to hold capacity objects. Capacity
        // must be >= _size.
        private void SetCapacity(int capacity)
        {
            T[] newarray = new T[capacity];
            if (_size > 0)
            {
                if (_head < _tail)
                {
                    ArrayT <T> .Copy(_array, _head, newarray, 0, _size);
                }
                else
                {
                    ArrayT <T> .Copy(_array, _head, newarray, 0, _array.Length - _head);

                    ArrayT <T> .Copy(_array, 0, newarray, _array.Length - _head, _tail);
                }
            }

            _array = newarray;
            _head  = 0;
            _tail  = (_size == capacity) ? 0 : _size;
            _version++;
        }
예제 #17
0
        // CopyTo copies a collection into an Array, starting at a particular
        // index into the array.
        //
        /// <include file='doc\Queue.uex' path='docs/doc[@for="Queue.CopyTo"]/*' />
        public void CopyTo(T[] array, int arrayIndex)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            if (arrayIndex < 0 || arrayIndex > array.Length)
            {
                throw new ArgumentOutOfRangeException("arrayIndex", SR.ArgumentOutOfRange_Index);
            }

            int arrayLen = array.Length;

            if (arrayLen - arrayIndex < _size)
            {
                throw new ArgumentException(SR.Argument_InvalidOffLen);
            }

            int numToCopy = (arrayLen - arrayIndex < _size) ? (arrayLen - arrayIndex) : _size;

            if (numToCopy == 0)
            {
                return;
            }

            int firstPart = (_array.Length - _head < numToCopy) ? _array.Length - _head : numToCopy;

            ArrayT <T> .Copy(_array, _head, array, arrayIndex, firstPart);

            numToCopy -= firstPart;
            if (numToCopy > 0)
            {
                ArrayT <T> .Copy(_array, 0, array, arrayIndex + _array.Length - _head, numToCopy);
            }
        }
예제 #18
0
        internal PdbFunction(/*string module, */ ManProcSym proc, BitAccess bits)
        {
            this.token = proc.token;
            //this.module = module;
            //this.name = proc.name;
            //this.flags = proc.flags;
            this.segment = proc.seg;
            this.address = proc.off;
            //this.length = proc.len;

            if (proc.seg != 1)
            {
                throw new PdbDebugException("Segment is {0}, not 1.", proc.seg);
            }
            if (proc.parent != 0 || proc.next != 0)
            {
                throw new PdbDebugException("Warning parent={0}, next={1}",
                                            proc.parent, proc.next);
            }
            //if (proc.dbgStart != 0 || proc.dbgEnd != 0) {
            //  throw new PdbDebugException("Warning DBG start={0}, end={1}",
            //                              proc.dbgStart, proc.dbgEnd);
            //}

            int constantCount;
            int scopeCount;
            int slotCount;
            int usedNamespacesCount;

            CountScopesAndSlots(bits, proc.end, out constantCount, out scopeCount, out slotCount, out usedNamespacesCount);
            int scope    = constantCount > 0 || slotCount > 0 || usedNamespacesCount > 0 ? 1 : 0;
            int slot     = 0;
            int constant = 0;
            int usedNs   = 0;

            scopes = ArrayT <PdbScope> .Create(scopeCount + scope);

            slots = ArrayT <PdbSlot> .Create(slotCount);

            constants = ArrayT <PdbConstant> .Create(constantCount);

            usedNamespaces = ArrayT <string> .Create(usedNamespacesCount);

            if (scope > 0)
            {
                scopes[0] = new PdbScope(this.address, proc.len, slots, constants, usedNamespaces);
            }

            while (bits.Position < proc.end)
            {
                ushort siz;
                ushort rec;

                bits.ReadUInt16(out siz);
                int star = bits.Position;
                int stop = bits.Position + siz;
                bits.Position = star;
                bits.ReadUInt16(out rec);

                switch ((SYM)rec)
                {
                case SYM.S_OEM: {    // 0x0404
                    OemSymbol oem;

                    bits.ReadGuid(out oem.idOem);
                    bits.ReadUInt32(out oem.typind);
                    // internal byte[]   rgl;        // user data, force 4-byte alignment

                    if (oem.idOem == msilMetaData)
                    {
                        string name = bits.ReadString();
                        if (name == "MD2")
                        {
                            ReadMD2CustomMetadata(bits);
                        }
                        else if (name == "asyncMethodInfo")
                        {
                            this.synchronizationInformation = new PdbSynchronizationInformation(bits);
                        }
                        bits.Position = stop;
                        break;
                    }
                    else
                    {
                        throw new PdbDebugException("OEM section: guid={0} ti={1}",
                                                    oem.idOem, oem.typind);
                        // bits.Position = stop;
                    }
                }

                case SYM.S_BLOCK32: {
                    BlockSym32 block = new BlockSym32();

                    bits.ReadUInt32(out block.parent);
                    bits.ReadUInt32(out block.end);
                    bits.ReadUInt32(out block.len);
                    bits.ReadUInt32(out block.off);
                    bits.ReadUInt16(out block.seg);
                    bits.SkipCString(out block.name);
                    bits.Position = stop;

                    scopes[scope++] = new PdbScope(this.address, block, bits, out slotToken);
                    bits.Position   = (int)block.end;
                    break;
                }

                case SYM.S_MANSLOT:
                    slots[slot++] = new PdbSlot(bits);
                    bits.Position = stop;
                    break;

                case SYM.S_MANCONSTANT:
                    constants[constant++] = new PdbConstant(bits);
                    bits.Position         = stop;
                    break;

                case SYM.S_UNAMESPACE:
                    bits.ReadCString(out usedNamespaces[usedNs++]);
                    bits.Position = stop;
                    break;

                case SYM.S_END:
                    bits.Position = stop;
                    break;

                default: {
                    //throw new PdbDebugException("Unknown SYM: {0}", (SYM)rec);
                    bits.Position = stop;
                    break;
                }
                }
            }

            if (bits.Position != proc.end)
            {
                throw new PdbDebugException("Not at S_END");
            }

            ushort esiz;
            ushort erec;

            bits.ReadUInt16(out esiz);
            bits.ReadUInt16(out erec);

            if (erec != (ushort)SYM.S_END)
            {
                throw new PdbDebugException("Missing S_END");
            }
        }
예제 #19
0
파일: PdbScope.cs 프로젝트: taktopiyush/cci
        internal PdbScope(uint funcOffset, BlockSym32 block, BitAccess bits, out uint typind)
        {
            //this.segment = block.seg;
            this.address = block.off;
            this.offset  = block.off - funcOffset;
            this.length  = block.len;
            typind       = 0;

            int constantCount;
            int scopeCount;
            int slotCount;
            int namespaceCount;

            PdbFunction.CountScopesAndSlots(bits, block.end, out constantCount, out scopeCount, out slotCount, out namespaceCount);
            constants = ArrayT <PdbConstant> .Create(constantCount);

            scopes = ArrayT <PdbScope> .Create(scopeCount);

            slots = ArrayT <PdbSlot> .Create(slotCount);

            usedNamespaces = ArrayT <string> .Create(namespaceCount);

            int constant = 0;
            int scope    = 0;
            int slot     = 0;
            int usedNs   = 0;

            while (bits.Position < block.end)
            {
                ushort siz;
                ushort rec;

                bits.ReadUInt16(out siz);
                int star = bits.Position;
                int stop = bits.Position + siz;
                bits.Position = star;
                bits.ReadUInt16(out rec);

                switch ((SYM)rec)
                {
                case SYM.S_BLOCK32: {
                    BlockSym32 sub = new BlockSym32();

                    bits.ReadUInt32(out sub.parent);
                    bits.ReadUInt32(out sub.end);
                    bits.ReadUInt32(out sub.len);
                    bits.ReadUInt32(out sub.off);
                    bits.ReadUInt16(out sub.seg);
                    bits.SkipCString(out sub.name);

                    bits.Position   = stop;
                    scopes[scope++] = new PdbScope(funcOffset, sub, bits, out typind);
                    break;
                }

                case SYM.S_MANSLOT:
                    slots[slot++] = new PdbSlot(bits);
                    bits.Position = stop;
                    break;

                case SYM.S_UNAMESPACE:
                    bits.ReadCString(out usedNamespaces[usedNs++]);
                    bits.Position = stop;
                    break;

                case SYM.S_END:
                    bits.Position = stop;
                    break;

                case SYM.S_MANCONSTANT:
                    constants[constant++] = new PdbConstant(bits);
                    bits.Position         = stop;
                    break;

                default:
                    //throw new PdbException("Unknown SYM in scope {0}", (SYM)rec);
                    bits.Position = stop;
                    break;
                }
            }

            if (bits.Position != block.end)
            {
                throw new Exception("Not at S_END");
            }

            ushort esiz;
            ushort erec;

            bits.ReadUInt16(out esiz);
            bits.ReadUInt16(out erec);

            if (erec != (ushort)SYM.S_END)
            {
                throw new Exception("Missing S_END");
            }
        }
예제 #20
0
 public void CopyTo(T[] array, int arrayIndex)
 {
     // Delegate rest of error checking to Array.Copy.
     ArrayT <T> .Copy(_items, 0, array, arrayIndex, _size);
 }