예제 #1
0
        /// <summary>
        /// Searches for an item by traversing all cells up to AppendIndex.
        /// The reads are volatile, the comparison Object.Equals().
        /// </summary>
        /// <param name="item">The object ref</param>
        /// <returns>A positive value if the item is found, -1 otherwise.</returns>
        public int IndexOf(T item)
        {
            int result = -1;
            int aIdx   = AppendIndex;
            var p      = new TesseractPos(0);

            for (var i = 0; i <= aIdx; i++)
            {
                p.Set(i);

                var r = Volatile.Read(ref blocks[p.D0][p.D1][p.D2][p.D3]);

                if (r != null && r.Equals(item))
                {
                    result = i;
                    break;
                }
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Iterates all cells from 0 up to AppendIndex and yields each item
        /// if it's not null at the time of the check.
        /// </summary>
        /// <param name="assertGear">If true volatile-reads the Drive at each iteration. False by default. </param>
        /// <returns>A not null item.</returns>
        /// <exception cref="InvalidOperationException">If the Drive is P</exception>
        public IEnumerable <T> NotNullItems(bool assertGear = false, bool allSlots = false)
        {
            T   item = null;
            var j    = allSlots ? AllocatedSlots - 1 : AppendIndex;
            var p    = new TesseractPos(j);

            for (int i = 0; i <= j; i++)
            {
                if (assertGear && Drive == TesseractGear.P)
                {
                    throw new InvalidOperationException("Wrong drive");
                }

                p.Set(i);
                item = Volatile.Read(ref blocks[p.D0][p.D1][p.D2][p.D3]);

                if (item != null)
                {
                    yield return(item);
                }
            }
        }