コード例 #1
0
        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(STuple.Equals(this, other, comparer));
        }
コード例 #2
0
        /// <summary>Return the Nth item in this tuple</summary>
        public object this[int index]
        {
            get
            {
                switch (index)
                {
                case 0:
                case -5: return(this.Item1);

                case 1:
                case -4: return(this.Item2);

                case 2:
                case -3: return(this.Item3);

                case 3:
                case -2: return(this.Item4);

                case 4:
                case -1: return(this.Item5);

                default: STuple.FailIndexOutOfRange(index, 5); return(null);
                }
            }
        }
コード例 #3
0
 int IStructuralEquatable.GetHashCode(System.Collections.IEqualityComparer comparer)
 {
     return(STuple.CombineHashCodes(
                this.Head != null ? this.Head.GetHashCode(comparer) : 0,
                comparer.GetHashCode(this.Tail)
                ));
 }
コード例 #4
0
 int IStructuralEquatable.GetHashCode(System.Collections.IEqualityComparer comparer)
 {
     return(STuple.CombineHashCodes(
                m_prefix.GetHashCode(),
                comparer.GetHashCode(m_items)
                ));
 }
コード例 #5
0
        public void PackKey(ref SliceWriter writer, ITuple items)
        {
            var tw = new TupleWriter(writer);

            STuple.Pack(ref tw, items);
            writer = tw.Output;
        }
コード例 #6
0
 public object this[int index]
 {
     get
     {
         return(m_items[m_offset + STuple.MapIndex(index, m_count)]);
     }
 }
コード例 #7
0
 int System.Collections.IStructuralEquatable.GetHashCode(System.Collections.IEqualityComparer comparer)
 {
     return(STuple.CombineHashCodes(
                comparer.GetHashCode(this.Item1),
                comparer.GetHashCode(this.Item2)
                ));
 }
コード例 #8
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(STuple.Equals(this, other, comparer));
        }
コード例 #9
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(STuple.Equals(this, other, comparer));
        }
コード例 #10
0
        public ITuple this[int?fromIncluded, int?toExcluded]
        {
            get
            {
                int begin = fromIncluded.HasValue ? STuple.MapIndexBounded(fromIncluded.Value, m_count) : 0;
                int end   = toExcluded.HasValue ? STuple.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]);
                }
                else if (end <= p)
                {                 // all selected items are in the head
                    return(this.Head[begin, end]);
                }
                else
                {                 // selected items are both in head and tail
                    return(new JoinedTuple(this.Head[begin, null], this.Tail[null, end - p]));
                }
            }
        }
コード例 #11
0
 public object this[int index]
 {
     get
     {
         index = STuple.MapIndex(index, m_count);
         return(index < m_split ? this.Head[index] : this.Tail[index - m_split]);
     }
 }
コード例 #12
0
 /// <summary>Return the typed value of an item of the tuple, given its position</summary>
 /// <typeparam name="R">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="R"/>.</returns>
 public R Get <R>(int index)
 {
     if (index > 0 || index < -1)
     {
         STuple.FailIndexOutOfRange(index, 1);
     }
     return(FdbConverters.Convert <T1, R>(this.Item1));
 }
コード例 #13
0
 public override string ToString()
 {
     return(new StringBuilder(32).Append('(')
            .Append(STuple.Stringify(this.Item1)).Append(", ")
            .Append(STuple.Stringify(this.Item2)).Append(", ")
            .Append(STuple.Stringify(this.Item3)).Append(')')
            .ToString());
 }
コード例 #14
0
 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
 {
     return(STuple.CombineHashCodes(
                comparer.GetHashCode(this.Item1),
                comparer.GetHashCode(this.Item2),
                comparer.GetHashCode(this.Item3)
                ));
 }
コード例 #15
0
 public static ITuple Append <T1, T2, T3, T4>([NotNull] this ITuple tuple, T1 value1, T2 value2, T3 value3, T4 value4)
 {
     if (tuple == null)
     {
         throw new ArgumentNullException(nameof(tuple));
     }
     return(new JoinedTuple(tuple, STuple.Create <T1, T2, T3, T4>(value1, value2, value3, value4)));
 }
コード例 #16
0
        public override T DecodeOrderedSelfTerm(ref SliceReader input)
        {
            //HACKHACK: we lose the current depth!
            var  reader = new TupleReader(input);
            T    value;
            bool res = STuple.DecodeNext <T>(ref reader, out value);

            input = reader.Input;
            return(res ? value : m_missingValue);
        }
コード例 #17
0
        public static ITuple ToTupleOrDefault(this Slice slice)
        {
            //note: this method is here to allow a fluent API with method chaining, like "something.ToFoundationDbKey().ToTuple().With((int x, int y) => .....)"

            if (slice.IsNullOrEmpty)
            {
                return(slice.HasValue ? STuple.Empty : null);
            }

            return(STuple.Unpack(slice));
        }
コード例 #18
0
 public object this[int index]
 {
     get
     {
         if (index > 0 || index < -1)
         {
             STuple.FailIndexOutOfRange(index, 1);
         }
         return(this.Item1);
     }
 }
