Curve Hash algorithm

Hi guys,

Does anyone have any idea what would be a good hashing algorithm for the Curve class in RhinoCommon ? Its GetHashCode() is giving me collisions when I try to add a collection of curves to a Hashtable. I also want to clarify that all the curves in the collection will never have reference equality.

Any tips would be great, thanks.

Curve equality is a fuzzy concept. You can have two similar curves which have a wildly different control-point structure. Does that count?

Also, what about two curves which are identical within tolerance. Or do you not care about tolerance equality.

Hi David,

good points, for the hash codes I only care that they dont have reference equality. So basically if two or more variables are not pointing to the same instance in memory, the objects should have distinct hash codes. If say, two curves are equal mathematically the above will still hold true if and only If their memory location is different. I ended up doing a workaround, I created a wrapper struct and as a property, I created a Guid to serve as a hash code. This way I was absolutely sure that I wouldn’t have any collisions.

You can use GCHandle.Alloc with GCHandleType.Weak to get the IntPtr of a reference. That might work.

1 Like

Yes! I was looking in to that option as well. I left the Guid as a byte array for the moment. But I will try with IntPtr as well.