Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36746

Re: How to parse an array?

From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: How to parse an array?
Date 2017-06-27 22:34 +0000
Organization A noiseless patient Spider
Message-ID <oiumi8$6om$1@dont-email.me> (permalink)
References (3 earlier) <1758ec6f-966d-44c2-bdb9-03e5d4b61619@googlegroups.com> <967dfbc4-0e58-4867-b08c-67ff910df3fe@googlegroups.com> <642c0caf-de21-4add-8f61-8b68e94b1081@googlegroups.com> <oiudpv$imf$1@dont-email.me> <dc58b7e1-186b-472f-a088-f9b848481404@googlegroups.com>

Show all headers | View raw


On Tue, 27 Jun 2017 14:01:20 -0700, Eric Douglas wrote:

> Yes my table model extends AbstractTableModel.  I have each cell value
> in a custom object that handles getting and setting values by String or
> numeric for different cell styles.  The model data is in an ArrayList. 
> Each element of the ArrayList is an array [] of that cell class.
>
Sounds good, though as the row is a fixed size I'm curious why it isn't a 
class instead, since that, given a getter/setter for each data element 
would seem to be functionally very similar.
 
>> Whats a 'usual' size in terms of row and column counts?
>>   
>>   
> Currently within the application a typical table may contain around 10
> columns and a few hundred rows.  I populated the table in some test
> programs with full query results of over 70,000 rows of 24 columns to
> test the search capability.
>
Understood. Thats a significant amount of data regardless of the size of 
the 'average column' so your performance stats should be good.

> It populates very quickly until I try to sort a column.
>
Do you know what sorting algorithm is being used? 

Its worth finding out and considering their strengths and weaknesses, 
which are not always obvious. 

For instance, quicksort is generally considered to be the bee's knees, 
but I discovered a weakness: its has an unstated optimisation (at least 
in my books) because they assume that moving sorted items into sequence 
will always be more expensive than key comparisons. This is not always 
the case.

Years back I implemented all the sort routines in 'Software Tools in 
Pascal' using a very small, somewhat C-like language (PL/9 which was 
effectively an implementation of PL/M in the 6809 MPU). In doing this I 
stored the input records as a heap of strings and added theit address 
pointers to an address array. This made swaps very fast because I never 
moved anything in record heap and reordered records by exchanging their 
pointer positions in the array. When I'd implemented multi-key sorts and 
lexicographic ordering, the key comparisons could become quite expensive 
to execute. In the course of experimenting with this I found that 
quicksort got much slower as the key comparisons got more complex but, 
surprisingly, the more lowly shellsort overtook quicksort as I made the 
key comparisons more and more complex.

This point may not affect you, but do bear it in mind when looking at 
comparisons of sorting algorithms, especially as the analyses often don't 
consider the relative costs of key comparisons vs swapping sorted items.

It might also be worthwhile seeing if different ways of storing the data 
speeds things up. Try using a TreeMap which should be good, if by 
'sorting' you mean changing the key of a row and having it jump to a new 
position determined by key comparison. It may also speed things up if the 
entire table gets resorted because you've changed the sort key from 
column A to column B and rebuilding the TreeMap. I think you'll find that 
rebuilding a TreeMap in this way leaves the arrays (or objects if you go 
that way) in their old positions in the heap while creating a new TreeMap 
instance in which each element contains the key and reference to the 
corresponding array/object, in which case building a new TreeMap and 
scrapping the old one should be a pretty fast operation.  

You might also consider the sort of indirection I mentioned above: that 
should make a big difference too if the current sort method involves 
swapping row positions in the ArrayList.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-20 12:18 -0700
  Re: How to parse an array? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-06-20 14:49 -0500
  Re: How to parse an array? Arne Vajhøj <arne@vajhoej.dk> - 2017-06-20 16:15 -0400
  Re: How to parse an array? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-06-20 16:23 -0400
  Re: How to parse an array? Robert Klemme <shortcutter@googlemail.com> - 2017-06-24 12:02 +0200
    Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-26 05:10 -0700
      Re: How to parse an array? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-06-26 09:36 -0400
        Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-26 07:47 -0700
          Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-26 15:47 +0000
        Re: How to parse an array? Arne Vajhøj <arne@vajhoej.dk> - 2017-06-26 20:37 -0400
      Re: How to parse an array? lewbloch@gmail.com - 2017-06-27 12:29 -0700
        Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-27 12:50 -0700
          Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-27 20:05 +0000
            Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-27 14:01 -0700
              Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-27 22:34 +0000
                Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-28 05:10 -0700
                Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-28 19:09 +0000
                Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-28 13:02 -0700
                Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-28 21:55 +0000
                Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-30 06:10 -0700
                Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-30 16:52 +0000
  Re: How to parse an array? Jerry Stuckle <jstucklex@attglobal.net> - 2017-06-24 16:34 -0400
    Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-24 22:42 +0000
      Re: How to parse an array? Jerry Stuckle <jstucklex@attglobal.net> - 2017-06-24 20:05 -0400
      Re: How to parse an array? Robert Klemme <shortcutter@googlemail.com> - 2017-06-25 12:20 +0200

csiph-web