vquicksort   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/core/math.xtm

Implementation

(bind-func vquicksort
  (lambda (buf:i64* left right)
    (if (< left right)
        (let ((tmp 0)
              (_swap (lambdas (x y)
                              (set! tmp (pref buf x))
                              (pset! buf x (pref buf y))
                              (pset! buf y tmp)))
              (pivot (pref buf right))
              (index left)
              (i 0))
          (dotimes (i left (- right left))
            (if (or (< (pref buf i) pivot)
                    (= (pref buf i) pivot))
                (begin (_swap i index)
                       (set! index (+ index 1)))))
          (_swap right index)
          (vquicksort buf left (- index 1))
          (vquicksort buf (+ index 1) right))
        void)))


Back to Index

Similar Entries