mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
Removing Sort as a module name
This commit is contained in:
parent
1daf9f0db0
commit
8d20bb90df
@ -1,4 +1,4 @@
|
||||
(defmodule Sort
|
||||
(defmodule Array
|
||||
(doc sort! "Perform an in-place heapsort of a given array.")
|
||||
(defn sort! [arr]
|
||||
(HeapSort.sort! arr))
|
||||
@ -11,17 +11,3 @@
|
||||
(defn sort [arr]
|
||||
(HeapSort.sort arr))
|
||||
)
|
||||
|
||||
(defmodule Array
|
||||
(doc sort! "Perform an in-place heapsort of a given array.")
|
||||
(defn sort! [arr]
|
||||
(Sort.sort! arr))
|
||||
|
||||
(doc sorted "Perform a heapsort in a new copy of given array.")
|
||||
(defn sorted [arr]
|
||||
(Sort.sorted arr))
|
||||
|
||||
(doc sort "Perform an in-place heapsort of a given owned array.")
|
||||
(defn sort [arr]
|
||||
(Sort.sort arr))
|
||||
)
|
||||
|
@ -1,6 +1,6 @@
|
||||
(use Int)
|
||||
(use Double)
|
||||
(use Sort)
|
||||
(use Array)
|
||||
|
||||
(defmodule Statistics
|
||||
(deftype Summary [
|
||||
@ -50,7 +50,7 @@
|
||||
(doc median "Compute the median of the samples data.")
|
||||
(defn median [data]
|
||||
(let [n (Array.length data)
|
||||
sorted (Sort.sorted data)]
|
||||
sorted (Array.sorted data)]
|
||||
(cond (= n 0) 0.0
|
||||
(= (mod n 2) 1) @(Array.nth data (/ n 2))
|
||||
(let [mid (/ n 2)] ; else
|
||||
@ -61,7 +61,7 @@
|
||||
(doc low-median "Compute the low median of the samples data.")
|
||||
(defn low-median [data]
|
||||
(let [n (Array.length data)
|
||||
sorted (Sort.sorted data)]
|
||||
sorted (Array.sorted data)]
|
||||
(cond (= n 0) 0.0
|
||||
(= (mod n 2) 1) @(Array.nth data (/ n 2))
|
||||
@(Array.nth data (dec (/ n 2)))))) ; else
|
||||
@ -69,7 +69,7 @@
|
||||
(doc high-median "Compute the high median of the samples data.")
|
||||
(defn high-median [data]
|
||||
(let [n (Array.length data)
|
||||
sorted (Sort.sorted data)]
|
||||
sorted (Array.sorted data)]
|
||||
(if (= n 0)
|
||||
0.0
|
||||
@(Array.nth data (/ n 2)))))
|
||||
@ -77,7 +77,7 @@
|
||||
(doc grouped-median "Compute the grouped median of the samples data.")
|
||||
(defn grouped-median [data interval]
|
||||
(let [n (Array.length data)
|
||||
sorted (Sort.sorted data)]
|
||||
sorted (Array.sorted data)]
|
||||
(cond (= n 0) 0.0
|
||||
(= n 1) @(Array.nth data 0)
|
||||
(let [x @(Array.nth data (/ n 2)) ; else
|
||||
@ -145,7 +145,7 @@
|
||||
|
||||
(doc quartiles "Compute the quartiles of the samples data.")
|
||||
(defn quartiles [data]
|
||||
(let [tmp (Sort.sorted data)
|
||||
(let [tmp (Array.sorted data)
|
||||
first 25.0
|
||||
second 50.0
|
||||
third 75.0
|
||||
@ -161,7 +161,7 @@
|
||||
|
||||
(hidden winsorize)
|
||||
(defn winsorize [samples pct]
|
||||
(let [tmp &(Sort.sorted samples)
|
||||
(let [tmp &(Array.sorted samples)
|
||||
lo (Statistics.percentile-of-sorted tmp pct)
|
||||
hi (Statistics.percentile-of-sorted tmp (Double.- 100.0 pct))]
|
||||
(do
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,5 +1,4 @@
|
||||
(use Array)
|
||||
(use Sort)
|
||||
(Project.no-echo)
|
||||
|
||||
(deftype Age [x Int])
|
||||
@ -14,7 +13,7 @@
|
||||
(Int.< @(Age.x a) @(Age.x b))))
|
||||
|
||||
(defn main []
|
||||
(let-do [ints (Sort.sort [10 3 75 40])
|
||||
ages (Sort.sort [(Age.init 10) (Age.init 3) (Age.init 75) (Age.init 40)])]
|
||||
(let-do [ints (Array.sort [10 3 75 40])
|
||||
ages (Array.sort [(Age.init 10) (Age.init 3) (Age.init 75) (Age.init 40)])]
|
||||
(IO.println &(Array.str &ints))
|
||||
(IO.println &(Array.str &ages))))
|
||||
|
@ -1,5 +1,6 @@
|
||||
(load "Test.carp")
|
||||
|
||||
(use Array)
|
||||
(use IO)
|
||||
(use Int)
|
||||
(use Float)
|
||||
@ -7,7 +8,6 @@
|
||||
(use Array)
|
||||
(use System)
|
||||
(use Char)
|
||||
(use Sort)
|
||||
(use Test)
|
||||
|
||||
(Debug.sanitize-addresses)
|
||||
@ -287,12 +287,12 @@
|
||||
;; (Array.length b))))
|
||||
;; (defn array-sort-1 []
|
||||
;; (let [xs [[0 0] [0 0 0] [0 0 0 0] [0]]
|
||||
;; ys (Sort.sort xs)]
|
||||
;; ys (Array.sort xs)]
|
||||
;; (assert (= &[[0] [0 0] [0 0 0] [0 0 0 0]] &ys))))
|
||||
|
||||
(defn array-sort-2 []
|
||||
(let [xs [5 2 4 3 1]
|
||||
ys (Sort.sort xs)]
|
||||
ys (Array.sort xs)]
|
||||
(assert (= &[1 2 3 4 5] &ys))))
|
||||
|
||||
(defn f [] @"Hello")
|
||||
|
@ -1,4 +1,4 @@
|
||||
(use Sort)
|
||||
(use Array)
|
||||
|
||||
(load "Test.carp")
|
||||
(use Test)
|
||||
@ -7,95 +7,95 @@
|
||||
(with-test test
|
||||
(let-do [arr [1 3 4 2 6 1]
|
||||
exp [1 1 2 3 4 6]]
|
||||
(Sort.sort! &arr)
|
||||
(Array.sort! &arr)
|
||||
(assert-equal test
|
||||
&exp
|
||||
&arr
|
||||
"Sort.sort! works with integers"))
|
||||
"Array.sort! works with integers"))
|
||||
|
||||
(let-do [arr [1 3 4 2 6 1]
|
||||
exp [1 1 2 3 4 6]
|
||||
res (Sort.sorted &arr)]
|
||||
res (Array.sorted &arr)]
|
||||
(assert-equal test
|
||||
&exp
|
||||
&res
|
||||
"Sort.sorted works with integers"))
|
||||
"Array.sorted works with integers"))
|
||||
|
||||
(let-do [res (Sort.sort [1 3 4 2 6 1])
|
||||
(let-do [res (Array.sort [1 3 4 2 6 1])
|
||||
exp [1 1 2 3 4 6]]
|
||||
(assert-equal test
|
||||
&exp
|
||||
&res
|
||||
"Sort.sort works with integers"))
|
||||
"Array.sort works with integers"))
|
||||
|
||||
(let-do [arr [1.0 0.8 12.4 3.2]
|
||||
exp [0.8 1.0 3.2 12.4]]
|
||||
(Sort.sort! &arr)
|
||||
(Array.sort! &arr)
|
||||
(assert-equal test
|
||||
&exp
|
||||
&arr
|
||||
"Sort.sort! works with floats"))
|
||||
"Array.sort! works with floats"))
|
||||
|
||||
(let-do [arr [1.0 0.8 12.4 3.2]
|
||||
exp [0.8 1.0 3.2 12.4]
|
||||
res (Sort.sorted &arr)]
|
||||
res (Array.sorted &arr)]
|
||||
(assert-equal test
|
||||
&exp
|
||||
&res
|
||||
"Sort.sorted works with floats"))
|
||||
"Array.sorted works with floats"))
|
||||
|
||||
(let-do [res (Sort.sort [1.0 0.8 12.4 3.2])
|
||||
(let-do [res (Array.sort [1.0 0.8 12.4 3.2])
|
||||
exp [0.8 1.0 3.2 12.4]]
|
||||
(assert-equal test
|
||||
&exp
|
||||
&res
|
||||
"Sort.sort works with floats"))
|
||||
"Array.sort works with floats"))
|
||||
|
||||
(let-do [arr [@"aaac" @"aaaa" @"aaab" @"aaad"]
|
||||
exp [@"aaaa" @"aaab" @"aaac" @"aaad"]]
|
||||
(Sort.sort! &arr)
|
||||
(Array.sort! &arr)
|
||||
(assert-equal test
|
||||
&exp
|
||||
&arr
|
||||
"Sort.sort! works with strings"))
|
||||
"Array.sort! works with strings"))
|
||||
|
||||
(let-do [arr [@"aaac" @"aaaa" @"aaab" @"aaad"]
|
||||
exp [@"aaaa" @"aaab" @"aaac" @"aaad"]
|
||||
res (Sort.sorted &arr)]
|
||||
res (Array.sorted &arr)]
|
||||
(assert-equal test
|
||||
&exp
|
||||
&res
|
||||
"Sort.sorted works with strings"))
|
||||
"Array.sorted works with strings"))
|
||||
|
||||
(let-do [res (Sort.sort [@"aaac" @"aaaa" @"aaab" @"aaad"])
|
||||
(let-do [res (Array.sort [@"aaac" @"aaaa" @"aaab" @"aaad"])
|
||||
exp [@"aaaa" @"aaab" @"aaac" @"aaad"]]
|
||||
(assert-equal test
|
||||
&exp
|
||||
&res
|
||||
"Sort.sort works with strings"))
|
||||
"Array.sort works with strings"))
|
||||
|
||||
(let-do [arr [\d \a \c \b]
|
||||
exp [\a \b \c \d]]
|
||||
(Sort.sort! &arr)
|
||||
(Array.sort! &arr)
|
||||
(assert-equal test
|
||||
&exp
|
||||
&arr
|
||||
"Sort.sort! works with chars"))
|
||||
"Array.sort! works with chars"))
|
||||
|
||||
(let-do [arr [\d \a \c \b]
|
||||
exp [\a \b \c \d]
|
||||
res (Sort.sorted &arr)]
|
||||
res (Array.sorted &arr)]
|
||||
(assert-equal test
|
||||
&exp
|
||||
&res
|
||||
"Sort.sorted works with chars"))
|
||||
"Array.sorted works with chars"))
|
||||
|
||||
(let-do [res (Sort.sort [\d \a \c \b])
|
||||
(let-do [res (Array.sort [\d \a \c \b])
|
||||
exp [\a \b \c \d]]
|
||||
(assert-equal test
|
||||
&exp
|
||||
&res
|
||||
"Sort.sort works with chars"))
|
||||
"Array.sort works with chars"))
|
||||
|
||||
(print-test-results test)))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user