aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-03-26 08:50:54 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-03-26 08:52:13 -0400
commit796d15378aee570675b4d0c34dd5b06c98e013dd (patch)
tree42f814eb9ab9ac39d679e5b8ce4b04dd56e45c9b /src
parent7be65886036969a93efd06d77f59730a157c0498 (diff)
Switch to index-based primitive lookups for speed
Diffstat (limited to 'src')
-rw-r--r--src/r.bqn16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/r.bqn b/src/r.bqn
index a42f1a35..e64ee27e 100644
--- a/src/r.bqn
+++ b/src/r.bqn
@@ -2,8 +2,8 @@
# Type Fill Log GroupLen GroupOrd _fillBy_
# !+-×÷⋆⌊=≤≢⥊⊑↕⌜`⊘
Decompose ← {0‿𝕩}
-Glyph ← {𝕩⋄!0}
-SetPrims ← {Decompose‿Glyph ↩ 𝕩}
+PrimInd ← {𝕩⋄!0}
+SetPrims ← {Decompose‿PrimInd ↩ 𝕩}
◶ ← {𝕨((𝕨𝔽𝕩)⊑𝕘){𝔽}𝕩} # LIMITED to number left operand result
⊢ ← {𝕩}
@@ -42,6 +42,11 @@ _fold←{
}
´ ← _fold
+_glyphLookup_ ← {
+ g←"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!˙˜˘¨⌜⁼´˝`∘○⊸⟜⌾⊘◶⎉⚇⍟%"
+ {PrimInd𝕩} ⊑ ((𝕘⊑˜·+´·×`𝕗(1-=)⌜<)⌜g)˙
+}
+
Cell←{(𝕨⊸+⊑𝕩˙)⌜↕(≠𝕩)-𝕨}⟜≢
∾ ← {k←≠𝕨⋄k⊸≤◶⟨⊑⟜𝕨⋄-⟜k⊑𝕩˜⟩⌜↕k+≠𝕩} # LIMITED to two vector arguments
@@ -704,12 +709,9 @@ JoinPrim ← ∾
⊒ ← OccurrenceCount⊘ ProgressiveIndexOf
⍷ ← ∊⊸/ ⊘ Find
-_glyphLookup_ ← {
- (0+´·∧`𝕗≠{Glyph𝕩})⊑(∾´𝕘)˙
-}
_lookup_ ← {
s ← 2×↕(≠𝕘)÷2
- (s⊏𝕘) _glyphLookup_ ((1+s)⊏𝕘)‿𝕗
+ (s⊏𝕘) _glyphLookup_ (((1+s)⊏𝕘)∾<𝕗)
}
Identity ← {𝕏0} ("´: Identity not found"!0˙) _lookup_ ⟨
'+',0 , '-',0
@@ -812,7 +814,7 @@ FuncInverse ← (⊑ ⊣◶⟨
Inverse ← Type◶(3‿1‿2/{⊢⊣𝕩IX∘≡⊢}‿FuncInverse‿("Cannot invert modifier"!0˙))
⁼ ↩ {𝕗 (≢∧INF˙⊸≢)◶0‿(5‿_inv_≢0‿¯2⊏Decompose∘⊢)◶⊢‿{𝕏_inv_(𝕎_invChk_𝕏)} Inverse 𝕗}
-structPrimClass ← {(∾𝕩)_glyphLookup_((/≍○<≠)≠¨𝕩)} ⥊¨ ⟨
+structPrimClass ← {(∾𝕩)_glyphLookup_((/∾≠)≠¨𝕩)} ⥊¨ ⟨
'⊢'‿'⊣'‿'˜'‿'∘'‿'○'‿'⊸'‿'⟜'‿'⊘'‿'◶'
'='‿'≠'‿'≢'
'<'