Esempio n. 1
0
        bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
        {
            if (object.ReferenceEquals(this, other))
            {
                return(true);
            }
            if (other == null)
            {
                return(false);
            }

            var list = other as ListTuple;

            if (!object.ReferenceEquals(list, null))
            {
                if (list.m_count != m_count)
                {
                    return(false);
                }

                if (list.m_offset == 0 && list.m_count == list.m_items.Length)
                {
                    return(CompareItems(list.m_items, comparer));
                }
                else
                {
                    return(CompareItems(list, comparer));
                }
            }

            return(TupleHelpers.Equals(this, other, comparer));
        }
Esempio n. 2
0
 public IVarTuple this[Range range]
 {
     get
     {
         int d = this.Depth;
         (int offset, int count) = range.GetOffsetAndLength(d + 1);
         if (count == 0)
         {
             return(STuple.Empty);
         }
         if (count == 1 && offset == d)
         {
             return(new STuple <T>(this.Tail));
         }
         if (offset == 0)
         {
             if (count == d + 1)
             {
                 return(this);
             }
             if (count == d)
             {
                 return(this.Head);
             }
         }
         return(TupleHelpers.Splice(this, range));
     }
 }
        bool System.Collections.IStructuralEquatable.Equals(object other, System.Collections.IEqualityComparer comparer)
        {
            if (object.ReferenceEquals(this, other))
            {
                return(true);
            }
            if (other == null)
            {
                return(false);
            }

            var linked = other as LinkedTuple <T>;

            if (!object.ReferenceEquals(linked, null))
            {
                // must have same length
                if (linked.Count != this.Count)
                {
                    return(false);
                }
                // compare the tail before
                if (!comparer.Equals(this.Tail, linked.Tail))
                {
                    return(false);
                }
                // compare the rest
                return(this.Head.Equals(linked.Tail, comparer));
            }

            return(TupleHelpers.Equals(this, other, comparer));
        }
Esempio n. 4
0
 public IVarTuple this[Range range]
 {
     get
     {
         int lenHead = this.Head.Count;
         int lenTail = this.Tail.Count;
         (int offset, int count) = range.GetOffsetAndLength(lenHead + lenTail);
         if (count == 0)
         {
             return(STuple.Empty);
         }
         if (offset == 0)
         {
             if (count == lenHead + lenTail)
             {
                 return(this);
             }
             if (count == lenHead)
             {
                 return(this.Head);
             }
         }
         if (offset == lenHead && count == lenTail)
         {
             return(this.Tail);
         }
         return(TupleHelpers.Splice(this, range));
     }
 }
Esempio n. 5
0
        public IVarTuple this[int?fromIncluded, int?toExcluded]
        {
            get
            {
                int begin = fromIncluded.HasValue ? TupleHelpers.MapIndexBounded(fromIncluded.Value, m_count) : 0;
                int end   = toExcluded.HasValue ? TupleHelpers.MapIndexBounded(toExcluded.Value, m_count) : m_count;

                if (end <= begin)
                {
                    return(STuple.Empty);
                }

                int p = this.Head.Count;
                if (begin >= p)
                {                 // all selected items are in the tail
                    return(this.Tail[begin - p, end - p]);
                }
                if (end <= p)
                {                 // all selected items are in the head
                    return(this.Head[begin, end]);
                }
                // selected items are both in head and tail
                return(new JoinedTuple(this.Head[begin, null], this.Tail[null, end - p]));
            }
        }
        /// <summary>Test if the start of current tuple is equal to another tuple</summary>
        /// <param name="left">Larger tuple</param>
        /// <param name="right">Smaller tuple</param>
        /// <returns>True if the beginning of <paramref name="left"/> is equal to <paramref name="right"/> or if both tuples are identical</returns>
        public static bool StartsWith([NotNull] this ITuple left, [NotNull] ITuple right)
        {
            Contract.NotNull(left, nameof(left));
            Contract.NotNull(right, nameof(right));

            //REVIEW: move this on ITuple interface ?
            return(TupleHelpers.StartsWith(left, right));
        }
Esempio n. 7
0
        /// <summary>Test if the end of current tuple is equal to another tuple</summary>
        /// <param name="left">Larger tuple</param>
        /// <param name="right">Smaller tuple</param>
        /// <returns>True if the end of <paramref name="left"/> is equal to <paramref name="right"/> or if both tuples are identical</returns>
        public static bool EndsWith(this IVarTuple left, IVarTuple right)
        {
            Contract.NotNull(left, nameof(left));
            Contract.NotNull(right, nameof(right));

            //REVIEW: move this on ITuple interface ?
            return(TupleHelpers.EndsWith(left, right));
        }
Esempio n. 8
0
 public object?this[int index]
 {
     get
     {
         int p = TupleHelpers.MapIndex(index, m_count);
         return(p < m_split ? this.Head[p] : this.Tail[p - m_split]);
     }
 }
Esempio n. 9
0
 /// <summary>Return the typed value of an item of the tuple, given its position</summary>
 /// <typeparam name="TItem">Expected type of the item</typeparam>
 /// <param name="index">Position of the item (if negative, means relative from the end)</param>
 /// <returns>Value of the item at position <paramref name="index"/>, adapted into type <typeparamref name="TItem"/>.</returns>
 public TItem Get <TItem>(int index)
 {
     if (index > 0 || index < -1)
     {
         return(TupleHelpers.FailIndexOutOfRange <TItem>(index, 1));
     }
     return(TypeConverters.Convert <T1, TItem>(this.Item1));
 }
