swift-collections icon indicating copy to clipboard operation
swift-collections copied to clipboard

Consider adding a Concurrent Dictionary (HashMap)

Open fwgreen opened this issue 4 years ago • 1 comments

This is a major go to in Java and it would be nice to have something similar here. It's safe to assume this would be for the distant future after Swift's concurrency and memory management stories are complete.

fwgreen avatar Dec 07 '21 02:12 fwgreen

Agreed.

Given that we have swift-atomics, this would be technically possible (if a bit painful) to implement right now, although there are some significant API design questions/issues that need to be resolved. (E.g., what constraints would such a type put on its Key/Value types? Do we need to constrain their memory layout in some way? Do they need to conform to AtomicValue in addition to Sendable?)

Similar to a weak dictionary (#2, which is in a sense just a narrow special case of the general concurrent dictionary), it is unlikely that a concurrent dictionary would be able to provide value semantics, or to conform to Collection.

Concurrent data structures feel different enough from regular collection types that they may not be a great fit here -- it may make sense to create a new package that is dedicated to them.

lorentey avatar Dec 09 '21 00:12 lorentey