コード例 #19
0
 bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
 {
     if (other == null)
     {
         return(false);
     }
     if (other is STuple <T1> )
     {
         return(comparer.Equals(this.Item1, ((STuple <T1>)other).Item1));
     }
     return(STuple.Equals(this, other, comparer));
 }
コード例 #20
0
        /// <summary>Return the typed value of an item of the tuple, given its position</summary>
        /// <typeparam name="R">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="R"/>.</returns>
        public R Get <R>(int index)
        {
            switch (index)
            {
            case 0:
            case -2: return(FdbConverters.Convert <T1, R>(this.Item1));

            case 1:
            case -1: return(FdbConverters.Convert <T2, R>(this.Item2));

            default: STuple.FailIndexOutOfRange(index, 2); return(default(R));
            }
        }
コード例 #21
0
 bool System.Collections.IStructuralEquatable.Equals(object other, System.Collections.IEqualityComparer comparer)
 {
     if (other == null)
     {
         return(false);
     }
     if (other is STuple <T1, T2> )
     {
         var tuple = (STuple <T1, T2>)other;
         return(comparer.Equals(this.Item1, tuple.Item1) &&
                comparer.Equals(this.Item2, tuple.Item2));
     }
     return(STuple.Equals(this, other, comparer));
 }
コード例 #22
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([NotNull] this ITuple left, [NotNull] ITuple right)
        {
            if (left == null)
            {
                throw new ArgumentNullException(nameof(left));
            }
            if (right == null)
            {
                throw new ArgumentNullException(nameof(right));
            }

            //REVIEW: move this on ITuple interface ?
            return(STuple.EndsWith(left, right));
        }
コード例 #23
0
 bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
 {
     if (other == null)
     {
         return(false);
     }
     if (other is STuple <T1, T2, T3> )
     {
         var tuple = (STuple <T1, T2, T3>)other;
         return(comparer.Equals(this.Item1, tuple.Item1) &&
                comparer.Equals(this.Item2, tuple.Item2) &&
                comparer.Equals(this.Item3, tuple.Item3));
     }
     return(STuple.Equals(this, other, comparer));
 }
コード例 #24
0
        public bool Equals(ITuple 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(STuple.Equals(this, other, SimilarValueComparer.Default));
        }
コード例 #25
0
        public ITuple this[int?fromIncluded, int?toExcluded]
        {
            get
            {
                int begin = fromIncluded.HasValue ? STuple.MapIndexBounded(fromIncluded.Value, m_count) : 0;
                int end   = toExcluded.HasValue ? STuple.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));
            }
        }
コード例 #26
0
        int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
        {
            bool canUseCache = object.ReferenceEquals(comparer, SimilarValueComparer.Default);

            if (m_hashCode.HasValue && canUseCache)
            {
                return(m_hashCode.Value);
            }

            int h = 0;

            for (int i = 0; i < m_count; i++)
            {
                h = STuple.CombineHashCodes(h, comparer.GetHashCode(m_slices[i + m_offset]));
            }
            if (canUseCache)
            {
                m_hashCode = h;
            }
            return(h);
        }
コード例 #27
0
        /// <summary>Return the typed value of an item of the tuple, given its position</summary>
        /// <typeparam name="R">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="R"/>.</returns>
        public R Get <R>(int index)
        {
            switch (index)
            {
            case 0:
            case -5: return(FdbConverters.Convert <T1, R>(this.Item1));

            case 1:
            case -4: return(FdbConverters.Convert <T2, R>(this.Item2));

            case 2:
            case -3: return(FdbConverters.Convert <T3, R>(this.Item3));

            case 3:
            case -2: return(FdbConverters.Convert <T4, R>(this.Item4));

            case 4:
            case -1: return(FdbConverters.Convert <T5, R>(this.Item5));

            default: STuple.FailIndexOutOfRange(index, 5); return(default(R));
            }
        }
コード例 #28
0
        /// <summary>Create a formatter that just add or remove a prefix to values</summary>
        public static ITupleFormatter <T> CreateAppender(ITuple prefix)
        {
            if (prefix == null)
            {
                throw new ArgumentNullException(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", nameof(tuple));
                }
                if (!STuple.StartsWith(tuple, prefix))
                {
                    throw new ArgumentException("Tuple does not start with the expected prefix", nameof(tuple));
                }
                return tuple.Last <T>();
            }
                       ));
        }
コード例 #29
0
        public ITuple this[int?fromIncluded, int?toExcluded]
        {
            get
            {
                int begin = fromIncluded.HasValue ? STuple.MapIndexBounded(fromIncluded.Value, m_count) : 0;
                int end   = toExcluded.HasValue ? STuple.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));
            }
        }
コード例 #30
0
        int IStructuralEquatable.GetHashCode(System.Collections.IEqualityComparer comparer)
        {
            // the cached hashcode is only valid for the default comparer!
            bool canUseCache = object.ReferenceEquals(comparer, SimilarValueComparer.Default);

            if (m_hashCode.HasValue && canUseCache)
            {
                return(m_hashCode.Value);
            }

            int h = 0;

            for (int i = 0; i < m_count; i++)
            {
                var item = m_items[i + m_offset];

                h = STuple.CombineHashCodes(h, comparer.GetHashCode(item));
            }
            if (canUseCache)
            {
                m_hashCode = h;
            }
            return(h);
        }