예제 #1
0
        public int GetHashCode(ComparableTuple2 <TItem0, TItem1> group)
        {
            int hash0 = group.Item0.GetHashCode();
            int hash1 = group.Item1.GetHashCode();
            int hash  = 577 * hash0 + 599 * hash1;

            return(hash.GetHashCode());
        }
        /// <summary>
        /// Method to copy the data in this Sparse2DMatrix instance to another instance.
        /// </summary>
        /// <param name="sparse2DMatrix">An instance of the Sparse2DMatrix class.</param>
        public void CopyTo(Sparse2DMatrix <TKey0, TKey1, TValue> sparse2DMatrix)
        {
            sparse2DMatrix.m_dictionary.Clear();

            // Copy each key value pair to the dictionary.
            foreach (KeyValuePair <ComparableTuple2 <TKey0, TKey1>, TValue> pair in m_dictionary)
            {
                ComparableTuple2 <TKey0, TKey1> newCombinedKey = new ComparableTuple2 <TKey0, TKey1>(pair.Key);
                sparse2DMatrix.m_dictionary.Add(newCombinedKey, pair.Value);
            }
        }
        /// <summary>
        /// Method to copy the data in another Sparse2DMatrix instance to this instance.
        /// </summary>
        /// <param name="sparse2DMatrix">An instance of the Sparse2DMatrix class.</param>
        private void Initialize(Sparse2DMatrix <TKey0, TKey1, TValue> sparse2DMatrix)
        {
            m_dictionary.Clear();

            // Copy each key value pair to the dictionary.
            foreach (KeyValuePair <ComparableTuple2 <TKey0, TKey1>, TValue> pair in sparse2DMatrix)
            {
                ComparableTuple2 <TKey0, TKey1> newCombinedKey = new ComparableTuple2 <TKey0, TKey1>(pair.Key);
                m_dictionary.Add(newCombinedKey, pair.Value);
            }
        }
예제 #4
0
        /// <summary>
        /// This methods implements the IComparable<ComparableTuple2<TItem0, TItem1>> interface.
        /// </summary>
        /// <param name="group">The group being compared to this group</param>
        /// <returns>
        /// The value -1 if this groups is less than the passed group.
        /// The value 1 if this group is greater than the passed group.
        /// The value 0 if this group and the passed groups are equal.
        /// </returns>
        public int CompareTo(ComparableTuple2 <TItem0, TItem1> group)
        {
            int result = this.Item0.CompareTo(group.Item0);

            if (result == 0)
            {
                result = this.Item1.CompareTo(group.Item1);
            }

            return(result);
        }
 public void SeparateCombinedKeys(ComparableTuple2 <TKey0, TKey1> combinedKey, ref TKey0 key0, ref TKey1 key1)
 {
     key0 = combinedKey.Item0;
     key1 = combinedKey.Item1;
 }
예제 #6
0
 /// <summary>
 /// Constructs a new instance with the same item values as this instance.
 /// </summary>
 /// <param name="group2"></param>
 public ComparableTuple2(ComparableTuple2 <TItem0, TItem1> group)
 {
     Item0 = group.Item0;
     Item1 = group.Item1;
 }
예제 #7
0
 /// IEqualityComparer.Equals compares the items in this group for equality.
 public bool Equals(ComparableTuple2 <TItem0, TItem1> groupA,
                    ComparableTuple2 <TItem0, TItem1> groupB)
 {
     return((groupA.Item0.Equals(groupB.Item0)) &&
            (groupA.Item1.Equals(groupB.Item1)));
 }