Esempio n. 1
0
        public bool Enqueue(FilePacketMemoryStream item)
        {
            Debug.Assert(item != null, $"{nameof(item)} is null");

            var hadCountiguousItems = CountContiguous != 0;

            if (!CanEnqueue(item))
            {
                return(false);
            }

            if (storage.Count != 0 && item.Index < storage[0].Index) // Если новый индекс меньше самого маленького, то просто вставляем его вперед.
            {
                storage.Insert(0, item);
            }
            else // If not, then add, and then resort the storage
            {
                storage.Add(item);
                storage.Sort((i1, i2) => i1.Index.CompareTo(i2.Index));
            }

            enqueueAddedFirstAvailableItem = !hadCountiguousItems && CountContiguous != 0;

            return(true);
        }
Esempio n. 2
0
        public bool CanEnqueue(FilePacketMemoryStream item)
        {
            Debug.Assert(item != null, $"{nameof(item)} is null");

            var canEnqueue = storage.Count < SoftLimit;

            if (!canEnqueue) // If limit is filled, we can add to queue, only if the new index limited by lower range edge
            {
                canEnqueue = item.Index < storage[storage.Count - 1].Index;
            }
            return(canEnqueue);
        }