Skip to content

Cache hashCode in Permutation class #329

@cicirello

Description

@cicirello

Summary

Many applications using the Permutation class may not need the hashCode method, but for those that do, such as if they need to maintain a HashSet or a HashMap with Permutation as the key type, recomputing a hashCode if Permutation length is long may create overhead (especially if the Permutations in question have not changed).

Solution

Cache the hashCode the first time the hashCode method is called (similar to what the Java API does for the hashCode of String objects). The cache will need to be invalidated whenever the state of the Permutation changes (not an issue for String objects since they are immutable, so solution is not exactly like that of String).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions