/// <summary> /// Two HashableView matrices are equal if they are MatrixEquals, that is, they have the same /// RowKeys and ColKeys (in the same order), the same special MissingValue, and the same values. /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { HashableView <TRowKey, TColKey, TValue> other = obj as HashableView <TRowKey, TColKey, TValue>; if (other == null) { return(false); } else { return(_hashCode == other._hashCode && this.MatrixEquals(other)); } }
/// <summary> /// Creates a view of the parent matrix which is hashable. For example, it can be used as the key of a dictionary. /// This is a 'view' in the sense that no copying an every little extra memory is used. /// /// Two HashableView matricies are equal if their RowKeys and ColKeys (in order), MissingValue, and values are equal. /// They will have the same hashcode if they are equal. /// /// The hashcode is computed only once when the the HashableView is contructed, so a HashableView does not allow /// its values to be changed. Also, changing values of the parent will give unexpected results. /// /// When used by Dictionary or HashSet, a full call of MatrixEquals (which looks at every value) is needed to confirm /// that two matrices with the same hashcode are really equal. ///</summary> /// <typeparam name="TRowKey">The type of the row key. Usually "String"</typeparam> /// <typeparam name="TColKey">The type of the col key. Usually "String"</typeparam> /// <typeparam name="TValue">The type of the value, for example, double, int, char, etc.</typeparam> /// <param name="parentMatrix">The matrix to wrap.</param> /// <returns>A hashable matrix</returns> static public Matrix <TRowKey, TColKey, TValue> HashableView <TRowKey, TColKey, TValue>( this Matrix <TRowKey, TColKey, TValue> parentMatrix) { //If this is a HashableView of a HashableView, simplify HashableView <TRowKey, TColKey, TValue> parentHashableViewOrNull = parentMatrix as HashableView <TRowKey, TColKey, TValue>; if (null != parentHashableViewOrNull) { return(parentHashableViewOrNull.ParentMatrix); } var hashableView = new HashableView <TRowKey, TColKey, TValue>(); hashableView.ParentMatrix = parentMatrix; return(hashableView); }