[swift-evolution] Dictionary Enhancements

David Waite david at alkaline-solutions.com
Sat Feb 18 01:20:38 CST 2017


> On Feb 16, 2017, at 5:26 PM, Ben Cohen via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
> Hi swift-evolution,
> 
> Following up on Ted’s post regarding the opening up of stage 2, I’m starting a thread to discuss improvements to the Dictionary type.
> 
> Here is a list of commonly requested changes/enhancements to Dictionary, all of which would probably be appropriate to put together into a single evolution proposal:
> 
<snip>
> Add a defaulting subscript get (e.g. counts[key, default: 0] += 1 or grouped(key, default:[]].append(value)).
Interesting, most of my scenarios aren’t one line subscript mutations like this, so I have been happy with counts[key] ?? 0, grouped(key) ?? [], etc.

> Add capacity property and reserveCapacity() method.
would CoW copies also have the same reserved capacity? One way I could hypothetically copy around dictionaries that are using significantly more memory than I suspected, the other way algorithms would be quite confusing as an assignment to a variable might cause the capacity to revert.
 
In terms of additional features, I have needed to group by value before, e.g. turn from K->V to V -> [K], which isn’t a simple reduce statement.

-DW
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170218/b3aed57f/attachment.html>


More information about the swift-evolution mailing list