xtd 0.2.0
Loading...
Searching...
No Matches
xtd::collections::generic::iequality_comparer< type_t > Class Template Referenceabstract
Inheritance diagram for xtd::collections::generic::iequality_comparer< type_t >:
xtd::interface

Definition

template<typename type_t>
class xtd::collections::generic::iequality_comparer< type_t >

Defines methods to support the comparison of objects for equality.

Definition
template<typename type_t>
Defines methods to support the comparison of objects for equality.
Definition iequality_comparer.hpp:34
#define interface_
This keyword is use to represent an interface.
Definition interface.hpp:58
Header
#include <xtd/collections/iequality_comparer
Namespace
xtd::collections::generic
Library
xtd.core
Remarks
This interface allows the implementation of customized equality comparison for collections. That is, you can create your own definition of equality for type type_t, and specify that this definition be used with a collection type that accepts the xtd::collections::generic::iequality_comparer <type_t> generic interface. In the xtd framework, constructors of the xtd::collections::generic::dictionary <key_t, value_t> generic collection type accept this interface.
A default implementation of this interface is provided by the xtd::collections::generic::equality_comparer::default_equality_comparer property of the xtd::collections::generic::equality_comparer <type_t> generic class. The xtd::string_comparer class implements xtd::collections::generic::iequality_comparer <type_t> of type xtd::string.
This interface supports only equality comparisons. Customization of comparisons for sorting and ordering is provided by the xtd::collections::generic::icomparer <type_t> generic interface.
We recommend that you derive from the xtd::collections::generic::equality_comparer <type_t> class instead of implementing the xtd::collections::generic::iequality_comparer <type_t> interface, because the xtd::collections::generic::equality_comparer <type_t> class tests for equality using the xtd::iequatable::equals method instead of the xtd::object::equals method. This is consistent with the contains, index_of, last_index_of, and remove methods of the xtd::collections::generic::dictionary <key_t, value_t> class and other generic collections.
Examples
generic_icollection.cpp, and generic_ilist.cpp.

Public Methods

virtual bool equals (const type_t &x, const type_t &y) const noexcept=0
 Determines whether the specified objects are equal.
 
virtual xtd::size get_hash_code (const type_t &obj) const noexcept=0
 Returns a hash code for the specified object.
 

Member Function Documentation

◆ equals()

template<typename type_t >
virtual bool xtd::collections::generic::iequality_comparer< type_t >::equals ( const type_t &  x,
const type_t &  y 
) const
pure virtualnoexcept

Determines whether the specified objects are equal.

Parameters
xThe first object of type type_t to compare.
yThe seco,d object of type type_t to compare.
Returns
true if the specified objects are equal; otherwise, false.
Remarks
Implement this method to provide a customized equality comparison for type type_t.
Notes to Implementers
Implementations are required to ensure that if the xtd::collections::generic::iequality_comparer::equals method returns true for two objects x and y, then the value returned by the xtd::collections::generic::iequality_comparer::get_hash_code method for x must equal the value returned for y. The xtd::collections::generic::iequality_comparer::equals method is reflexive, symmetric, and transitive. That is, it returns true if used to compare an object with itself; true for two objects x and y if it is true for y and x; and true for two objects x and z if it is true for x and y and also true for y and z.

◆ get_hash_code()

template<typename type_t >
virtual xtd::size xtd::collections::generic::iequality_comparer< type_t >::get_hash_code ( const type_t &  obj) const
pure virtualnoexcept

Returns a hash code for the specified object.

Parameters
objThe xtd::object for which a hash code is to be returned.
Returns
A hash code for the specified object.
Remarks
Implement this method to provide a customized hash code for type type_t, corresponding to the customized equality comparison provided by the xtd::collections::generic::iequality_comparer::equals method.
Notes to Implementers
Implementations are required to ensure that if the xtd::collections::generic::iequality_comparer::equals method returns true for two objects x and y, then the value returned by the xtd::collections::generic::iequality_comparer::get_hash_code method for x must equal the value returned for y.

The documentation for this class was generated from the following file: