You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A weak Set and a weak-keyed (or weak-valued) Dictionary are often-requested data structures that aren't easy to implement. It's especially difficult to do it correctly in terms of the existing Set and Dictionary -- most attempts end up accidentally changing the identity of keys already in a hash table, which violates invariants and leads to runtime errors.
This package would be a good place to host a set of weak collection implementations.
While the implementation isn't entirely trivial, I expect this will be mostly an API design challenge. Some notes:
These would work best if they came with their own hash table implementation whose lookup etc. operations are aware of the fact that keys/values could disappear at any moment, and are able to update the table accordingly.
Deallocated keys work like tombstones.
The Element, Key and/or Value types would be constrained to AnyObject. We can probably still allow custom Hashable implementations, as long as the hash table operations are aware of niled out entries. The tradeoff here is that requiring Hashable will make developers do more work by having to manually implement it, even if they only want to use object identity.
Ideally lookup operations would be able to incrementally update the table by getting rid of obsolete entries they encounter. A mutating lookup would probably preclude the use of these types in concurrent contexts. This is fine -- these are typically used for caches local to a particular actor.
These types probably won't be able to conform to Collection as their count can change at any point. This is fine -- they shouldn't even provide a count of live entries.
The types may or may not implement value semantics (depending on whichever choice makes most sense). This is fine.
The text was updated successfully, but these errors were encountered:
A weak
Set
and a weak-keyed (or weak-valued)Dictionary
are often-requested data structures that aren't easy to implement. It's especially difficult to do it correctly in terms of the existingSet
andDictionary
-- most attempts end up accidentally changing the identity of keys already in a hash table, which violates invariants and leads to runtime errors.This package would be a good place to host a set of weak collection implementations.
While the implementation isn't entirely trivial, I expect this will be mostly an API design challenge. Some notes:
Element
,Key
and/orValue
types would be constrained toAnyObject
. We can probably still allow customHashable
implementations, as long as the hash table operations are aware ofnil
ed out entries. The tradeoff here is that requiringHashable
will make developers do more work by having to manually implement it, even if they only want to use object identity.Collection
as theircount
can change at any point. This is fine -- they shouldn't even provide acount
of live entries.The text was updated successfully, but these errors were encountered: