From 1e1932c3314ce84ca590c5749494776e359437ad Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 1 May 2021 22:06:04 -0400 Subject: Some cleanup for binary search --- src/r1.bqn | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/r1.bqn b/src/r1.bqn index 398b079b..dedf3125 100644 --- a/src/r1.bqn +++ b/src/r1.bqn @@ -106,13 +106,6 @@ Cmp ← +○IsArray◶⟨ } ⟩ -_binSearch ← { - B ← 𝔽 - { - R←{a←B m←𝕩+h←⌊𝕨÷2⋄(h+a×𝕨-2×h)R a⊑𝕩‿m}⍟(>⟜1) - 1+(𝕩+1)R ¯1 - }⍟(0⊸<) -} _grade ← { gt ← 𝕗 cmps ← {𝕏˜}⌜⍟𝕗⟨Cmp,Cmp0,Cmp≤0˙,≤⟩ @@ -143,20 +136,26 @@ _grade ← { sr◶Merge‿Count 𝕩 }⟩𝕩 }⊘{ - c←1-˜=𝕨 + cx←(=𝕩)-c←1-˜=𝕨 "⍋ or ⍒: Rank of 𝕨 must be at least 1" ! 0≤c - "⍋ or ⍒: Rank of 𝕩 must be at least cell rank of 𝕨" ! c≤=𝕩 - lw←1×´sw←1 Cell 𝕨 ⋄ nw←≠𝕨 ⋄ 𝕨↩⥊𝕨 ⋄ Gw←⊑⟜𝕨 ⋄ a0w←IsSimple𝕨 - lew←{𝕏○Gw} _getC_ lw a0w+2×1=lw - "⍋ or ⍒: 𝕨 must be sorted" ! 0⊸<◶⟨1,1×´·LEw⟜(lw⊸+)∘(lw⊸×)⌜↕∘-⟜1⟩nw - 𝕩↩ToArray𝕩 - cx←c-˜=𝕩 - sx←cx Cell 𝕩 ⋄ sz←cx↑≢𝕩 ⋄ 𝕩↩⥊𝕩 ⋄ Gx←⊑⟜𝕩 - a0←IsSimple∘𝕩⊸×⍟⊢a0w - cd‿lc←sw CmpLen sx - le ← cd {GW⊸𝕏⟜GX}_getC_ lc a0+2×1=lc - B←(1×´sw)⊸×⊸LE - 0 Fill nw⊸{B⟜𝕩 _binSearch 𝕨}⌜ (1×´sx)⊸×⌜ ⥊⟜(↕1×´⊢)sz + "⍋ or ⍒: Rank of 𝕩 must be at least cell rank of 𝕨" ! 0≤cx + sw←1 Cell 𝕨 ⋄ nw←≠𝕨 + 𝕩↩ToArray𝕩 ⋄ sx←cx Cell 𝕩 ⋄ lz←1×´sz←cx↑≢𝕩 + sz ⥊ 𝕨 (0⟜1) + 1 + (nw+1) R ¯1 + } + (BinSearch (1×´sx)⊸×)⌜ ↕lz + }○⥊ 𝕩 } } -- cgit v1.2.3