/// <summary>Compare two tuples</summary>
 /// <param name="x">First tuple</param>
 /// <param name="y">Second tuple</param>
 /// <returns>Returns a positive value if x is greater than y, a negative value if x is less than y and 0 if x is equal to y.</returns>
 public int Compare(STuple <T1> x, STuple <T1> y)
 {
     if (this.Offset != 0)
     {
         throw new InvalidOperationException("Cannot compare fixed tuples with non-zero offset.");
     }
     return(this.Comparer.Compare(x.Item1, y.Item1));
 }
            /// <summary>Compare two tuples</summary>
            /// <param name="x">First tuple</param>
            /// <param name="y">Second tuple</param>
            /// <returns>Returns a positive value if x is greater than y, a negative value if x is less than y and 0 if x is equal to y.</returns>
            public int Compare(STuple <T1, T2> x, STuple <T1, T2> y)
            {
                if (this.Offset != 0)
                {
                    throw new InvalidOperationException("Cannot compare fixed tuples with non-zero offset.");
                }
                int cmp = this.Comparer1.Compare(x.Item1, y.Item1);

                if (cmp == 0)
                {
                    cmp = this.Comparer2.Compare(x.Item2, y.Item2);
                }
                return(cmp);
            }
Пример #3
0
        public IVarTuple Concat(IVarTuple tuple)
        {
            Contract.NotNull(tuple, nameof(tuple));

            int n1 = tuple.Count;

            if (n1 == 0)
            {
                return(this);
            }

            int n2 = this.Count;

            if (n1 + n2 >= 10)
            {             // it's getting big, merge to a new List tuple
                return(STuple.Concat(this.Head, this.Tail, tuple));
            }
            // REVIEW: should we always concat with the tail?
            return(STuple.Concat(this.Head, this.Tail.Concat(tuple)));
        }
Пример #4
0
 /// <summary>Appends four values at the end of a tuple</summary>
 public static IVarTuple Append <T1, T2, T3, T4>(this IVarTuple tuple, T1 value1, T2 value2, T3 value3, T4 value4)
 {
     Contract.NotNullAllowStructs(tuple, nameof(tuple));
     return(new JoinedTuple(tuple, STuple.Create <T1, T2, T3, T4>(value1, value2, value3, value4)));
 }
 public static ITuple Append <T1, T2, T3, T4>([NotNull] this ITuple tuple, T1 value1, T2 value2, T3 value3, T4 value4)
 {
     Contract.NotNull(tuple, nameof(tuple));
     return(new JoinedTuple(tuple, STuple.Create <T1, T2, T3, T4>(value1, value2, value3, value4)));
 }
 public static ITuple Append <T1, T2>([NotNull] this ITuple tuple, T1 value1, T2 value2)
 {
     Contract.NotNull(tuple, nameof(tuple));
     return(new JoinedTuple(tuple, STuple.Create(value1, value2)));
 }
 public IVarTuple Concat(IVarTuple tuple)
 {
     return(STuple.Concat(this, tuple));
 }
Пример #8
0
 public bool Equals(STuple <T1> other)
 {
     return(SimilarValueComparer.Default.Equals(this.Item1, other.Item1));
 }
Пример #9
0
 /// <summary>Appends two values at the end of a tuple</summary>
 public static IVarTuple Append <T1, T2>(this IVarTuple tuple, T1 value1, T2 value2)
 {
     Contract.NotNullAllowStructs(tuple);
     return(new JoinedTuple(tuple, STuple.Create(value1, value2)));
 }
Пример #10
0
 public ITuple ToTuple(T key)
 {
     return(STuple.Create(key));
 }