Ejemplo n.º 1
0
        public static OutputIterator <T> UniqueCopy <T>(InputIterator <T> begin, InputIterator <T> end, OutputIterator <T> dest, IEqualityComparer <T> comparer)
        {
            if (begin.Equals(end))
            {
                return(null);
            }

            begin = IteratorUtil.Clone(begin);
            dest  = IteratorUtil.Clone(dest);

            T t = begin.Read();

            dest.Write(t);
            dest.MoveNext();
            begin.MoveNext();
            for (; !begin.Equals(end); begin.MoveNext())
            {
                T next = begin.Read();
                if (!comparer.Equals(t, next))
                {
                    t = next;
                    dest.Write(next);
                    dest.MoveNext();
                }
            }
            return(dest);
        }
Ejemplo n.º 2
0
        public static OutputIterator <T> UniqueCopy <T>(InputIterator <T> begin, InputIterator <T> end, OutputIterator <T> dest, Functional.BinaryPredicate <T> func)
        {
            if (begin.Equals(end))
            {
                return(null);
            }

            begin = IteratorUtil.Clone(begin);
            dest  = IteratorUtil.Clone(dest);
            T t = begin.Read();

            dest.Write(t);
            dest.MoveNext();
            begin.MoveNext();
            for (; !begin.Equals(end); begin.MoveNext())
            {
                T next = begin.Read();

                if (!func(t, next))
                {
                    t = next;
                    dest.Write(next);
                    dest.MoveNext();
                }
            }
            return(dest);
        }
Ejemplo n.º 3
0
        public static void Merge <T>(InputIterator <T> begin1, InputIterator <T> end1,
                                     InputIterator <T> begin2, InputIterator <T> end2, OutputIterator <T> dest, IComparer <T> comp)
        {
            T t1, t2;

            begin1 = IteratorUtil.Clone(begin1);
            begin2 = IteratorUtil.Clone(begin2);
            dest   = IteratorUtil.Clone(dest);
            for (; !begin1.Equals(end1) && !begin2.Equals(end2); dest.MoveNext())
            {
                t1 = begin1.Read();
                t2 = begin2.Read();
                int compare = comp.Compare(t1, t2);

                if (compare == -1)
                {
                    dest.Write(t1);
                    begin1.MoveNext();
                }
                else
                {
                    dest.Write(t2);
                    begin2.MoveNext();
                }
            }

            Copy(begin1, end1, dest);
            Copy(begin2, end2, dest);
        }
Ejemplo n.º 4
0
 public static void ForEach <T>(InputIterator <T> begin, InputIterator <T> end, Functional.UnaryVoidFunction <T> func)
 {
     for (begin = IteratorUtil.Clone(begin); !begin.Equals(end); begin.MoveNext())
     {
         func(begin.Read());
     }
 }
