[swift-evolution] Dictionary Enhancements

Ben Cohen ben_cohen at apple.com
Thu Feb 16 19:45:54 CST 2017


> On Feb 16, 2017, at 5:38 PM, Slava Pestov <spestov at apple.com> wrote:
> 
> 
>> On Feb 16, 2017, at 5:32 PM, David Sweeris via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> 
>>> On Feb 16, 2017, at 5:17 PM, Ben Cohen <ben_cohen at apple.com <mailto:ben_cohen at apple.com>> wrote:
>>> 
>>> The win with mapping only the values is that the underlying hash table can retain the same physical layout, just with different values in the slots, so it can be done faster.
>> 
>> Only if the mapped dictionary’s values are the same type (or at least the same size) as in the original dictionary, right? Would the proposed function allow you to mapValues from a [K:V] to a [K:T]?
> 
> In both cases the key/bucket structure would be the same, I believe.
> 

Right. Values could be different types, you can still reuse the layout i.e. allocate the same element-count buffer (even if the size of the element differs), then put the pairs in the same places they were per the keys, without going through the whole process of computing hashes, resolving collisions etc.

> Slava
> 
>> 
>> - Dave Sweeris
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170216/82dd75df/attachment.html>


More information about the swift-evolution mailing list