help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More Informed Sort


From: David Bateman
Subject: Re: More Informed Sort
Date: Sat, 11 Feb 2006 10:55:09 +0100
User-agent: Mozilla Thunderbird 0.8 (X11/20040923)

The octave soring class is based on a mergesort and given partially sorted lists will be significantly faster than other types of sorts. The matlab sorting class is based on quicksort so is better for random lists. This being the case just using octave sort function should give near optimum performance.

Additionally as the octave sort function is written as a class you can easily apply it to sort other types of data in an oct-file. For example to sort an octave_idx_type vector and also return the vector of indices you can do something like

class
octave_idx_vector_sort
{
public:
 octave_idx_type i;
 octave_idx_type idx;
};

bool
octave_idx_vector_comp (octave_idx_vector_sort* i,
                       octave_idx_vector_sort* j)
{
 return (i->i < j->i);
}

template class octave_sort<octave_idx_vector_sort *>;

int main (void){
...
         OCTAVE_LOCAL_BUFFER (octave_idx_vector_sort *, sidx, n);
         OCTAVE_LOCAL_BUFFER (octave_idx_vector_sort, sidxX, n);

         for (octave_idx_type i = 0; i < n; i++)
       {
         sidx[i] = &sidxX[i];
         sidx[i]->i = lhs_idx.elem(i);
         sidx[i]->idx = i;
       }

octave_sort<octave_idx_vector_sort *> sort (octave_idx_vector_comp);
         sort.sort (sidx, n);
...
}

Where sidx[i]->i returns the data and sidx[i]->idx returns the list of indices..

Regards
David

--
David Bateman                                address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) 91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax) The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]