mirror of
https://github.com/janet-lang/janet
synced 2024-12-27 17:00:27 +00:00
Merge pull request #628 from yumaikas/master
Switch out `by` to `before?` in sort functions.
This commit is contained in:
commit
c941e5a8f4
@ -756,7 +756,7 @@
|
|||||||
a
|
a
|
||||||
(if (not= (> b a) (> b c)) b c)))
|
(if (not= (> b a) (> b c)) b c)))
|
||||||
|
|
||||||
(defn- sort-help [a lo hi by]
|
(defn- sort-help [a lo hi before?]
|
||||||
(when (< lo hi)
|
(when (< lo hi)
|
||||||
(def pivot
|
(def pivot
|
||||||
(median-of-three (in a hi) (in a lo)
|
(median-of-three (in a hi) (in a lo)
|
||||||
@ -764,8 +764,8 @@
|
|||||||
(var left lo)
|
(var left lo)
|
||||||
(var right hi)
|
(var right hi)
|
||||||
(while true
|
(while true
|
||||||
(while (by (in a left) pivot) (++ left))
|
(while (before? (in a left) pivot) (++ left))
|
||||||
(while (by pivot (in a right)) (-- right))
|
(while (before? pivot (in a right)) (-- right))
|
||||||
(when (<= left right)
|
(when (<= left right)
|
||||||
(def tmp (in a left))
|
(def tmp (in a left))
|
||||||
(set (a left) (in a right))
|
(set (a left) (in a right))
|
||||||
@ -773,14 +773,14 @@
|
|||||||
(++ left)
|
(++ left)
|
||||||
(-- right))
|
(-- right))
|
||||||
(if (>= left right) (break)))
|
(if (>= left right) (break)))
|
||||||
(sort-help a lo right by)
|
(sort-help a lo right before?)
|
||||||
(sort-help a left hi by))
|
(sort-help a left hi before?))
|
||||||
a)
|
a)
|
||||||
|
|
||||||
(defn sort
|
(defn sort
|
||||||
"Sort an array in-place. Uses quick-sort and is not a stable sort."
|
"Sort an array in-place. Uses quick-sort and is not a stable sort."
|
||||||
[a &opt by]
|
[a &opt before?]
|
||||||
(sort-help a 0 (- (length a) 1) (or by <)))
|
(sort-help a 0 (- (length a) 1) (or before? <)))
|
||||||
|
|
||||||
(defn sort-by
|
(defn sort-by
|
||||||
``Returns `ind` sorted by calling
|
``Returns `ind` sorted by calling
|
||||||
@ -790,8 +790,8 @@
|
|||||||
|
|
||||||
(defn sorted
|
(defn sorted
|
||||||
"Returns a new sorted array without modifying the old one."
|
"Returns a new sorted array without modifying the old one."
|
||||||
[ind &opt by]
|
[ind &opt before?]
|
||||||
(sort (array/slice ind) by))
|
(sort (array/slice ind) before?))
|
||||||
|
|
||||||
(defn sorted-by
|
(defn sorted-by
|
||||||
``Returns a new sorted array that compares elements by invoking
|
``Returns a new sorted array that compares elements by invoking
|
||||||
|
Loading…
Reference in New Issue
Block a user