Re: [swift-evolution] [Proposal] Add .order() family of methods to Collection

2016-04-11 Thread Dave Abrahams via swift-evolution
on Mon Apr 11 2016, Taras Zakharko wrote: > Hi, > > I think it depends on how expensive the indexed access is on the collection. I > use it primarily on arrays, where self[i] essentially boils down to a pointer > dereference, so I expect the generated code to be very efficient. Your version > m

Re: [swift-evolution] [Proposal] Add .order() family of methods to Collection

2016-04-11 Thread Milos Rankovic via swift-evolution
> On 11 Apr 2016, at 20:47, Taras Zakharko > wrote: > > the question is what is faster: {self[0] < self[1]} or {$1.0 < $1.1} Yes, you are right that this is in fact not obvious! I’ve just measured and, though my implementation is faster, it’s advantage only grows

Re: [swift-evolution] [Proposal] Add .order() family of methods to Collection

2016-04-11 Thread Milos Rankovic via swift-evolution
Hi Taras, > On 11 Apr 2016, at 19:38, Taras Zakharko > wrote: > > Your version might be faster for collection with expensive element access, > but it should be slower for arrays and the like, as it involves additional > intermediate structure allocations and copie

Re: [swift-evolution] [Proposal] Add .order() family of methods to Collection

2016-04-11 Thread Taras Zakharko via swift-evolution
Hi, I think it depends on how expensive the indexed access is on the collection. I use it primarily on arrays, where self[i] essentially boils down to a pointer dereference, so I expect the generated code to be very efficient. Your version might be faster for collection with expensive element

Re: [swift-evolution] [Proposal] Add .order() family of methods to Collection

2016-04-11 Thread Milos Rankovic via swift-evolution
Hi Taras, > On 11 Apr 2016, at 08:48, Taras Zakharko via swift-evolution > wrote: > > The implementation should be fairly straightforward. E.g. here is an > extension method I use: > > extension CollectionType { > func order(@noescape isOrderedBefore: (Self.Generator.Element, > Self.Gene

[swift-evolution] [Proposal] Add .order() family of methods to Collection

2016-04-11 Thread Taras Zakharko via swift-evolution
Swift standard library already offers a useful set of sort() functions. However, it is also often useful to know how the collection should be rearranged in order to become sorted. For example, R defines the order() function which returns a permutation of collection indexes which rearrange the c