aboutsummaryrefslogtreecommitdiff
path: root/src/sort
AgeCommit message (Collapse)Author
2020-12-09all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTempRuss Cox
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-17sort: fix grammar in updated Less commentzikaeroh
The rewritten comment didn't sound right to my ears. Tweak it to be grammatically correct. Change-Id: Iae7d9f8810fff78cfd964bb3117099bce4479c14 Reviewed-on: https://go-review.googlesource.com/c/go/+/263180 Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Robert Griesemer <gri@golang.org>
2020-10-16sort: update commentsRuss Cox
- Describe requirements on Less more precisely. - Standardize on x for the variable name of the data being sorted (was variously a, p, slice). - Many other minor wording changes. Fixes #41951. Change-Id: Ic9e222a53ec035fcc3b5ddfc7f0eefbe1bb2890d Reviewed-on: https://go-review.googlesource.com/c/go/+/262657 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-10-14sort: document requirements of Less relationalandonovan
Fixes #34915 Change-Id: Ia62ff3b6f198ddcd79e8afc7b4f5514a44f2442c Reviewed-on: https://go-review.googlesource.com/c/go/+/261959 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Akhil Indurti <aindurti@gmail.com> Trust: Alberto Donizetti <alb.donizetti@gmail.com>
2019-05-02sort: simplify bootstrapRuss Cox
We compile package sort as part of the compiler bootstrap, to make sure the compiler uses a consistent sort algorithm no matter what version of Go it is compiled against. (This matters for elements that compare "equal" but are distinguishable.) Package sort was compiled in such a way as to disallow sort.Slice entirely during bootstrap (at least with some compilers), while cmd/internal/obj was compiled in such a way as to make obj.SortSlice available to all compilers, precisely because sort.Slice was not. This is all highly confusing. Simplify by making sort.Slice available all the time. Followup to CL 169137 and #30440 (and also CL 40114 and CL 73951). Change-Id: I127f4e02d6c71392805d256c3a90ef7c51f9ba0c Reviewed-on: https://go-review.googlesource.com/c/go/+/174525 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-27sort, internal/reflectlite: flesh out reflectlite enough for use by sortBrad Fitzpatrick
Now the net package is back to no longer depending on unicode. And lock that in with a test. Fixes #30440 Change-Id: I18b89b02f7d96488783adc07308da990f505affd Reviewed-on: https://go-review.googlesource.com/c/go/+/169137 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-22sort: replace Errorf+FailNow with FatalfIskander Sharipov
Change-Id: I4f8d0178e780b86d1f551b367e2ddac3789be5aa Reviewed-on: https://go-review.googlesource.com/c/go/+/168880 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-01-27sort: change let to let'sGiantsLoveDeathMetal
Trivial typo Change-Id: I3804f365519453bfa19997f55ead34742ac1a9db GitHub-Last-Rev: 0e04e928d05121099b78a2cefc1cb7531f6a7650 GitHub-Pull-Request: golang/go#29930 Reviewed-on: https://go-review.googlesource.com/c/159479 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2018-06-01all: update comment URLs from HTTP to HTTPS, where possibleTim Cooper
Each URL was manually verified to ensure it did not serve up incorrect content. Change-Id: I4dc846227af95a73ee9a3074d0c379ff0fa955df Reviewed-on: https://go-review.googlesource.com/115798 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2018-04-22sort: fix typo in commentTakayoshi Nishida
Change-Id: Ia2c87473d63175db6cb36a21be0769ae9fcb4f8b Reviewed-on: https://go-review.googlesource.com/108695 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-19sort: fix typo, was a mixup between identifiers 'unsorted' and 'data'Neven Sajko
Change-Id: If9ad8ae663f007efe43cc35631713565fa754e93 Reviewed-on: https://go-review.googlesource.com/93237 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-10all: fix non-standard "DO NOT EDIT" comments for generated filesMark Rushakoff
I found files to change with this command: git grep 'DO NOT EDIT' | grep -v 'Code generated .* DO NOT' There are more files that match that grep, but I do not intend on fixing them. Change-Id: I4b474f1c29ca3135560d414785b0dbe0d1a4e52c GitHub-Last-Rev: 65804b02634abd85bf113788b38354d48801241f GitHub-Pull-Request: golang/go#24334 Reviewed-on: https://go-review.googlesource.com/99955 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-10-27sort: split post-Go1.4 code into its own fileRuss Cox
This will let us build the latest sort when bootstrapping the compiler. The compiler depends on the precise tie-breaks used by sort in some cases, and it's easier to bring sort along than require checking every sort call ever added to the compiler. Change-Id: Idc622f89aedbb40d848708c76650fc28779d0c3c Reviewed-on: https://go-review.googlesource.com/73951 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-09-24sort: update main example to use Slice along with SortAgniva De Sarker
This is to let sort.Slice get more prominence since it's the most common use case. Fixes #21989 Change-Id: I0b180cc20256f5f09065b722e191c508c872f4f7 Reviewed-on: https://go-review.googlesource.com/65710 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-08-28sort: add examples for IntsAreSorted, Float64s and Float64sAreSortedKarsten Köhler
Change-Id: Ib4883470bd2271e546daea3156d4a48dd873aaa3 Reviewed-on: https://go-review.googlesource.com/57670 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-08-25sort: fix mix-up between "!less" and "greater" in examplesTom Levy
If Less(a, b) returns true when a is less than b, the correct way to check if a is greater than b is to use Less(b, a). It is wrong to use !Less(a, b) because that checks if a is greater than *or equal to* b. 1. The decreasingDistance function in Example_sortKeys makes this mistake. Fix it. 2. The documentation of multiSorter.Less says it loops along the less functions until it finds a comparison "that is either Less or !Less". This is nonsense, because (Less(a, b) or !Less(a, b)) is always true. Fix the documentation to say that it finds a comparison "that discriminates between the two items (one is less than the other)". The implementation already does this correctly. Change-Id: If52b79f68e4fdb0d1095edf29bdecdf154a61b8d Reviewed-on: https://go-review.googlesource.com/57752 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-08-25sort: fix TestAdversaryTom Levy
There are some major problems with TestAdversary (based on "A Killer Adversary for Quicksort"[1] by M. D. McIlroy). See #21581 for details. Rewrite the test to closely match the version in the paper so it can be verified as correct by virtue of similarity. The only major difference between this new version and the version in the paper is that this version swaps the values directly instead of permuting an array of indices because we don't need to recover the original permutation. This new version also counts the number of calls to Less() and fails the test if there are too many. Fixes #21581. [1]: http://www.cs.dartmouth.edu/~doug/mdmspe.pdf Change-Id: Ia94b5b6d288b8fa3805a5fa27661cebbc5bad9a7 Reviewed-on: https://go-review.googlesource.com/58330 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-07-15sort: add example for StringsTony Walker
Change-Id: I33f0e2362e85287b493d9279d43b760733e2abcb Reviewed-on: https://go-review.googlesource.com/48831 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2017-06-09all: single space after periodBrad Fitzpatrick
Done with grep & interactive search & replace, to double-check replacements. Not many remained after CL 20022. Fixes #18572 Change-Id: Idbe90ba3b584f9b9661d2bbd141607daaadfa41a Reviewed-on: https://go-review.googlesource.com/45270 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2017-06-01sort: clarify comment about not-a-number valuesIan Lance Taylor
Updates #20540 Change-Id: I864008fadd77b0aeb10fe7e7f1ec696516a5add5 Reviewed-on: https://go-review.googlesource.com/44492 Reviewed-by: Robert Griesemer <gri@golang.org>
2017-05-31sort: document NaN behavior for Float64Slice and friendsIan Lance Taylor
Fixes #20540 Change-Id: I440eee02d37b6921613f9ae77875d91eeec48b1e Reviewed-on: https://go-review.googlesource.com/44490 Reviewed-by: Robert Griesemer <gri@golang.org>
2017-02-22sort: new example: Sorting slices with sort.SliceStableKenny Grant
ExampleSliceStable echoes the sort.Slice example, to demonstrate sorting on two fields together preserving order between sorts. Change-Id: I8afc20c0203991bfd57260431eda73913c165355 Reviewed-on: https://go-review.googlesource.com/37196 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-10sort: optimize average calculation in symMerge and doPivot.David R. Jenni
Change code of the form `i + (j-i)/2` to `int(uint(i+j) >> 1)`. The optimized average calculation uses fewer instructions to calculate the average without overflowing at the addition. Analogous to https://golang.org/cl/36332. name old time/op new time/op delta StableString1K-4 49.6µs ± 3% 49.1µs ± 8% ~ (p=0.659 n=16+19) StableInt1K-4 160µs ±10% 148µs ± 5% -7.29% (p=0.000 n=20+16) StableInt1K_Slice-4 139µs ± 4% 136µs ± 3% -2.52% (p=0.000 n=20+16) StableInt64K-4 8.84ms ± 6% 8.57ms ± 5% -3.07% (p=0.001 n=20+19) Stable1e2-4 162µs ±19% 147µs ±16% -8.79% (p=0.002 n=20+20) Stable1e4-4 31.0ms ± 5% 30.6ms ± 5% ~ (p=0.221 n=20+20) Stable1e6-4 6.37s ± 3% 6.27s ± 2% -1.67% (p=0.000 n=19+20) Change-Id: I1cea0bcb9ace8ef7e48b8fab772e41b4b2170da9 Reviewed-on: https://go-review.googlesource.com/36570 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2017-02-06sort: optimize average calculation in binary searchDavid R. Jenni
Use fewer instructions to calculate the average of i and j without overflowing at the addition. Even if both i and j are math.MaxInt{32,64}, the sum fits into a uint{32,64}. Because the sum of i and j is always ≥ 0, the right shift by one does the same as a division by two. The result of the shift operation is at most math.MaxInt{32,64} and fits again into an int{32,64}. name old time/op new time/op delta SearchWrappers-4 153ns ± 3% 143ns ± 6% -6.33% (p=0.000 n=90+100) This calculation is documented in: https://research.googleblog.com/2006/06/extra-extra-read-all-about-it-nearly.html Change-Id: I2be7922afc03b3617fce32e59364606c37a83678 Reviewed-on: https://go-review.googlesource.com/36332 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-12-01sort: add Slice exampleBrad Fitzpatrick
Change-Id: I34ba4eaf1d232b639998ad3bbb0d075dd097722b Reviewed-on: https://go-review.googlesource.com/33763 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dominik Honnef <dominik@honnef.co>
2016-10-05sort: fix a slice benchmark not using the stable variant, add anotherBrad Fitzpatrick
Change-Id: I9783d8023d453a72c4605a308064bef98168bcb8 Reviewed-on: https://go-review.googlesource.com/30360 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-10-03sort: add Slice, SliceStable, and SliceIsSortedBrad Fitzpatrick
Add helpers for sorting slices. Slice sorts slices: sort.Slice(s, func(i, j int) bool { if s[i].Foo != s[j].Foo { return s[i].Foo < s[j].Foo } return s[i].Bar < s[j].Bar }) SliceStable is the same, but does a stable sort. SliceIsSorted reports whether a slice is already sorted. Fixes #16721 Change-Id: I346530af1c5dee148ea9be85946fe08f23ae53e7 Reviewed-on: https://go-review.googlesource.com/27321 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2016-09-17sort: fix search descending order exampleSuyash
Change-Id: I27b82d8c63a06ddf7e148b15853aba24a22a6282 Reviewed-on: https://go-review.googlesource.com/29336 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-09-16sort: add examples for sort.SearchSuyash
This adds examples showing the different ways of using sort.Search. Change-Id: Iaa08b4501691f37908317fdcf2e618fbe9f99ade Reviewed-on: https://go-review.googlesource.com/29131 Reviewed-by: Andrew Gerrand <adg@golang.org> Run-TryBot: Andrew Gerrand <adg@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-09-14sort: cut 140 seconds off race build testsBrad Fitzpatrick
No coverage is gained by running the 1e6 versions of the test over the 1e4 versions. It just adds 140 seconds of race overhead time. Updates #17104 Change-Id: I41408aedae34a8b1a148eebdda20269cdefffba3 Reviewed-on: https://go-review.googlesource.com/29159 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2016-03-25all: delete dead non-test codeDominik Honnef
This change removes a lot of dead code. Some of the code has never been used, not even when it was first commited. The rest shouldn't have survived refactors. This change doesn't remove unused routines helpful for debugging, nor does it remove code that's used in commented out blocks of code that are only unused temporarily. Furthermore, unused constants weren't removed when they were part of a set of constants from specifications. One noteworthy omission from this CL are about 1000 lines of unused code in cmd/fix, 700 lines of which are the typechecker, which hasn't been used ever since the pre-Go 1 fixes have been removed. I wasn't sure if this code should stick around for future uses of cmd/fix or be culled as well. Change-Id: Ib714bc7e487edc11ad23ba1c3222d1fd02e4a549 Reviewed-on: https://go-review.googlesource.com/20926 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-02all: single space after period.Brad Fitzpatrick
The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-02-24all: fix typos and spellingMartin Möhrmann
Change-Id: Icd06d99c42b8299fd931c7da821e1f418684d913 Reviewed-on: https://go-review.googlesource.com/19829 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-02-24sort: fix for nondeterministic less function in quicksort pivotJure Ham
Fixes #14377 Change-Id: I130a6e1b8bc827db44efd0a74e759b894ecc4977 Reviewed-on: https://go-review.googlesource.com/19823 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-02-18sort: Fix typo in stable sort commentMatt Bostock
Fix `reverences`, which I believe should read as `references`. Change-Id: I450efcbeee0f8861a84b209f2e6636764034232a Reviewed-on: https://go-review.googlesource.com/19469 Reviewed-by: Russ Cox <rsc@golang.org>
2015-12-04sort: improve average quicksort performanceRuss Cox
Revert "Revert "sort: improve average quicksort performance"" This reverts commit 30b87bb9aa0c6658830f3d111920e2f366476644. See https://golang.org/cl/15688 for the CL being replayed. Change-Id: I2ba36334003f4971f95a10536adfdd86be9a50de Reviewed-on: https://go-review.googlesource.com/17389 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2015-12-04Revert "sort: improve average quicksort performance"Russ Cox
Broke the build: http://build.golang.org/log/8159de7e0d6f3832da394c310975ddd4c4c74627 (cmd/gofmt TestRewrite) This reverts commit 6f6b2f04b5c342edf70944e60c9c9a30eef5a9eb. Change-Id: Ifd46b0b76c30b0a568521eaaf5ef8968a9549bf5 Reviewed-on: https://go-review.googlesource.com/17383 Reviewed-by: Russ Cox <rsc@golang.org>
2015-12-04sort: improve average quicksort performanceSokolov Yura
- change way of protection from O(N^2) on duplicate values. Previous algorithm does additional comparisons and swaps on every split pass. Changed algorithm does one ordinal quicksort split pass, and if distribution is skewed, then additional pass to separate pivot's duplicates. Changed algorithm could be slower on very ununique slice, but it is still protected from O(N^2). - increase small slice size and do simple shell sort pass to amortize worst case on small slices. Small slice has higher probability to have skewed distribution, so lets sort it with simpler algorithm. benchmark old ns/op new ns/op delta BenchmarkSortString1K 458374 388641 -15.21% BenchmarkSortInt1K 217851 181796 -16.55% BenchmarkSortInt64K 20539264 16730340 -18.54% BenchmarkSort1e2 98668 95554 -3.16% BenchmarkSort1e4 20278500 18316829 -9.67% BenchmarkSort1e6 3215724392 2795999911 -13.05% number of operations: Size: Total: Swap: Less: % % % Sort 100 Avg -5.98% -18.43% -1.90% Sort 100 Max -14.43% -16.02% -4.51% Sort 300 Avg -7.50% -12.76% -5.96% Sort 300 Max -11.29% -9.60% -4.30% Sort 1000 Avg -12.13% -11.65% -12.25% Sort 1000 Max -13.81% -11.77% -11.89% Sort 3000 Avg -14.61% -9.30% -15.86% Sort 3000 Max -15.81% -8.66% -15.19% Sort 10000 Avg -16.10% -8.47% -17.80% Sort 10000 Max -17.13% -7.63% -16.97% Sort 30000 Avg -17.46% -7.56% -19.57% Sort 30000 Max -18.24% -7.62% -17.68% Sort 100000 Avg -18.83% -6.64% -21.33% Sort 100000 Max -19.72% -6.70% -20.96% Sort 300000 Avg -19.61% -6.16% -22.30% Sort 300000 Max -20.69% -6.15% -21.81% Sort 1000000 Avg -20.42% -5.58% -23.31% Sort 1000000 Max -21.54% -5.56% -23.61% Change-Id: I23868e8b52b5841b358cd5403967c9a97871e4d5 Reviewed-on: https://go-review.googlesource.com/15688 Reviewed-by: Russ Cox <rsc@golang.org>
2015-11-18strings: fix period placement in Search doc commentCaleb Spare
Change-Id: Ieba62c0cb668daeb343f72fdd568e46b0b21b7d6 Reviewed-on: https://go-review.googlesource.com/16998 Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-08-17sort: Fix typo in Stable() commentMatt Bostock
Correct 'an' to 'on' in the comment above the Stable() function. Change-Id: I714e38b2d3a79dfd539d5368967d1c6b519cb948 Reviewed-on: https://go-review.googlesource.com/13662 Reviewed-by: Rob Pike <r@golang.org>
2015-02-08sort: fixed small typo in commentsFlorin Patan
There was a small typo in the comment before the Stable function. Change-Id: Ia6fa5272aa7869124a637d2eeda81c4f35ef46c8 Reviewed-on: https://go-review.googlesource.com/4201 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-01-13sort: reduce number of comparisons needed by medianOfThreeMartin Möhrmann
For some cases we can ensure the correct order of elements in two instead of three comparisons. It is unnecessary to compare m0 and m1 again if m2 and m1 are not swapped. benchmark old ns/op new ns/op delta BenchmarkSortString1K 302721 299590 -1.03% BenchmarkSortInt1K 124055 123215 -0.68% BenchmarkSortInt64K 12291522 12203402 -0.72% BenchmarkSort1e2 58027 57111 -1.58% BenchmarkSort1e4 12426805 12341761 -0.68% BenchmarkSort1e6 1966250030 1960557883 -0.29% Change-Id: I2b17ff8dee310ec9ab92a6f569a95932538768a9 Reviewed-on: https://go-review.googlesource.com/2614 Reviewed-by: Robert Griesemer <gri@golang.org>
2015-01-06sort: optimize symMerge performance for blocks with one elementMartin Möhrmann
Use direct binary insertion instead of recursive calls to symMerge when one of the blocks has only one element. benchmark old ns/op new ns/op delta BenchmarkStableString1K 421999 397629 -5.77% BenchmarkStableInt1K 123422 120592 -2.29% BenchmarkStableInt64K 9629094 9620200 -0.09% BenchmarkStable1e2 123089 120209 -2.34% BenchmarkStable1e4 39505228 36870029 -6.67% BenchmarkStable1e6 8196612367 7630840157 -6.90% Change-Id: I49905a909e8595cfa05920ccf9aa00a8f3036110 Reviewed-on: https://go-review.googlesource.com/2219 Reviewed-by: Robert Griesemer <gri@golang.org>
2014-12-23sort: simplify rotate and reduce calls to itMartin Möhrmann
Move the checks for empty rotate changes from the beginning of rotate to the callers. Remove additional variable p used instead of existing m with same value. Remove special casing of equal ranges (i==j) to exit early as no work is saved vs checking (i!=j) and making a single swapRange call if this is false. benchmark old ns/op new ns/op delta BenchmarkStableString1K 417195 425218 +1.92% BenchmarkStableInt1K 126661 124498 -1.71% BenchmarkStableInt64K 10365014 10417438 +0.51% BenchmarkStable1e2 132151 130648 -1.14% BenchmarkStable1e4 42027428 40812649 -2.89% BenchmarkStable1e6 8524772364 8430192391 -1.11% Change-Id: Ia7642e9d31408496970c700f5843d53cc3ebe817 Reviewed-on: https://go-review.googlesource.com/2100 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2014-12-22sort: reduce leaf calls in StableJosh Bleecher Snyder
Move the symMerge recursion stopping condition from the beginning of symMerge to the callers. This halves the number of calls to symMerge while running 'go test sort'. benchmark old ns/op new ns/op delta BenchmarkStable1e6 8358117060 7954143849 -4.83% BenchmarkStable1e4 40116117 38583285 -3.82% BenchmarkStableInt1K 119150 115182 -3.33% BenchmarkStableInt64K 9799845 9515475 -2.90% BenchmarkStableString1K 388901 393516 +1.19% BenchmarkStable1e2 124917 123618 -1.04% Change-Id: I7ba2ca277f213b076fe6830e1139edb47ac53800 Reviewed-on: https://go-review.googlesource.com/1820 Reviewed-by: Robert Griesemer <gri@golang.org>
2014-12-19sort: deduplicate inner loop of StableJosh Bleecher Snyder
benchmark old ns/op new ns/op delta BenchmarkStableInt1K 117212 116287 -0.79% BenchmarkStableInt64K 9632002 9587872 -0.46% BenchmarkStable1e4 40044309 39865644 -0.45% BenchmarkStable1e2 126985 126456 -0.42% BenchmarkStableString1K 389774 391052 +0.33% BenchmarkStable1e6 8183202516 8157693442 -0.31% Change-Id: I14e518ad49ecce3d1fc2b056e1acd5e5a2de8144 Reviewed-on: https://go-review.googlesource.com/1821 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.