Esempio n. 10
0
 public object this[int index]
 {
     get
     {
         index = TupleHelpers.MapIndex(index, m_count);
         return(index < m_split ? this.Head[index] : this.Tail[index - m_split]);
     }
 }
Esempio n. 11
0
 object IReadOnlyList <object> .this[int index]
 {
     get
     {
         if (index > 0 || index < -1)
         {
             return(TupleHelpers.FailIndexOutOfRange <object>(index, 1));
         }
         return(this.Item1);
     }
 }
Esempio n. 12
0
 object?IVarTuple.this[int index]
 {
     get
     {
         if (index > 0 || index < -1)
         {
             return(TupleHelpers.FailIndexOutOfRange <object>(index, 1));
         }
         return(this.Item1);
     }
 }
Esempio n. 13
0
 public object?this[Index index]
 {
     get
     {
         int p = TupleHelpers.MapIndex(index, this.Depth + 1);
         if (p == this.Depth)
         {
             return(this.Tail);
         }
         return(this.Head[p]);
     }
 }
        public bool Equals(IVarTuple?other)
        {
            if (other == null)
            {
                return(false);
            }

            if (other is MemoizedTuple mt)
            {
                return(m_packed.Equals(mt.m_packed));
            }

            return(TupleHelpers.Equals(this, other, SimilarValueComparer.Default));
        }
        public bool Equals(IVarTuple other)
        {
            if (object.ReferenceEquals(other, null))
            {
                return(false);
            }

            var memoized = other as MemoizedTuple;

            if (!object.ReferenceEquals(memoized, null))
            {
                return(m_packed.Equals(memoized.m_packed));
            }

            return(TupleHelpers.Equals(this, other, SimilarValueComparer.Default));
        }
Esempio n. 16
0
 bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
 {
     if (other == null)
     {
         return(false);
     }
     if (other is STuple <T1> stuple)
     {
         return(comparer.Equals(this.Item1, stuple.Item1));
     }
     if (other is ValueTuple <T1> vtuple)
     {
         return(comparer.Equals(this.Item1, vtuple.Item1));
     }
     return(TupleHelpers.Equals(this, other, comparer));
 }
Esempio n. 17
0
        public static ITupleFormatter <T> CreateAppender([NotNull] ITuple prefix)
        {
            Contract.NotNull(prefix, nameof(prefix));

            return(new AnonymousTupleFormatter <T>(
                       (value) => prefix.Append <T>(value),
                       (tuple) =>
            {
                if (tuple.Count != prefix.Count + 1)
                {
                    throw new ArgumentException("Tuple size is invalid", "tuple");
                }
                if (!TupleHelpers.StartsWith(tuple, prefix))
                {
                    throw new ArgumentException("Tuple does not start with the expected prefix", "tuple");
                }
                return tuple.Last <T>();
            }
                       ));
        }
Esempio n. 18
0
        public IVarTuple this[int?fromIncluded, int?toExcluded]
        {
            get
            {
                int begin = fromIncluded.HasValue ? TupleHelpers.MapIndexBounded(fromIncluded.Value, m_count) : 0;
                int end   = toExcluded.HasValue ? TupleHelpers.MapIndexBounded(toExcluded.Value, m_count) : m_count;

                int len = end - begin;
                if (len <= 0)
                {
                    return(STuple.Empty);
                }
                if (begin == 0 && len == m_count)
                {
                    return(this);
                }

                Contract.Assert(m_offset + begin >= m_offset);
                Contract.Assert(len >= 0 && len <= m_count);

                return(new ListTuple(m_items, m_offset + begin, len));
            }
        }
Esempio n. 19
0
        public IVarTuple this[int?fromIncluded, int?toExcluded]
        {
            get
            {
                int count = m_items.Length;
                int begin = fromIncluded.HasValue ? TupleHelpers.MapIndexBounded(fromIncluded.Value, count) : 0;
                int end   = toExcluded.HasValue ? TupleHelpers.MapIndexBounded(toExcluded.Value, count) : count;

                int len = end - begin;
                if (len <= 0)
                {
                    return(STuple.Empty);
                }
                if (begin == 0 && len == count)
                {
                    return(this);
                }

                Contract.Debug.Assert(begin >= 0);
                Contract.Debug.Assert((uint)len <= count);

                return(new ListTuple <T>(m_items.Slice(begin, len)));
            }
        }
 public object this[int index] => m_items[TupleHelpers.MapIndex(index, m_items.Length)];
Esempio n. 21
0
        public T Get <T>(int index)
        {
            index = TupleHelpers.MapIndex(index, m_count);

            return(index < m_split?this.Head.Get <T>(index) : this.Tail.Get <T>(index - m_split));
        }
 public object this[int index]
 {
     get { return(m_items[TupleHelpers.MapIndex(index, m_items.Length)]); }
 }
Esempio n. 23
0
 public T this[Index index] => m_items.Span[TupleHelpers.MapIndex(index, m_items.Length)];
 public ITuple this[int?fromIncluded, int?toExcluded]
 {
     get { return(TupleHelpers.Splice(this, fromIncluded, toExcluded)); }
 }
Esempio n. 25
0
 public object this[int index] => m_items[m_offset + TupleHelpers.MapIndex(index, m_count)];
 bool IStructuralEquatable.Equals(object other, System.Collections.IEqualityComparer comparer)
 {
     return(TupleHelpers.Equals(this, other, comparer));
 }
 int System.Collections.IStructuralEquatable.GetHashCode(System.Collections.IEqualityComparer comparer)
 {
     return(TupleHelpers.StructuralGetHashCode(this, comparer));
 }
 public IVarTuple this[int?fromIncluded, int?toExcluded] => TupleHelpers.Splice(this, fromIncluded, toExcluded);