Well, from a practical perspective, Rust does the same thing as Java, where HashSet<T> is implemented as HashMap<T, ()>, but since the unit type () is a zero sized type, it takes up no memory, and any code that would handle it is optimized out, leading to an implementation as efficient as a handcrafted one.
View all comments
Show parent comment
8
u/kazagistar Oct 23 '17
Well, from a practical perspective, Rust does the same thing as Java, where
HashSet<T>is implemented asHashMap<T, ()>, but since the unit type()is a zero sized type, it takes up no memory, and any code that would handle it is optimized out, leading to an implementation as efficient as a handcrafted one.