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


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

Re: How to parse an array?

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: How to parse an array?
Date Mon, 26 Jun 2017 15:47:23 -0000 (UTC)
Organization A noiseless patient Spider
Lines 52
Message-ID <oiraab$igd$2@dont-email.me> (permalink)
References <b36c14f6-dfe7-492e-99ab-7bb7aeb35ac3@googlegroups.com> <English-20170620202702@ram.dialup.fu-berlin.de> <er6rmeFbgtsU1@mid.individual.net> <1758ec6f-966d-44c2-bdb9-03e5d4b61619@googlegroups.com> <oir2ej$rnh$1@dont-email.me> <21b6dbae-d72c-446d-b272-bac67bc7fd86@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Mon, 26 Jun 2017 15:47:23 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="bd9c564d5e0e09d99abbff91f4050575"; logging-data="18957"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18z2Q4ozEzijyQB8MWx3JCN7EalNC/pUnQ="
User-Agent Pan/0.141 (Tarzan's Death; 168b179 git.gnome.org/pan2)
Cancel-Lock sha1:FWViBOpmY4raeju8HK4SYC1GyRo=
Xref csiph.com comp.lang.java.programmer:36733

Show key headers only | View raw


On Mon, 26 Jun 2017 07:47:19 -0700, Eric Douglas wrote:

> On Monday, June 26, 2017 at 9:37:16 AM UTC-4, Eric Sosman wrote:
>>      It's true that dynamic insertions and deletions are simpler to
>>      write
>> with an ArrayList<Thing> than with a Thing[].  But your original post
>> didn't mention simplicity as a goal; rather, you asked for "a more
>> efficient way."
>> 
>>      Open-coded Thing[] will be no less efficient than ArrayList<Thing>
>> (barring silly mistakes in the open code), and stands a good chance of
>> being more efficient.  By how much remains an open question.
> 
> Now if you're saying it would be more efficient to use String[] instead
> of the ArrayList<String> and int[] instead of the ArrayList<Integer>,
> the first question is how much more and do I end up copying all the code
> from the ArrayList class when I need to remove or insert elements.  The
> second question is how do you manage an array of arrays.
> 
> Consider list1 is actually ArrayList<String[]>.  Now list2 passes in the
> integer list of indexes to return and a second parameter passes in a
> second list of the element order to return.  So each index now returns a
> String[] set, all sets having the same number of elements, now you want
> them sorted based on say their second element.
> 
> The Oracle Java does this automatically in DefaultRowSorter.sort() but
> it does take several seconds for each call with a relatively large table
> as they completely rebuild arrays, while the filtering without sorting
> appears instant.

If I need an ordered list, and particularly if the list will be 
constructed once and read at least twice, I'll probably use a TreeMap.

TreeMaps are implemented as red-black binary trees, so stepping through a 
one is generally fairly efficient and so are searches since they only 
need to look at one node in each level of the tree: a red-black tree with 
4 million elements has 23 levels [1].  So far I haven't had any 
performance issues doing it this way, and I've used this approach for 
trees that big. However, it may be an inefficient approach for tiny trees 
due to the per-node overheads when adding or removing nodes.

[1] Red-black binary trees are always balanced because they rebalance as 
nodes are added and are not sensitive to the order in which nodes are 
added. This is not the case for simple binary trees, which do not self-
balance and in the extreme case, adding nodes in key sequence, will 
degenerate into an ordered linked list.


-- 
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