Exemple #1
0
        public Deque(IEnumerable <TValue> collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection), "Collection cannot be null.");
            }
#if DEBUG
            this.m_lock = new SpinLockWrapper(true);
#else
            this.m_lock = new SpinLockWrapper(false);
#endif

            var source = CollectionExtensions.ToReadOnlyCollection(collection);
            var count  = source.Count;

            if (count > 0)
            {
                this.SetCapacity(count);
                this.DoAddRange(source);
            }
            else
            {
                this.m_data   = new TValue[DefaultCapacity];
                this.m_count  = 0;
                this.m_offset = 0;
            }

            this.m_isDisposed = 0;
        }
Exemple #2
0
        public virtual void AddRangeFront(IEnumerable <TValue> items)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items), "Collection cannot be null.");
            }

            this.CheckDisposed();
            var result = CollectionExtensions.ToReadOnlyCollection(items);

            if (result.Count <= 0)
            {
                return;
            }

            this.m_lock.Lock();

            try {
                this.EnsureCapacity(result.Count);
                var idx = this.PreDecrement(result.Count);
                this.CopyFrom(result, idx);
            } finally {
                this.m_lock.Unlock();
            }
        }