Skip to content

Commit 67b2e2a

Browse files
committed
perf improvement in sorted-numbers?
sorted-numbers? is called once at the beginning of the permutations function in order to determine which version of the permutations algorithm to use -- a more efficient algorithm can be chosen if the numbers are already sorted. Since this function is only called once, improving its performance will have a negligible effect on the overall performance of permutations. But this is an improvement, so why not?
1 parent efb4878 commit 67b2e2a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/main/clojure/clojure/math/combinatorics.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ In prior versions of the combinatorics library, there were two similar functions
172172

173173
(defn- sorted-numbers?
174174
"Returns true iff s is a sequence of numbers in non-decreasing order"
175-
[s]
175+
[s]
176176
(and (every? number? s)
177-
(every? (partial apply <=) (partition 2 1 s))))
177+
(or (empty? s) (apply <= s))))
178178

179179
(defn- multi-perm
180180
"Handles the case when you want the permutations of a list with duplicate items."

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy