Re: sorting columns



In comp.lang.javascript message <j8uonk$v6j$1@xxxxxxxxxxxxxxxxx>, Thu, 3
Nov 2011 20:06:35, Andreas Bergmaier <andber93@xxxxxx> posted:

Dr J R Stockton schrieb:
Why sort a<table>?
Why not?

Because sorting an N-element list requires something like 2 N log N
individual element reads, and maybe N log N element writes. For those,
the sort algorithms refer to an element by its index number. Therefore,
if the number of rows may be large, one wants to optimise the speed of
each of the N log N steps of the sort. Using an array for the rows will
provide the simplest access to the elements being sorted. Using arrays
for the data within the rows will provide simple access to the items to
be compared.

If the columns are numbered 1 to J, then the sort keys could be stored
in Column 0, for ready access.


Supply the data in JavaScript, as a "two-dimensional array"
Arr[[..., ..., ... ], [...], [...], [...], ... [...]] ;

At need, sort that. Then remove any existing Table, build the new Table
using DOM methods, and insert the new Table.

What do you mean with two-dimensional array? Does it represent the cell
data, or does each second-level-array contain the relevant cell content
(of the column you want to sort) and a reference to the row element?

I meant that the elements of the array, if written out in the usual two-
dimensional form, would look like the actual table elements on screen.

I guess it would be faster to store the dom elements, instead of
rebuilding them.

That, I think, will depend strongly on the number of rows in the array;
one *must* have easy access to the values to be compared. If it is
large, the only important thing is to optimise the actual sorting. If
it is small, the whole thing will take very little time anyway.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
.



Relevant Pages

  • Re: A Fast sorting algorithm for almost sorted data
    ... far my compressor has potential but is nowhere near ready. ... It does however make heavy use of sorting. ... which I am currently calling Run sort. ... entire selected run can be added to the sorted output array. ...
    (comp.compression)
  • Re: Sorting routine
    ... n RSHIFT shifts n bits. ... in the output array. ... This would be handy for sign sorting of 2's complement. ... So Radix/Distribution sort is about 1.4 times faster than Sedge's Sort. ...
    (comp.lang.forth)
  • Re: Efficiently Extracting Identical Values From A List/Array
    ... struct SortHelper ... Now sort that array according to NodeIndex: ... running through the data structure and sorting things out. ...
    (comp.lang.cpp)
  • Re: indirect sort
    ... I wrote a Comparator (I don't want to use ... Comparable in order to be able to choose the field I am sorting by) ... a way to create a doublearray of my fields I want to sort by, ...
    (comp.lang.java.programmer)
  • Re: "Sorting" assignment
    ... And many others prefer to call partition exchange because "quicksort" ... bin B depending on whether it is greater than, ... If the array is already sorted, this means that you end up ... attempt to sort them. ...
    (comp.programming)