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


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

Re: Did the sort do anything?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!goblin3!goblin.stu.neva.ru!odin.sdf-eu.org!.POSTED!not-for-mail
From dagon@dagon.net (Dagon)
Newsgroups comp.lang.java.programmer
Subject Re: Did the sort do anything?
Date Mon, 7 Nov 2011 12:50:26 -0800
Organization Dagon.net
Lines 30
Message-ID <itslo8-iq7.ln1@dagon.net> (permalink)
References <4d8fb7l8qb1g820cphr4fh447a9uitlddj@4ax.com>
NNTP-Posting-Host sverige.sdf.org
X-Trace odin.sdf-eu.org 1320699315 5144 192.94.73.4 (7 Nov 2011 20:55:15 GMT)
X-Complaints-To usenet@odin.sdf-eu.org
NNTP-Posting-Date Mon, 7 Nov 2011 20:55:15 +0000 (UTC)
mail-copies-to never
x-fastest-land-animal cheetah
disclaimer bears author this post for full responsibility
X-Newsreader trn 4.0-test77 (Sep 1, 2010)
Originator dagon@dagon.net (Dagon)
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9750

Show key headers only | View raw


Roedy Green  <see_website@mindprod.com.invalid> wrote:
>What is the easiest way to determine if a sort actually changed the
>order?

Easiest?  Copy it, run the sort, do a compare.  Alternately, instrument your
collection to note when elements are changed (though the simplest version of
this won't detect when the sort changes order and then puts it back).  Or
instrument your sorting routing to note when it hits a state that indicates a
change is needed / was made.

>1. do I really need to sort in cases when  the data are most likely
>already in order? (perhaps just sorting is as fast as trying to bypass
>it most of the time).
>2. did the sort change anything. Do I have to commit the changed order
>to disk?

Note that #1 is a different question than you asked.  "would a sort
change the order" is not the same as "did a sort change the order".  Many
implementations can be used for both, of course.

>The obvious solution to (1) is to pairwise compare array exported from
>the collection before the sort.
>The obvious solution to (2) is compare corresponding elements in
>arrays exported before and after the sort with the comparator, or use
>(1). 

Instrumenting the collection or the sort method beats both of these in terms
of performance, though perhaps not in terms of simplicity.  
--
Mark Rafn    dagon@dagon.net    <http://www.dagon.net/>  

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


Thread

Did the sort do anything? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-07 01:27 -0800
  Re: Did the sort do anything? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-07 02:20 -0800
    Re: Did the sort do anything? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-11-07 11:21 +0000
  Re: Did the sort do anything? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-11-07 10:49 +0000
    Re: Did the sort do anything? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-07 02:58 -0800
  Re: Did the sort do anything? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-07 07:11 -0500
    Re: Did the sort do anything? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-11-07 08:30 -0600
      Re: Did the sort do anything? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-07 21:03 -0500
  Re: Did the sort do anything? markspace <-@.> - 2011-11-07 07:48 -0800
  Re: Did the sort do anything? dagon@dagon.net (Dagon) - 2011-11-07 12:50 -0800
    Re: Did the sort do anything? Cindy <c.thurston@frell.okb.uwa.edu> - 2011-11-07 22:02 -0500
      Re: Did the sort do anything? Cindy <c.thurston@frell.okb.uwa.edu> - 2011-11-07 22:22 -0500
  Re: Did the sort do anything? Arne Vajhøj <arne@vajhoej.dk> - 2011-11-07 17:42 -0500

csiph-web