[swift-evolution] [RFC] New collections model: collections advance indices

Trent Nadeau tanadeau at gmail.com
Tue Mar 1 20:55:27 CST 2016


Why is the protocol for iterators called IteratorProtocol instead of
Iterator or Iterable? If that is/was discussed elsewhere, I apologize, but
I don't remember seeing that particular name before. Is that new to this
proposal?

On Tue, Mar 1, 2016 at 9:04 PM, Dmitri Gribenko via swift-evolution <
swift-evolution at swift.org> wrote:

> Hi,
>
> We would like to propose a major change to how collection indices
> work.  The standard library team has discussed this idea internally
> and we wrote a prototype.  Now we think it is a viable direction to
> consider, and we are bringing it for wider public discussion.
>
> I'm pasting the first section of the proposal below to give you a
> general idea about this change, but please read the proposal to
> understand the full details.
>
> You can find the most up to date version of the proposal at
>
> https://github.com/gribozavr/swift-evolution/blob/new-collections/proposals/NNNN-collections-move-indices.md
>
> Permalink:
> https://github.com/gribozavr/swift-evolution/blob/87df19a9a9d73e64a2a966b807440216a608b8ad/proposals/NNNN-collections-move-indices.md
>
> Dmitri
>
> ## Introduction
>
> We are proposing a new model for collections, where indices can only be
> advanced forward or backward by the corresponding collection instance.
> Indices become opaque tokens representing collection positions, that can
> be produced and consumed by collection APIs.  This allows us to reduce
> the amount of data stored in indices to the bare minimum.
>
> Compared to the current state, the new scheme simplifies implementation
> of non-trivial indices, and fixes concurrency issues in `Set` and
> `Dictionary` indices.  It also allows us to eliminate reference-counted
> stored properties from most indices, including non-trivial ones, like
> `Set.Index` and `Dictionary.Index`, creating more optimizable code.
>
> Out of scope for this proposal:
>
> * Expanding the set of concrete collections provided by the standard
>   library.
>
> * Expanding the set of collection protocols to provide functionality
>   beyond what is already provided (for example, protocols for sorted
>   collections, queues etc.)  Discussing how other concrete collections
>   fit into the current protocol hierarchy is in scope, though.
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>



-- 
Trent Nadeau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160301/36abdb90/attachment.html>


More information about the swift-evolution mailing list