author | Francesco Abbate <francesco.bbt@gmail.com> | 2013年02月05日 10:20:36 +0100 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2013年02月05日 10:20:36 +0100 |
commit | dac5106531534f5dbc7e223a30acbdc7a8c686ca (patch) | |
tree | cfa08ecf63ffcc6b397f30bdaf24cc0a9f12d544 /gdt-plot.lua | |
parent | fd774f79da279888d48728d95d6009594ddf63ad (diff) | |
download | gsl-shell-dac5106531534f5dbc7e223a30acbdc7a8c686ca.tar.gz |
-rw-r--r-- | gdt-plot.lua | 42 |
diff --git a/gdt-plot.lua b/gdt-plot.lua index 99322be7..073b0f44 100644 --- a/gdt-plot.lua +++ b/gdt-plot.lua @@ -47,6 +47,46 @@ local stat_lookup = { count = {f = function(accu, x, n) return n end}, } +local function quicksort_mirror(t, f, mirror) + + local function quicksort(start, endi) + if start >= endi then return end + local pivot = start + for i = start + 1, endi do + if f(t[i], t[pivot]) then + local temp = t[pivot + 1] + local temp_m = mirror[pivot + 1] + t[pivot + 1] = t[pivot] + mirror[pivot + 1] = mirror[pivot] + if(i == pivot + 1) then + t[pivot] = temp + mirror[pivot] = temp_m + else + t[pivot] = t[i] + t[i] = temp + mirror[pivot] = mirror[i] + mirror[i] = temp_m + end + pivot = pivot + 1 + end + end + + quicksort(start, pivot - 1) + quicksort(pivot + 1, endi) + end + + quicksort(1, #t) +end + +local function sort_labels_func(lab_a, lab_b) + local n = #lab_a + for k = 1, n do + local a, b = lab_a[k], lab_b[k] + if a ~= b then return a < b end + end + return false +end + local function compare_list(a, b) local n = #a for k = 1, n do @@ -152,6 +192,8 @@ local function rect_funcbin(t, jxs, jys, jes) end end + quicksort_mirror(labels, sort_labels_func, val) + return labels, enums, val end |