needs tests/harness mem/sort testbegin \test sort create myarray map< , 3 7 8 5 2 1 9 5 4 myarray 9 sort create expected map< , 1 2 3 4 5 5 7 8 9 myarray expected 9 []= # \test sortpairs \ I don't include the two 5s this time because which one of them goes first is \ undefined. create myarray map< , 3 1 7 2 8 3 5 4 2 5 1 6 9 7 4 8 myarray 8 sortpairs create expected map< , 1 6 2 5 3 1 4 8 5 4 7 2 8 3 9 7 myarray expected 16 []= # \test bisect \ tests below might seem redundant, but they in fact test edge cases with even \ and uneven sub ranges, where there's a trickiness due to division by 2. create myarray map< , 2 4 6 8 10 12 0 myarray 6 bisect not #true 0 #eq 1 myarray 6 bisect not #true 0 #eq 2 myarray 6 bisect #true 0 #eq 3 myarray 6 bisect not #true 1 #eq 4 myarray 6 bisect #true 1 #eq 5 myarray 6 bisect not #true 2 #eq 6 myarray 6 bisect #true 2 #eq 7 myarray 6 bisect not #true 3 #eq 8 myarray 6 bisect #true 3 #eq 9 myarray 6 bisect not #true 4 #eq 10 myarray 6 bisect #true 4 #eq 11 myarray 6 bisect not #true 5 #eq 12 myarray 6 bisect #true 5 #eq 13 myarray 6 bisect not #true 6 #eq \test bisectleft create myarray map< , 1 2 2 2 3 2 myarray 5 bisectleft #true 1 #eq 1 myarray 5 bisectleft #true 0 #eq 0 myarray 5 bisectleft not #true 0 #eq \test bisectpairs create myarray map< , 2 42 4 42 6 42 8 42 10 42 12 0 myarray 6 bisectpairs not #true 0 #eq 3 myarray 6 bisectpairs not #true 1 #eq 4 myarray 6 bisectpairs #true 1 #eq \test bisectpairsleft create myarray map< , 1 42 2 42 2 42 2 42 3 2 myarray 5 bisectpairsleft #true 1 #eq 1 myarray 5 bisectpairsleft #true 0 #eq 0 myarray 5 bisectpairsleft not #true 0 #eq testend