示例#1
0
        public bool TryPeek(out T result)
        {
            result = default(T);

            if (count == 0)
            {
                return(false);
            }

            int             hintIndex;
            CyclicDeque <T> bag = GetBag(out hintIndex, false);
            bool            ret = true;

            if (bag == null || !bag.PeekBottom(out result))
            {
                var self = bag;
                ret = false;
                foreach (var other in staging)
                {
                    ret = TryGetHint(out hintIndex) && container[hintIndex].PeekTop(out result);

                    if (!ret && other.Value != self)
                    {
                        ret = other.Value.PeekTop(out result);
                    }

                    if (ret)
                    {
                        break;
                    }
                }
            }

            return(ret);
        }
示例#2
0
        public bool TryPeek(out T result)
        {
            result = default(T);

            if (count == 0)
            {
                return(false);
            }

            int             hintIndex;
            CyclicDeque <T> bag = GetBag(out hintIndex, false);
            bool            ret = true;

            if (bag == null || !bag.PeekBottom(out result))
            {
                var self = bag;
                ret = false;
                foreach (var other in staging)
                {
                    // Try to retrieve something based on a hint
                    ret = TryGetHint(out hintIndex) && container[hintIndex].PeekTop(out result);

                    // We fall back to testing our slot
                    if (!ret && other.Value != self)
                    {
                        ret = other.Value.PeekTop(out result);
                    }

                    // If we found something, stop
                    if (ret)
                    {
                        break;
                    }
                }
            }

            return(ret);
        }