Skip to content

Maintain hash codes incrementally #1

@slburson

Description

@slburson

Currently, all the classes compute their hash codes on demand and then cache them. It would be better to maintain them incrementally, wouldn't it?

I suppose the reason I did it this way is that, except for elements of FHashSet and keys of FHashMap, we don't call hashCode on elements for any other reason. The method might be very expensive, or might even crash, and we don't want to pay the cost of calling it unless and until we know we need the result.

Against that is the fact that the current strategy may cause us to call it many times on the same object, unnecessarily.

Hmm. It does seem that at the very least, FHashSet should maintain its hash code incrementally unconditionally. It's not too much of a stretch to argue that FHashMap should do so also, even though this means calling hashCode on the values, which we don't currently do by default. (The same goes for the linked versions.) For the other classes, perhaps it would be better to wait until hashCode is called on the collection before starting to maintain it incrementally. This still risks redundant computation in some circumstances, but probably won't call hashCode on an object the programmer doesn't want it called on.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions