insertion-sort ( base extended -- base )


Vocabulary
punycode.private

Inputs
basean object
extendedan object


Outputs
basean object


Definition


:: insertion-sort ( base extended -- base )
N :> ch! -1 :> pos! BIAS :> bias! 0 :> extpos! extended
length :> extlen
[ extpos extlen < ] [
extended extpos bias decode-delta
:> ( newpos delta ) delta 1 + pos +
pos! pos base length 1 + /mod pos! ch + ch! ch 1114111 >
[ ch invalid-character ] when ch pos base insert-nth!
delta base length extpos 0 = adapt bias! newpos extpos!
] while base ;