コード例 #1
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static void MinMaxElement <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     Func <T, T, bool> comp,
     out ArrayIterator <T> min,
     out ArrayIterator <T> max
     )
 {
     if (first.IsEqual(last))
     {
         min = last;
         max = last;
     }
     min = first;
     max = first;
     while ((first = first.GetNext()).NotEqual(last))
     {
         if (comp(first.GetCurrent(), min.GetCurrent()))
         {
             min = first;
         }
         if (comp(max.GetCurrent(), first.GetCurrent()))
         {
             max = first;
         }
     }
 }
コード例 #2
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static ArrayIterator <T> SetDifference <T>(
     this ArrayIterator <T> first1,
     ArrayIterator <T> last1,
     ArrayIterator <T> first2,
     ArrayIterator <T> last2,
     ArrayIterator <T> result,
     Func <T, T, bool> comp
     )
 {
     while (first1.NotEqual(last1) && first2.NotEqual(last2))
     {
         if (comp(first1.GetCurrent(), first2.GetCurrent()))
         {
             result.SetCurrent(first1.GetCurrent());
             result = result.GetNext();
             first1 = first1.GetNext();
         }
         else if (comp(first2.GetCurrent(), first1.GetCurrent()))
         {
             first2 = first2.GetNext();
         }
         else
         {
             first1 = first1.GetNext();
             first2 = first2.GetNext();
         }
     }
     return(first1.Copy(last1, result));
 }
コード例 #3
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static void PartitionCopy <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     ArrayIterator <T> resultTrue,
     ArrayIterator <T> resultFalse,
     Func <T, bool> pred,
     out ArrayIterator <T> outResultTrue,
     out ArrayIterator <T> outResultFalse
     )
 {
     while (first.NotEqual(last))
     {
         if (pred(first.GetCurrent()))
         {
             resultTrue.SetCurrent(first.GetCurrent());
             resultTrue = resultTrue.GetNext();
         }
         else
         {
             resultFalse.SetCurrent(first.GetCurrent());
             resultFalse = resultFalse.GetNext();
         }
         first = first.GetNext();
     }
     outResultTrue  = resultTrue;
     outResultFalse = resultFalse;
 }
コード例 #4
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static ArrayIterator <T> Merge <T>(
     this ArrayIterator <T> first1,
     ArrayIterator <T> last1,
     ArrayIterator <T> first2,
     ArrayIterator <T> last2,
     ArrayIterator <T> result,
     Func <T, T, bool> comp
     )
 {
     while (true)
     {
         if (first1.IsEqual(last1))
         {
             return(first2.Copy(last2, result));
         }
         if (first2.IsEqual(last2))
         {
             return(first1.Copy(last1, result));
         }
         if (comp(first2.GetCurrent(), first1.GetCurrent()))
         {
             result.SetCurrent(first2.GetCurrent());
             first2 = first2.GetNext();
         }
         else
         {
             result.SetCurrent(first1.GetCurrent());
             first1 = first1.GetNext();
         }
         result = result.GetNext();
     }
 }
コード例 #5
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
        public static ArrayIterator <T> UniqueCopy <T>(
            this ArrayIterator <T> first,
            ArrayIterator <T> last,
            ArrayIterator <T> result,
            Func <T, T, bool> pred
            )
        {
            if (first.IsEqual(last))
            {
                return(last);
            }

            result.SetCurrent(first.GetCurrent());
            while ((first = first.GetNext()).NotEqual(last))
            {
                var val = first.GetCurrent();
                if (pred(result.GetCurrent(), val) == false)
                {
                    result = result.GetNext();
                    result.SetCurrent(val);
                }
            }
            result = result.GetNext();
            return(result);
        }
コード例 #6
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static ArrayIterator <T> Partition <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     Func <T, bool> pred
     )
 {
     while (first.NotEqual(last))
     {
         while (pred(first.GetCurrent()))
         {
             first = first.GetNext();
             if (first.IsEqual(last))
             {
                 return(first);
             }
         }
         do
         {
             last = last.GetPrev();
             if (first.IsEqual(last))
             {
                 return(first);
             }
         } while (pred(last.GetCurrent()) == false);
         first.Swap(last);
         first = first.GetNext();
     }
     return(first);
 }
コード例 #7
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static ArrayIterator <T> ReplaceCopyIf <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     ArrayIterator <T> result,
     Func <T, bool> pred,
     T newValue
     )
 {
     while (first.NotEqual(last))
     {
         result.SetCurrent(pred(first.GetCurrent()) ? newValue : first.GetCurrent());
         first  = first.GetNext();
         result = result.GetNext();
     }
     return(result);
 }
コード例 #8
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
        public static void Swap <T>(this ArrayIterator <T> a, ArrayIterator <T> b)
        {
            var temp = a.GetCurrent();

            a.SetCurrent(b.GetCurrent());
            b.SetCurrent(temp);
        }
