/// <summary> /// Initializes a new instance of the <see cref="T:LexicographicalOrd`2"/> class. /// </summary> /// <param name="itemOrder">The order relation defined on the items of the list, must be effective.</param> /// <exception cref="ArgumentNullException">If the given <paramref name="itemOrder"/> is not effective.</exception> public LexicographicalOrd(IOrd <TA, TB> itemOrder) { if (itemOrder == null) { throw new ArgumentNullException("itemOrder"); } Contract.EndContractBlock(); this.itemOrder = itemOrder; }
/// <summary> /// Compares the two effective items. /// </summary> /// <returns>The result of the comparsion of the two effective items.</returns> /// <param name="a">The first item to compare.</param> /// <param name="b">The second item to compare.</param> protected override Ordering CompareEffective(IEnumerable <TA> a, IEnumerable <TB> b) { IEnumerator <TA> ea = a.GetEnumerator(); IEnumerator <TB> eb = b.GetEnumerator(); TA ca; TB cb; bool ma, mb; Ordering res; IOrd <TA, TB> itemOrder = this.itemOrder; if (ea == null || eb == null) { return(Ordering.Unknown); } else { ma = ea.MoveNext(); mb = eb.MoveNext(); while (ma && mb) { ca = ea.Current; cb = eb.Current; res = itemOrder.Compare(ca, cb); if ((res & Ordering.EQ) != 0x00) { return(res); } ma = ea.MoveNext(); mb = eb.MoveNext(); } if (ma) { return(Ordering.GT); } else if (mb) { return(Ordering.LT); } return(Ordering.EQ); } }