aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-04-27 19:53:22 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-04-27 19:53:22 -0400
commitb824fecc3fc66196f767be5c4c70989443e4b5ff (patch)
tree708abaf6f56f06e867122d28dc931ac4d047be4b /src
parent3a22f8cb04d2556f18fcfaa0d7af0981537017b2 (diff)
Fast exit for Grade with 2 or fewer elements; always enable counting sort otherwise
Diffstat (limited to 'src')
-rw-r--r--src/r.bqn48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/r.bqn b/src/r.bqn
index c41d48e7..e35564f8 100644
--- a/src/r.bqn
+++ b/src/r.bqn
@@ -140,32 +140,32 @@ Cmp ← +○IsArray◶⟨
_grade ← {
gt ← 𝕗
- cmps ← {𝕏˜}⌜⍟𝕗⟨≤,Cmp≤0˙,Cmp0,Cmp⟩
- GetLE ← {
- m←1-1=𝕨 ⋄ a←0<0+´IsArray⌜𝕩
- 𝕨 {(𝕏 _getCellCmp 𝕨)≤0˙}⍟m 𝕩{𝕏○(⊑⟜𝕗)} (a+2×m)⊑cmps
- }
- {
+ cmps ← {𝕏˜}⌜⍟𝕗⟨Cmp,Cmp0,Cmp≤0˙,≤⟩
+ 0 Fill {
"⍋𝕩: 𝕩 must have rank at least 1" ! 1≤=𝕩
l←≠𝕩
- m←1×´1 Cell 𝕩
- 𝕩↩⥊𝕩
- Merge ← { # Merge sort
- le←m GetLE 𝕩
- B←l⊸≤◶⊢‿l
- (↕l){
- i←-d←𝕨 ⋄ j←ei←ej←0
- e←3 ⋄ G←LE○(⊑⟜(m⊸×⌜⍟(1-m=1)𝕩)) ⋄ c←⟨1-G,0,1,2⟩
- s←(8≤d)⊑⟨+,{(𝕩-1){𝕩⋄e↩2⋄j↩i⋄i↩𝕩}⍟G⍟(1-e)𝕩}⟩
- N←{i↩d+𝕨⋄ej↩B d+ei↩B j↩d+𝕩⋄e↩l≤j⋄S ei⋄i R j}
- R←{𝕨e◶c𝕩}◶{e+↩2×ei=i↩1+𝕨⋄𝕨}‿{e+↩ej=j↩1+𝕩⋄𝕩}‿N
- {(i R j)⊑𝕩}⟜𝕩⌜𝕩
- }´(2⋆ni-1+⊢)⌜↕ni←⌈2 Log l+l=0
- }
- # Counting sort for small-range ints
- bl←bu←0 ⋄ Count←{GroupLen⊸GroupOrd (gt⊑⟨-⟜bl,bu⊸-⟩)⌜𝕩}
- sr←{((bu↩⌈´𝕩)-bl↩⌊´𝕩)≤2×l}∘𝕩⍟⊢((m=1)×32<l)◶0‿(1×´Int⌜)𝕩
- 0 Fill sr◶Merge‿Count 𝕩
+ (2≤l)◶⟨↕∘l,{
+ m1←1=m←1×´1 Cell 𝕩
+ 𝕩↩⥊𝕩
+ a0←1⋄ts←0⋄{a0×↩1≤𝕩⋄ts+↩𝕩}∘Type⌜𝕩
+ cs←a0+2×m1
+ Merge ← { # Merge sort
+ le ← m {(𝕏 _getCellCmp m)≤0˙}⍟(1-m1) 𝕩{𝕏○(⊑⟜𝕗)} cs⊑cmps
+ B←l⊸≤◶⊢‿l
+ (↕l){
+ i←-d←𝕨 ⋄ j←ei←ej←0
+ e←3 ⋄ G←LE○(⊑⟜(m⊸×⌜⍟(1-m=1)𝕩)) ⋄ c←⟨1-G,0,1,2⟩
+ s←(8≤d)⊑⟨+,{(𝕩-1){𝕩⋄e↩2⋄j↩i⋄i↩𝕩}⍟G⍟(1-e)𝕩}⟩
+ N←{i↩d+𝕨⋄ej↩B d+ei↩B j↩d+𝕩⋄e↩l≤j⋄S ei⋄i R j}
+ R←{𝕨e◶c𝕩}◶{e+↩2×ei=i↩1+𝕨⋄𝕨}‿{e+↩ej=j↩1+𝕩⋄𝕩}‿N
+ {(i R j)⊑𝕩}⟜𝕩⌜𝕩
+ }´(2⋆ni-1+⊢)⌜↕ni←⌈2 Log l+l=0
+ }
+ # Counting sort for small-range ints
+ bl←bu←0 ⋄ Count←{GroupLen⊸GroupOrd (gt⊑⟨-⟜bl,bu⊸-⟩)⌜𝕩}
+ sr←((3=cs)×ts=l)◶⟨0,(1×´⌊⊸=⌜)◶0‿{((bu↩⌈´𝕩)-bl↩⌊´𝕩)≤2×l}⟩𝕩
+ sr◶Merge‿Count 𝕩
+ }⟩𝕩
}
}
_binSearch ← {