jsakamoto / ipaddressrange

.NET Class Library for range of IP address, both IPv4 and IPv6.
Mozilla Public License 2.0
368 stars 71 forks source link

GetHashCode and Equals methods are now overridden in IPAddressRange #54

Closed DNikitenko closed 5 years ago

DNikitenko commented 5 years ago

It would be useful to override GetHashCode method for the IPAddressRange, so that e.g. it can be used as a key in dictionary.

jsakamoto commented 5 years ago

Thank you for your contribution!

I'll merge this PR, however, I'm considering well before merge, for example, consider more clerverly hash algorithm.

DNikitenko commented 5 years ago

Sure, there is an effective built-in implementation for anonymous types, so I could just write return new {Begin, End}.GetHashCode();. Examples can be found here: https://codingsight.com/the-origin-of-gethashcode-in-net/

jsakamoto commented 5 years ago

@DNikitenko It sounds good!

However, that code generate an object in heap each GetHashCode() invoking, doesn't it?
It will be a reason of GC (Garbage Collection).

By the way, I found a feature of Visual Studio 2019 that generate GetHashCode() implementation.

movie-001

How do you think about this?

jsakamoto commented 5 years ago

@DNikitenko Okay, I'll merge this pull request. And after does it, I'll change the implementation of the "GetHashCode()" to what Visual Studio generated.

I'll also implement IEquatable<T> for good performance.

Anyway, thank you for your contributions! 👍