bool System.Collections.IStructuralEquatable.Equals(object?other, System.Collections.IEqualityComparer comparer)
        {
            if (object.ReferenceEquals(this, other))
            {
                return(true);
            }
            if (other == null)
            {
                return(false);
            }

            if (other is PrefixedTuple linked)
            {
                // Should all of these tuples be considered equal ?
                // * Head=(A,B) + Tail=(C,)
                // * Head=(A,) + Tail=(B,C,)
                // * Head=() + Tail=(A,B,C,)

                // first check the subspaces
                if (!linked.m_prefix.Equals(m_prefix))
                {                 // they have a different prefix
                    return(false);
                }

                if (m_items.Count != linked.m_items.Count)
                {                 // there's no way they would be equal
                    return(false);
                }

                return(comparer.Equals(m_items, linked.m_items));
            }

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

            var sliced = other as SlicedTuple;

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

                // compare slices!
                for (int i = 0; i < m_count; i++)
                {
                    if (m_slices[i + m_offset] != sliced.m_slices[i + sliced.m_offset])
                    {
                        return(false);
                    }
                }
                return(false);
            }

            return(TupleHelpers.Equals(this, other, comparer));
        }
        bool IStructuralEquatable.Equals(object?other, IEqualityComparer comparer)
        {
            if (object.ReferenceEquals(this, other))
            {
                return(true);
            }
            if (other == null)
            {
                return(false);
            }

            if (other is SlicedTuple sliced)
            {
                // compare slices!
                var left  = m_slices.Span;
                var right = sliced.m_slices.Span;
                if (left.Length != right.Length)
                {
                    return(false);
                }
                for (int i = 0; i < left.Length; i++)
                {
                    if (left[i] != right[i])
                    {
                        return(false);
                    }
                }
                return(false);
            }

            return(TupleHelpers.Equals(this, other, comparer));
        }
Ejemplo n.º 4
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);
                }
                return(new SlicedTuple(m_slices, m_offset + begin, len));
            }
        }
Ejemplo n.º 5
0
 public Slice GetSlice(int index)
 {
     return(m_slices[m_offset + TupleHelpers.MapIndex(index, m_count)]);
 }
        public Slice GetSlice(int index)
        {
            var slices = m_slices;

            return(slices.Span[TupleHelpers.MapIndex(index, slices.Length)]);
        }