コード例 #9
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
        public static void Sort <T>(
            this ArrayIterator <T> first,
            ArrayIterator <T> last,
            Func <T, T, bool> comp
            )
        {
            // Quicksort
            if (first.IsEqual(last))
            {
                return;
            }
            var sep = first;

            for (var i = first.GetNext(); i.NotEqual(last); i = i.GetNext())
            {
                if (comp(i.GetCurrent(), first.GetCurrent()))
                {
                    sep = sep.GetNext();
                    sep.Swap(i);
                }
            }
            first.Swap(sep);
            first.Sort(sep, comp);
            sep.GetNext().Sort(last, comp);
        }
コード例 #10
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static ArrayIterator <T> CopyIf <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     ArrayIterator <T> result,
     Func <T, bool> pred
     )
 {
     while (first.NotEqual(last))
     {
         if (pred(first.GetCurrent()))
         {
             result.SetCurrent(first.GetCurrent());
             result = result.GetNext();
         }
         first = first.GetNext();
     }
     return(result);
 }
コード例 #11
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static bool BinarySearch <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     T val,
     Func <T, T, bool> comp
     )
 {
     first = first.LowerBound(last, val, comp);
     return(first.NotEqual(last) && comp(val, first.GetCurrent()) == false);
 }
コード例 #12
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static bool IsPartitioned <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     Func <T, bool> pred
     )
 {
     while (first.NotEqual(last) && pred(first.GetCurrent()))
     {
         first = first.GetNext();
     }
     while (first.NotEqual(last))
     {
         if (pred(first.GetCurrent()))
         {
             return(false);
         }
         first = first.GetNext();
     }
     return(true);
 }
コード例 #13
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static void ForEach <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     Action <T> callback
     )
 {
     while (first.NotEqual(last))
     {
         callback(first.GetCurrent());
         first = first.GetNext();
     }
 }
コード例 #14
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static bool Includes <T>(
     this ArrayIterator <T> first1,
     ArrayIterator <T> last1,
     ArrayIterator <T> first2,
     ArrayIterator <T> last2,
     Func <T, T, bool> comp
     )
 {
     while (first2.NotEqual(last2))
     {
         if ((first1.IsEqual(last1)) || comp(first2.GetCurrent(), first1.GetCurrent()))
         {
             return(false);
         }
         if (comp(first1.GetCurrent(), first2.GetCurrent()) == false)
         {
             first2 = first2.GetNext();
         }
         first1 = first1.GetNext();
     }
     return(true);
 }
コード例 #15
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static bool LexicographicalCompare <T>(
     this ArrayIterator <T> first1,
     ArrayIterator <T> last1,
     ArrayIterator <T> first2,
     ArrayIterator <T> last2,
     Func <T, T, bool> comp
     )
 {
     while (first1.NotEqual(last1))
     {
         if (first2.IsEqual(last2) || comp(first2.GetCurrent(), first1.GetCurrent()))
         {
             return(false);
         }
         else if (comp(first1.GetCurrent(), first2.GetCurrent()))
         {
             return(true);
         }
         first1 = first1.GetNext();
         first2 = first2.GetNext();
     }
     return(first2.NotEqual(last2));
 }
コード例 #16
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static ArrayIterator <T> CopyBackward <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     ArrayIterator <T> result
     )
 {
     while (last.NotEqual(first))
     {
         result = result.GetPrev();
         last   = last.GetPrev();
         result.SetCurrent(last.GetCurrent());
     }
     return(result);
 }
コード例 #17
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static ArrayIterator <T> ReverseCopy <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     ArrayIterator <T> result
     )
 {
     while (first.NotEqual(last))
     {
         last = last.GetPrev();
         result.SetCurrent(last.GetCurrent());
         result = result.GetNext();
     }
     return(result);
 }
コード例 #18
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static ArrayIterator <T> CopyN <T>(
     this ArrayIterator <T> first,
     int n,
     ArrayIterator <T> result
     )
 {
     while (n > 0)
     {
         result.SetCurrent(first.GetCurrent());
         result = result.GetNext();
         first  = first.GetNext();
         n--;
     }
     return(result);
 }
コード例 #19
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static ArrayIterator <T> Transform <T>(
     this ArrayIterator <T> first1,
     ArrayIterator <T> last1,
     ArrayIterator <T> result,
     Func <T, T> op
     )
 {
     while (first1.NotEqual(last1))
     {
         result.SetCurrent(op(first1.GetCurrent()));
         result = result.GetNext();
         first1 = first1.GetNext();
     }
     return(result);
 }
コード例 #20
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static bool AllOf <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     Func <T, bool> pred
     )
 {
     while (first.NotEqual(last))
     {
         if (pred(first.GetCurrent()) == false)
         {
             return(false);
         }
         first = first.GetNext();
     }
     return(true);
 }
