Exemplo n.º 1
0
        public TElement First(Func <TElement, bool> predicate)
        {
            CachingComparer <TElement> comparer = GetComparer();

            using (IEnumerator <TElement> e = source.GetEnumerator())
            {
                TElement value;
                do
                {
                    if (!e.MoveNext())
                    {
                        throw Error.NoMatch();
                    }
                    value = e.Current;
                } while (!predicate(value));
                comparer.SetElement(value);
                while (e.MoveNext())
                {
                    TElement x = e.Current;
                    if (predicate(x) && comparer.Compare(x, true) < 0)
                    {
                        value = x;
                    }
                }
                return(value);
            }
        }
Exemplo n.º 2
0
        public TElement LastOrDefault(Func <TElement, bool> predicate)
        {
            CachingComparer <TElement> comparer = GetComparer();

            using (IEnumerator <TElement> e = source.GetEnumerator())
            {
                TElement value;
                do
                {
                    if (!e.MoveNext())
                    {
                        return(default(TElement));
                    }
                    value = e.Current;
                } while (!predicate(value));
                comparer.SetElement(value);
                while (e.MoveNext())
                {
                    TElement x = e.Current;
                    if (predicate(x) && comparer.Compare(x, false) > 0)
                    {
                        value = x;
                    }
                }
                return(value);
            }
        }
Exemplo n.º 3
0
        private bool TryGetFirst(out TElement result)
        {
            CachingComparer <TElement> comparer = GetComparer();

            using (IEnumerator <TElement> e = source.GetEnumerator())
            {
                if (!e.MoveNext())
                {
                    result = default(TElement);
                    return(false);
                }
                TElement value = e.Current;
                comparer.SetElement(value);
                while (e.MoveNext())
                {
                    TElement x = e.Current;
                    if (comparer.Compare(x, true) < 0)
                    {
                        value = x;
                    }
                }
                result = value;
                return(true);
            }
        }
Exemplo n.º 4
0
        public TElement TryGetLast(Func <TElement, bool> predicate, out bool found)
        {
            CachingComparer <TElement> comparer = GetComparer();

            using (IEnumerator <TElement> e = _source.GetEnumerator())
            {
                TElement value;
                do
                {
                    if (!e.MoveNext())
                    {
                        found = false;
                        return(default(TElement));
                    }

                    value = e.Current;
                }while (!predicate(value));

                comparer.SetElement(value);
                while (e.MoveNext())
                {
                    TElement x = e.Current;
                    if (predicate(x) && comparer.Compare(x, false) >= 0)
                    {
                        value = x;
                    }
                }

                found = true;
                return(value);
            }
        }
Exemplo n.º 5
0
        public TElement TryGetLast(out bool found)
        {
            using (IEnumerator <TElement> e = _source.GetEnumerator())
            {
                if (!e.MoveNext())
                {
                    found = false;
                    return(default(TElement));
                }

                CachingComparer <TElement> comparer = GetComparer();
                TElement value = e.Current;
                comparer.SetElement(value);
                while (e.MoveNext())
                {
                    TElement current = e.Current;
                    if (comparer.Compare(current, false) >= 0)
                    {
                        value = current;
                    }
                }

                found = true;
                return(value);
            }
        }
Exemplo n.º 6
0
        public TElement TryGetFirst(out bool found)
        {
            CachingComparer <TElement> comparer = GetComparer();

            using (IEnumerator <TElement> e = _source.GetEnumerator())
            {
                if (!e.MoveNext())
                {
                    found = false;
                    return(default(TElement));
                }

                TElement value = e.Current;
                comparer.SetElement(value);
                while (e.MoveNext())
                {
                    TElement x = e.Current;
                    if (comparer.Compare(x, true) < 0)
                    {
                        value = x;
                    }
                }

                found = true;
                return(value);
            }
        }
Exemplo n.º 7
0
        private TElement Last(Buffer <TElement> buffer)
        {
            CachingComparer <TElement> comparer = GetComparer();

            TElement[] items = buffer.items;
            int        count = buffer.count;
            TElement   value = items[0];

            comparer.SetElement(value);
            for (int i = 1; i != count; ++i)
            {
                TElement x = items[i];
                if (comparer.Compare(x, false) >= 0)
                {
                    value = x;
                }
            }
            return(value);
        }
Exemplo n.º 8
0
        public TElement LastOrDefault()
        {
            CachingComparer <TElement> comparer = GetComparer();

            using (IEnumerator <TElement> e = source.GetEnumerator())
            {
                if (!e.MoveNext())
                {
                    return(default(TElement));
                }
                TElement value = e.Current;
                comparer.SetElement(value);
                while (e.MoveNext())
                {
                    TElement x = e.Current;
                    if (comparer.Compare(x, false) >= 0)
                    {
                        value = x;
                    }
                }
                return(value);
            }
        }
Exemplo n.º 9
0
 public CachingComparerWithChild(Func <TElement, TKey> keySelector, IComparer <TKey> comparer, bool descending, CachingComparer <TElement> child)
     : base(keySelector, comparer, descending)
 {
     _child = child;
 }
Exemplo n.º 10
0
 internal abstract CachingComparer <TElement> GetComparer(CachingComparer <TElement> childComparer);