Skip to main content
added 11 characters in body
Source Link

Update:

This is basically the equality checker that fulfills my requirements (but again, I don't need an equality comparer, I need a hash equality-comparer)

This is basically the equality checker that fulfills my requirements (but again, I don't need an equality comparer, I need a hash equality-comparer)

Update:

This is basically the equality checker that fulfills my requirements (but again, I don't need an equality comparer, I need a hash equality-comparer)

deleted 83 characters in body
Source Link

Note that this EqualityComparer is a private class and is only meant to serve the purpose of this specific HashSet which is not exposed at all.
In fact I don't also really care about the Equals, but rather about the GetHashCode, so I know whether an object with my specs have already been added to a HashSet. What can happen if I keep the Equals unimplemented? Does HashSet ever call it?

Note that this EqualityComparer is a private class and is only meant to serve the purpose of this specific HashSet which is not exposed at all.
In fact I don't also really care about the Equals, but rather about the GetHashCode, so I know whether an object with my specs have already been added to a HashSet. What can happen if I keep the Equals unimplemented? Does HashSet ever call it?

Note that this EqualityComparer is a private class and is only meant to serve the purpose of this specific HashSet which is not exposed at all.
In fact I don't also really care about the Equals, but rather about the GetHashCode, so I know whether an object with my specs have already been added to a HashSet.

added 65 characters in body
Source Link
public override bool Equals(ITrackableObjectData x, ITrackableObjectData y)
{
  if (x == y) return true; //ref eq.
  else if (x == null)
    return y == null;
  else if (y == null)
    return false;
  else if (x.TypeName != y.TypeName)
    return false;
  else
  {
    if (x.Id == null)
      return y.Id == null;
    else if (y.Id == null)
      return false;
    else
    {
      int xId = x.Id.GetHashCode(),
          yId = y.Id.GetHashCode();
      if (xId == 0 || yId == 0)
        return x.Equals(y); //use default eq.
      else
        return xId == yId;
    }
  }
}
public override bool Equals(ITrackableObjectData x, ITrackableObjectData y)
{
  if (x == null)
    return y == null;
  else if (y == null)
    return false;
  else if (x.TypeName != y.TypeName)
    return false;
  else
  {
    if (x.Id == null)
      return y.Id == null;
    else if (y.Id == null)
      return false;
    else
    {
      int xId = x.Id.GetHashCode(),
          yId = y.Id.GetHashCode();
      if (xId == 0 || yId == 0)
        return x.Equals(y);
      else
        return xId == yId;
    }
  }
}
public override bool Equals(ITrackableObjectData x, ITrackableObjectData y)
{
  if (x == y) return true; //ref eq.
  else if (x == null)
    return y == null;
  else if (y == null)
    return false;
  else if (x.TypeName != y.TypeName)
    return false;
  else
  {
    if (x.Id == null)
      return y.Id == null;
    else if (y.Id == null)
      return false;
    else
    {
      int xId = x.Id.GetHashCode(),
          yId = y.Id.GetHashCode();
      if (xId == 0 || yId == 0)
        return x.Equals(y); //use default eq.
      else
        return xId == yId;
    }
  }
}
added 44 characters in body
Source Link
Loading
edited body
Source Link
Loading
added 125 characters in body
Source Link
Loading
added 822 characters in body
Source Link
Loading
Tweeted twitter.com/StackCodeReview/status/871852406673465344
fixed missing tick
Source Link
t3chb0t
  • 44.7k
  • 9
  • 85
  • 191
Loading
added 164 characters in body
Source Link
Loading
added 164 characters in body
Source Link
Loading
Source Link
Loading