public static bool IsPermutation <T>( this ArrayIterator <T> first1, ArrayIterator <T> last1, ArrayIterator <T> first2, Func <T, T, bool> pred ) { first1.Mismatch(last1, first2, pred, out first1, out first2); if (first1.IsEqual(last1)) { return(true); } var last2 = first2; last2 = last2.GetAdvanced(first1.Distance(last1)); for (var it1 = first1; it1.NotEqual(last1); it1 = it1.GetNext()) { if (first1.Find(it1, it1.GetCurrent(), pred).IsEqual(it1)) { var n = first2.Count(last2, it1.GetCurrent(), pred); if (n == 0 || it1.Count(last1, it1.GetCurrent(), pred) != n) { return(false); } } } return(true); }