Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-21 Thread Matt Harden
On Fri, Apr 21, 2017 at 12:43 AM Ian Davis wrote: > > > > On Fri, 21 Apr 2017, at 03:31 AM, Ivan Kurnosov wrote: > > @Rob, > > honestly to me they look the same: > > > func IsSorted(data Interface) bool { > n := data.Len() > for i := n - 1; i > 0; i-- { > if

Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-21 Thread David Collier-Brown
Some compilers know that and create a hidden variable (B and C on GCOS, if memory serves) On Thursday, April 20, 2017 at 11:50:39 PM UTC-4, andrey mirtchovski wrote: > > > 297 for i := n - 1; i > 0; i-- { > > "i > 0" is cheaper than "i < n" on some processors :) > > -- You received this

Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-21 Thread Ian Davis
On Fri, 21 Apr 2017, at 03:31 AM, Ivan Kurnosov wrote: > @Rob, > > honestly to me they look the same: > > > func IsSorted(data Interface) bool { > n := data.Len() for i := n - 1; i > ; i-- { if data.Less(i, i-1) { >return false } } return true } > > > func IsSortedForward(data

Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-20 Thread Ivan Kurnosov
Speaking low level - how about memory prefetch algorithms (os, hardware)? Do they work equally good when one iterates backward? On Friday, April 21, 2017 at 3:50:39 PM UTC+12, andrey mirtchovski wrote: > > > 297 for i := n - 1; i > 0; i-- { > > "i > 0" is cheaper than "i < n" on some

Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-20 Thread andrey mirtchovski
> 297 for i := n - 1; i > 0; i-- { "i > 0" is cheaper than "i < n" on some processors :) On Thu, Apr 20, 2017 at 3:14 AM, wrote: > Hi > > At the moment it is implemented as > >295func IsSorted(data Interface) bool { >296n := data.Len() >

Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-20 Thread Ivan Kurnosov
@Rob, honestly to me they look the same: func IsSorted(data Interface) bool { n := data.Len() for i := n - 1; i > 0; i-- { if data.Less(i, i-1) { return false } } return true } func IsSortedForward(data sort.Interface) bool { n := data.Len()

Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-20 Thread Rob Pike
Try it the other way. You'll see it's not so clean. -rob On Thu, Apr 20, 2017 at 7:47 PM, Ian Lance Taylor wrote: > On Thu, Apr 20, 2017 at 2:14 AM, wrote: > > > > At the moment it is implemented as > > > >295 func IsSorted(data Interface) bool { > >

Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-20 Thread Ian Lance Taylor
On Thu, Apr 20, 2017 at 2:14 AM, wrote: > > At the moment it is implemented as > >295 func IsSorted(data Interface) bool { >296 n := data.Len() >297 for i := n - 1; i > 0; i-- { >298 if data.Less(i, i-1) { >299 return false >300 } >301 } >302