コード例 #21
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static ArrayIterator <T> FindIf <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     Func <T, bool> pred
     )
 {
     while (first.NotEqual(last))
     {
         if (pred(first.GetCurrent()))
         {
             return(first);
         }
         first = first.GetNext();
     }
     return(last);
 }
コード例 #22
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static void ReplaceIf <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     Func <T, bool> pred,
     T newValue
     )
 {
     while (first.NotEqual(last))
     {
         if (pred(first.GetCurrent()))
         {
             first.SetCurrent(newValue);
         }
         first = first.GetNext();
     }
 }
コード例 #23
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
        public static int CountIf <T>(
            this ArrayIterator <T> first,
            ArrayIterator <T> last,
            Func <T, bool> pred
            )
        {
            var count = 0;

            while (first.NotEqual(last))
            {
                if (pred(first.GetCurrent()))
                {
                    count++;
                }
                first = first.GetNext();
            }
            return(count);
        }
コード例 #24
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static bool Equal <T>(
     this ArrayIterator <T> first1,
     ArrayIterator <T> last1,
     ArrayIterator <T> first2,
     Func <T, T, bool> pred
     )
 {
     while (first1.NotEqual(last1))
     {
         if (pred(first1.GetCurrent(), first2.GetCurrent()) == false)
         {
             return(false);
         }
         first1 = first1.GetNext();
         first2 = first2.GetNext();
     }
     return(true);
 }
コード例 #25
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
        public static ArrayIterator <T> MaxElement <T>(
            this ArrayIterator <T> first,
            ArrayIterator <T> last,
            Func <T, T, bool> comp
            )
        {
            if (first.IsEqual(last))
            {
                return(last);
            }
            var largest = first;

            while ((first = first.GetNext()).NotEqual(last))
            {
                if (comp(largest.GetCurrent(), first.GetCurrent()))
                {
                    largest = first;
                }
            }
            return(largest);
        }
コード例 #26
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static ArrayIterator <T> FindFirstOf <T>(
     this ArrayIterator <T> first1,
     ArrayIterator <T> last1,
     ArrayIterator <T> first2,
     ArrayIterator <T> last2,
     Func <T, T, bool> pred
     )
 {
     while (first1.NotEqual(last1))
     {
         for (var it = first2; it.NotEqual(last2); it = it.GetNext())
         {
             if (pred(it.GetCurrent(), first1.GetCurrent()))
             {
                 return(first1);
             }
         }
         first1 = first1.GetNext();
     }
     return(last1);
 }
コード例 #27
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static void Mismatch <T>(
     this ArrayIterator <T> first1,
     ArrayIterator <T> last1,
     ArrayIterator <T> first2,
     Func <T, T, bool> pred,
     out ArrayIterator <T> mismatch1,
     out ArrayIterator <T> mismatch2
     )
 {
     while (first1.NotEqual(last1))
     {
         if (pred(first1.GetCurrent(), first2.GetCurrent()) == false)
         {
             break;
         }
         first1 = first1.GetNext();
         first2 = first2.GetNext();
     }
     mismatch1 = first1;
     mismatch2 = first2;
 }
コード例 #28
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
        public static ArrayIterator <T> IsSortedUntil <T>(
            this ArrayIterator <T> first,
            ArrayIterator <T> last,
            Func <T, T, bool> comp
            )
        {
            if (first.IsEqual(last))
            {
                return(first);
            }
            var next = first;

            while ((next = next.GetNext()).NotEqual(last))
            {
                if (comp(next.GetCurrent(), first.GetCurrent()))
                {
                    return(next);
                }
                first = first.GetNext();
            }
            return(last);
        }
コード例 #29
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
        public static void PushHeap <T>(
            this ArrayIterator <T> first,
            ArrayIterator <T> last,
            Func <T, T, bool> comp
            )
        {
            if (first.Distance(last) < 2)
            {
                return;
            }
            last = last.GetPrev();
            var temp   = last.GetCurrent();
            var parent = first.GetAdvanced((first.Distance(last) - 1) / 2);

            while (first.Distance(last) > 0 && comp(parent.GetCurrent(), temp))
            {
                last.SetCurrent(parent.GetCurrent());
                last   = parent;
                parent = first.GetAdvanced((first.Distance(last) - 1) / 2);
            }
            last.SetCurrent(temp);
        }
コード例 #30
0
ファイル: ArrayIterator.cs プロジェクト: thygrrr/iterator
 public static ArrayIterator <T> AdjacentFind <T>(
     this ArrayIterator <T> first,
     ArrayIterator <T> last,
     Func <T, T, bool> pred
     )
 {
     if (first.NotEqual(last))
     {
         var next = first;
         next = next.GetNext();
         while (next.NotEqual(last))
         {
             if (pred(first.GetCurrent(), next.GetCurrent()))
             {
                 return(first);
             }
             first = first.GetNext();
             next  = next.GetNext();
         }
     }
     return(last);
 }