fast-ruby
fast-ruby copied to clipboard
Hash#has_key? vs Set#include?
When selecting a data structure to store a set of unique elements, in which a common operation will be to check if an element is part of that data structure, the a Set comes to mind as the ideal, minimal choice.
One downside of Set is that it's slower than a Hash when checking for present of an element, even though Set's implementation is backed by a Hash.
This PR documents the difference in performance profile between Hash#has_key? and Set#include? to help users that need to check for an association in performance critical paths.