[swift-evolution] Custom equality/hash for Sets
Jacob Bandes-Storch
jtbandes at gmail.com
Thu Feb 18 16:58:22 CST 2016
Would it make sense for the standard library Set to provide variants (or
parallel versions of the same data structure) that take custom hashValue/==
implementations at init time (functions taking in Elements), rather than
relying on Hashable/Comparable protocols?
Use case: I want a set of objects that are compared for equality using ===
rather than ==. This doesn't seem possible today, using Set, without
creating some sort of wrapper object.
This particular case would be analogous to using NSHashTable with
NSPointerFunctionsObjectPointerPersonality. (Maybe all I'm asking for is a
Swiftier API for NSHashTable — including ArrayLiteralConvertible, using
generics instead of UnsafePointer<Void>, etc.)
Similarly, C++'s unordered_map
<http://en.cppreference.com/w/cpp/container/unordered_map> and friends have
template parameters specifying the hash function and equality comparator,
which use std::hash and == by default.
(Apologies if this has been discussed already; I haven't seen it.)
Jacob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160218/7333d198/attachment.html>
More information about the swift-evolution
mailing list