Returns a set backed by map: its members are the map's keys, iterated, compared, hashed and
printed as the map orders and compares its keys.
The set is live in both directions. add(member) calls map.getOrInsert(member, true), so the
map's key rules, access order and maxSize eviction apply; a present member is kept and its
value is not written. addAll returns true when some element was absent (map.has) just
before its own add, so it calls the map twice per element. Iteration, cursor, forEach and
every removal go through map.keySet(), so the set iterates live or fails fast as that key set
does. Changes made directly to the map show through the set, and the set's size and
revision are the map's. Writing a value of a present key leaves membership unchanged.
Errors of the set's own argument checks name SetFromMap.<method>; errors raised by the map
keep the map's name, and iteration errors keep the key set's name.
Time: O(1), or the map's isEmpty cost for a range view of a sorted map (O(log n)); each
operation of the returned set costs what the matching map or key set operation costs.
TypeError when map is not a map from this library.
Throws
IllegalArgumentError when map is not empty.
Example
// A set that keeps the 100 most recently added members. constrecent = newSetFromMap( newLinkedHashMap<string, boolean>({ accessOrder:true, maxSize:100 }), ) recent.add('a').add('b').add('a') // re-adding 'a' makes it the most recent member recent.toArray() // ['b', 'a']
Returns a set backed by
map: its members are the map's keys, iterated, compared, hashed and printed as the map orders and compares its keys.The set is live in both directions.
add(member)callsmap.getOrInsert(member, true), so the map's key rules, access order andmaxSizeeviction apply; a present member is kept and its value is not written.addAllreturnstruewhen some element was absent (map.has) just before its own add, so it calls the map twice per element. Iteration,cursor,forEachand every removal go throughmap.keySet(), so the set iterates live or fails fast as that key set does. Changes made directly to the map show through the set, and the set'ssizeandrevisionare the map's. Writing a value of a present key leaves membership unchanged.Errors of the set's own argument checks name
SetFromMap.<method>; errors raised by the map keep the map's name, and iteration errors keep the key set's name.Time: O(1), or the map's
isEmptycost for a range view of a sorted map (O(log n)); each operation of the returned set costs what the matching map or key set operation costs.