Ejemplo n.º 5
0
        public static bool LexCompare <T>(InputIterator <T> begin1, InputIterator <T> end1,
                                          InputIterator <T> begin2, InputIterator <T> end2,
                                          Comparer <T> comparer)
        {
            begin1 = IteratorUtil.Clone(begin1);
            //end1   = IteratorUtil.Clone(end1);
            begin2 = IteratorUtil.Clone(begin2);
            //end2   = IteratorUtil.Clone(end2);

            for (;; begin1.MoveNext(), begin2.MoveNext())
            {
                if (begin2.Equals(end2))
                {
                    return(false);
                }
                if (begin1.Equals(end1))
                {
                    return(true);
                }

                int compare = comparer.Compare(begin1.Read(), begin2.Read());
                if (compare == -1)
                {
                    return(true);
                }
                if (compare == 1)
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 6
0
        public static void Merge <T>(InputIterator <T> begin1, InputIterator <T> end1,
                                     InputIterator <T> begin2, InputIterator <T> end2, OutputIterator <T> dest, Functional.BinaryPredicate <T> func)
        {
            T t1, t2;

            begin1 = IteratorUtil.Clone(begin1);
            begin2 = IteratorUtil.Clone(begin2);
            dest   = IteratorUtil.Clone(dest);
            for (; !begin1.Equals(end1) && !begin2.Equals(end2); dest.MoveNext())
            {
                t1 = begin1.Read();
                t2 = begin2.Read();
                bool less = func(t1, t2);

                if (less)
                {
                    dest.Write(t1);
                    begin1.MoveNext();
                }
                else
                {
                    dest.Write(t2);
                    begin2.MoveNext();
                }
            }

            Copy(begin1, end1, dest);
            Copy(begin2, end2, dest);
        }
Ejemplo n.º 7
0
        public static T Accumulate <T>(InputIterator <T> begin, InputIterator <T> end, T initialValue, Functional.BinaryFunction <T, T, T> func)
        {
            T result = initialValue;

            for (begin = IteratorUtil.Clone(begin); !begin.Equals(end); begin.MoveNext())
            {
                result = func(result, begin.Read());
            }
            return(result);
        }
Ejemplo n.º 8
0
 public static OutputIterator <T> Copy <T>(InputIterator <T> begin, InputIterator <T> end, OutputIterator <T> target)
 {
     for (begin = IteratorUtil.Clone(begin), target = IteratorUtil.Clone(target);
          !begin.Equals(end);
          begin.MoveNext(), target.MoveNext())
     {
         target.Write(begin.Read());
     }
     return(target);
 }
Ejemplo n.º 9
0
        public static IEnumerable <T> CreateEnumerator <T>(InputIterator <T> begin, InputIterator <T> end)
        {
            begin = IteratorUtil.Clone(begin);
            while (!begin.Equals(end))
            {
                yield return(begin.Read());

                begin.MoveNext();
            }
        }
Ejemplo n.º 10
0
 public static InputIterator <T> FindIf <T>(InputIterator <T> begin, InputIterator <T> end, Functional.UnaryPredicate <T> func)
 {
     for (begin = IteratorUtil.Clone(begin); !begin.Equals(end); begin.MoveNext())
     {
         if (func(begin.Read()))
         {
             return(begin);
         }
     }
     return(null);
 }
Ejemplo n.º 11
0
        public static bool Equal <T>(InputIterator <T> begin, InputIterator <T> end, InputIterator <T> cmpBegin, InputIterator <T> cmpEnd, IComparer <T> comparer)
        {
            for (; !begin.Equals(end) && !cmpBegin.Equals(cmpEnd); begin.MoveNext(), cmpBegin.MoveNext())
            {
                T t1 = begin.Read();
                T t2 = cmpBegin.Read();
                if (comparer.Compare(t1, t2) != 0)
                {
                    return(false);
                }
            }

            if (begin.Equals(end) && cmpBegin.Equals(cmpEnd))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 12
0
        public static int Distance <T>(InputIterator <T> first, InputIterator <T> last)
        {
            first = IteratorUtil.Clone(first);
            int result = 0;

            while (!first.Equals(last))
            {
                first.MoveNext();
                ++result;
            }
            return(result);
        }
Ejemplo n.º 13
0
 public static OutputIterator <O> Transform <I, O>(InputIterator <I> begin1, InputIterator <I> end1, InputIterator <I> begin2,
                                                   OutputIterator <O> dest, Functional.BinaryFunction <I, I, O> func)
 {
     begin1 = IteratorUtil.Clone(begin1);
     begin2 = IteratorUtil.Clone(begin2);
     dest   = IteratorUtil.Clone(dest);
     for (; !begin1.Equals(end1); begin1.MoveNext(), begin2.MoveNext(), dest.MoveNext())
     {
         dest.Write(func(begin1.Read(), begin2.Read()));
     }
     return(dest);
 }
Ejemplo n.º 14
0
 public static InputIterator <T> Find <T>(InputIterator <T> begin, InputIterator <T> end, T value)
     where T : IEquatable <T>
 {
     for (; !begin.Equals(end); begin.MoveNext())
     {
         if (value.Equals(begin.Read()))
         {
             return(begin);
         }
     }
     return(null);
 }
Ejemplo n.º 15
0
        public static bool Equal <T>(InputIterator <T> begin, InputIterator <T> end, InputIterator <T> cmpBegin, IEqualityComparer <T> comparer)
        {
            begin    = IteratorUtil.Clone(begin);
            cmpBegin = IteratorUtil.Clone(cmpBegin);

            for (; !begin.Equals(end); begin.MoveNext(), cmpBegin.MoveNext())
            {
                T t1 = begin.Read();
                T t2 = cmpBegin.Read();
                if (!comparer.Equals(t1, t2))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 16
0
        public static int CountIf <T>(InputIterator <T> begin, InputIterator <T> end, Functional.UnaryPredicate <T> func)
        {
            return(CountIf(IteratorUtil.CreateEnumerator(begin, end), func));

#if NEVER
            int count = 0;
            while (!begin.Equals(end))
            {
                if (func(begin.Read()))
                {
                    ++count;
                }
                begin.MoveNext();
            }

            return(count);
#endif
        }
Ejemplo n.º 17
0
        public static int Count <T>(InputIterator <T> begin, InputIterator <T> end, T t, IComparer <T> comparer)
        {
            return(Count(IteratorUtil.CreateEnumerator(begin, end), t, comparer));

#if NEVER
            int count = 0;
            while (!begin.Equals(end))
            {
                if (comparer.Compare(t, begin.Read()) == 0)
                {
                    ++count;
                }
                begin.MoveNext();
            }

            return(count);
#endif
        }
Ejemplo n.º 18
0
// Not sure why I coded these. The STL doesn't have an analgous version of these
        public static bool Equal <T>(InputIterator <T> begin, InputIterator <T> end, InputIterator <T> cmpBegin, InputIterator <T> cmpEnd)
            where T : IEquatable <T>
        {
            return(Equal(begin, end, cmpBegin, cmpEnd, new Functional.EqualComparer <T>()));

#if NEVER
            for (; !begin.Equals(end); begin.MoveNext(), cmpBegin.MoveNext())
            {
                T t1 = begin.Read();
                T t2 = cmpBegin.Read();
                if (!t1.Equals(t2))
                {
                    return(false);
                }
            }

            return(true);
#endif
        }
Ejemplo n.º 19
0
        public static int Count <T>(InputIterator <T> begin, InputIterator <T> end, T value)
            where T : IEquatable <T>
        {
            return(Count(IteratorUtil.CreateEnumerator(begin, end), value));

#if NEVER
            int count = 0;
            while (!begin.Equals(end))
            {
                if (value.Equals(begin.Read()))
                {
                    ++count;
                }
                begin.MoveNext();
            }

            return(count);
#endif
        }
Ejemplo n.º 20
0
        public static InputIterator <T> AdjacentFind <T>(InputIterator <T> begin, InputIterator <T> end, IEqualityComparer <T> comparer)
        {
            if (begin.Equals(end))
            {
                return(null);
            }
            begin = IteratorUtil.Clone(begin);
            InputIterator <T> next = IteratorUtil.Clone(begin);

            next.MoveNext();
            T t1 = begin.Read();
            T t2;

            for (; !next.Equals(end); begin.MoveNext(), next.MoveNext(), t1 = t2)
            {
                t2 = next.Read();
                if (comparer.Equals(t1, t2))
                {
                    return(IteratorUtil.Clone(begin));
                }
            }
            return(null);
        }
Ejemplo n.º 21
0
        public static InputIterator <T> AdjacentFind <T>(InputIterator <T> begin, InputIterator <T> end, Functional.BinaryPredicate <T> op)
        {
            if (begin.Equals(end))
            {
                return(null);
            }

            begin = IteratorUtil.Clone(begin);
            InputIterator <T> next = IteratorUtil.Clone(begin);

            next.MoveNext();
            T t1 = begin.Read();
            T t2;

            for (; !next.Equals(end); begin.MoveNext(), next.MoveNext(), t1 = t2)
            {
                t2 = next.Read();
                if (op(t1, t2))
                {
                    return(IteratorUtil.Clone(begin));
                }
            }
            return(null);
        }
Ejemplo n.º 22
0
 public static OutputIterator <O> Transform <I, O>(InputIterator <I> begin, InputIterator <I> end, OutputIterator <O> dest, Functional.UnaryFunction <I, O> func)
 {
     for (begin = IteratorUtil.Clone(begin), dest = IteratorUtil.Clone(dest); !begin.Equals(end); begin.MoveNext(), dest.MoveNext())
     {
         dest.Write(func(begin.Read()));
     }
     return(dest);
 }
Ejemplo n.º 23
0
 public static OutputIterator <T> RemoveCopyIf <T>(InputIterator <T> begin, InputIterator <T> end, OutputIterator <T> dest, Functional.UnaryPredicate <T> func)
 {
     for (begin = IteratorUtil.Clone(begin), dest = IteratorUtil.Clone(dest); !begin.Equals(end); begin.MoveNext())
     {
         T t = begin.Read();
         if (!func(t))
         {
             dest.Write(t);
             dest.MoveNext();
         }
     }
     return(dest);
 }
Ejemplo n.º 24
0
 public static void ReplaceCopyIf <T>(InputIterator <T> begin, InputIterator <T> end, OutputIterator <T> dest, Functional.UnaryPredicate <T> func, T newValue)
 {
     for (begin = IteratorUtil.Clone(begin), dest = IteratorUtil.Clone(dest); !begin.Equals(end); begin.MoveNext(), dest.MoveNext())
     {
         if (func(begin.Read()))
         {
             dest.Write(newValue);
         }
     }
 }
Ejemplo n.º 25
0
 public static bool IsOneElementRange <T>(InputIterator <T> first, InputIterator <T> last)
 {
     first = IteratorUtil.Clone(first);
     first.MoveNext();
     return(first.Equals(last));
 }
Ejemplo n.º 26
0
 public static OutputIterator <T> RemoveCopy <T>(InputIterator <T> begin, InputIterator <T> end, OutputIterator <T> dest, T value, IEqualityComparer <T> comparer)
 {
     for (begin = IteratorUtil.Clone(begin), dest = IteratorUtil.Clone(dest); !begin.Equals(end); begin.MoveNext())
     {
         T t = begin.Read();
         if (!comparer.Equals(value, t))
         {
             dest.Write(t);
             dest.MoveNext();
         }
     }
     return(dest);
 }
Ejemplo n.º 27
0
 public static OutputIterator <T> RemoveCopy <T>(InputIterator <T> begin, InputIterator <T> end, OutputIterator <T> dest, T value)
     where T : IEquatable <T>
 {
     for (begin = IteratorUtil.Clone(begin), dest = IteratorUtil.Clone(dest); !begin.Equals(end); begin.MoveNext())
     {
         T t = begin.Read();
         if (!value.Equals(t))
         {
             dest.Write(t);
             dest.MoveNext();
         }
     }
     return(dest);
 }
Ejemplo n.º 28
0
        Mismatch <T>(InputIterator <T> begin, InputIterator <T> end, InputIterator <T> cmpBegin, IEqualityComparer <T> comparer)
        {
            for (begin = IteratorUtil.Clone(begin), cmpBegin = IteratorUtil.Clone(cmpBegin); !begin.Equals(end); begin.MoveNext(), cmpBegin.MoveNext())
            {
                T t1 = begin.Read();
                T t2 = cmpBegin.Read();
                if (!comparer.Equals(t1, t2))
                {
                    return(new CSTL.Utility.Pair <InputIterator <T>, InputIterator <T> >(IteratorUtil.Clone(begin), IteratorUtil.Clone(cmpBegin)));
                }
            }

            return(new CSTL.Utility.Pair <InputIterator <T>, InputIterator <T> >(null, null));//begin, cmpBegin);
        }
Ejemplo n.º 29
0
 public static void ReplaceCopy <T>(InputIterator <T> begin, InputIterator <T> end, OutputIterator <T> dest, T oldValue, T newValue, IEqualityComparer <T> comparer)
 {
     for (begin = IteratorUtil.Clone(begin), dest = IteratorUtil.Clone(dest); !begin.Equals(end); begin.MoveNext(), dest.MoveNext())
     {
         T srcValue = begin.Read();
         if (comparer.Equals(oldValue, srcValue))
         {
             dest.Write(newValue);
         }
         else
         {
             dest.Write(srcValue);
         }
     }
 }