qx.ui.table.model.Simple.setSortMethods()

View: New views
8 Messages — Rating Filter:   Alert me  

qx.ui.table.model.Simple.setSortMethods()

by Ian Horst :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I wonder why there are 2 sort methods, one for ascending, second for descending.

It's enough to define ascending sort method. Descending is just
reverse of ascending sort method.

ascending:
ascSortMethod();

descending:
- ascSortMethod();

---
Ian

------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@...
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Re: qx.ui.table.model.Simple.setSortMethods()

by Derrell Lipman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Jul 3, 2009 at 10:12 AM, Ian Horst <ian.horst@...> wrote:
I wonder why there are 2 sort methods, one for ascending, second for descending.

It's enough to define ascending sort method. Descending is just
reverse of ascending sort method.

ascending:
ascSortMethod();

descending:
- ascSortMethod();

Hi Ian,

The sort method is passed to Array.sort(). According to my O'Reilly book, there's no mechanism for specifying that the sort order should be reversed. One could use the Ascending sort function to sort the array followed by a call to Array.reverse if a descending sort was requested, but that sounds mighty inefficient.

Maybe there's a feature of a later version of Javascript (my book is old; it covers up through 1.5) that allows sorting in reverse, but I think we'd still need both sort functions anyway to support older browsers.

Derrell



------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@...
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Re: qx.ui.table.model.Simple.setSortMethods()

by Ian Horst :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Derrell,

I see your point. But let's take away from developers to define
descending function. Qooxdoo framework can figure it out itself. Less
code is better. :)

I don't have time to look at the backend of qooxdoo right now, but
instead of setSortMethods we could use

...setSortMethod: function (sortAscMethod)
{
  var sortDescMethod = function (row1, row2) {return
sortAscMethod(row2, row1);};
  var sortMethods = {ascending: sortAscMethod, descending: sortDescMethod};
  ...
}



---
Ian

2009/7/6 Derrell Lipman <derrell.lipman@...>:

> On Fri, Jul 3, 2009 at 10:12 AM, Ian Horst <ian.horst@...> wrote:
>>
>> I wonder why there are 2 sort methods, one for ascending, second for
>> descending.
>>
>> It's enough to define ascending sort method. Descending is just
>> reverse of ascending sort method.
>>
>> ascending:
>> ascSortMethod();
>>
>> descending:
>> - ascSortMethod();
>
> Hi Ian,
>
> The sort method is passed to Array.sort(). According to my O'Reilly book,
> there's no mechanism for specifying that the sort order should be reversed.
> One could use the Ascending sort function to sort the array followed by a
> call to Array.reverse if a descending sort was requested, but that sounds
> mighty inefficient.
>
> Maybe there's a feature of a later version of Javascript (my book is old; it
> covers up through 1.5) that allows sorting in reverse, but I think we'd
> still need both sort functions anyway to support older browsers.
>
> Derrell
>
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> qooxdoo-devel mailing list
> qooxdoo-devel@...
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>

------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@...
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Re: qx.ui.table.model.Simple.setSortMethods()

by Derrell Lipman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Jul 6, 2009 at 6:01 AM, Ian Horst <ian.horst@...> wrote:
Derrell,

I see your point. But let's take away from developers to define
descending function. Qooxdoo framework can figure it out itself. Less
code is better. :)

I don't have time to look at the backend of qooxdoo right now, but
instead of setSortMethods we could use

...setSortMethod: function (sortAscMethod)
{
 var sortDescMethod = function (row1, row2) {return
sortAscMethod(row2, row1);};
 var sortMethods = {ascending: sortAscMethod, descending: sortDescMethod};
 ...
}

Ian, that sounds like a great idea. I need to think about it some more to ensure there aren't cases where simply swapping the parameters wouldn't do the job, and it is an API change that should be well-considered. Would you please create an enhancement bug for this, including the issue you're trying to solve and your proposed solution. That way, this won't get forgotten. It's likely not to get into the upcoming release, but can still make it into 0.9 if we agree it's appropriate.

Derrell


------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@...
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Re: qx.ui.table.model.Simple.setSortMethods()

by dmbaggett :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I agree with Ian: swapping parameters to the user-provided sort-function should work just fine. JavaScript's Array sort method expects a function that imposes a "total order" on the objects to be sorted. In particular,

f(a, b) =
  -1 if a < b
   0 if a == b
   1 if a > b

By reversing the parameters, it's easy to see that you're just swapping the -1 and 1 values:

f(b, a) =
  -1 if b < a
   0 if b == a
   1 if b > a

So provided that function f() is correct from the standpoint of Array.sort, its inverse (obtained by swapping the a and b parameters) is also correct, and will sort in the opposite order.

The argument given in the source for having two methods is "performance reasons". But swapping parameters obviously causes no performance degradation.

For the new (to-be-named) enhanced table model which I recently submitted as an enhancement, this is a trivial change.

The only question is whether we want to do anything to avoid breaking existing code as this will constitute an API change.

Dave

Derrell Lipman wrote:
On Mon, Jul 6, 2009 at 6:01 AM, Ian Horst <ian.horst@googlemail.com> wrote:

> Derrell,
>
> I see your point. But let's take away from developers to define
> descending function. Qooxdoo framework can figure it out itself. Less
> code is better. :)
>
> I don't have time to look at the backend of qooxdoo right now, but
> instead of setSortMethods we could use
>
> ...setSortMethod: function (sortAscMethod)
> {
>  var sortDescMethod = function (row1, row2) {return
> sortAscMethod(row2, row1);};
>  var sortMethods = {ascending: sortAscMethod, descending: sortDescMethod};
>  ...
> }
>

Ian, that sounds like a great idea. I need to think about it some more to
ensure there aren't cases where simply swapping the parameters wouldn't do
the job, and it is an API change that should be well-considered. Would you
please create an enhancement bug for this, including the issue you're trying
to solve and your proposed solution. That way, this won't get forgotten.
It's likely not to get into the upcoming release, but can still make it into
0.9 if we agree it's appropriate.

Derrell

------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Re: qx.ui.table.model.Simple.setSortMethods()

by Derrell Lipman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Jul 8, 2009 at 10:21 AM, dmbaggett <dave@...> wrote:


The argument given in the source for having two methods is "performance
reasons". But swapping parameters obviously causes no performance
degradation.

Actually, I don't believe that's true. It imposes an extra function call for each two items that are compared. Depending upon the sort algorithm that's implemented in the native Array.sort() and how out-of-order the items are to begin with, this means a likely minimum number of extra function calls is the number of rows in the table, and the actual number could be much, much greater.

For the new (to-be-named) enhanced table model which I recently submitted as
an enhancement, this is a trivial change.

The only question is whether we want to do anything to avoid breaking
existing code as this will constitute an API change.

See my proposed implementation that handles this and associated comments in bug #2553:
  http://bugzilla.qooxdoo.org/show_bug.cgi?id=2553

Derrell


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@...
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Re: qx.ui.table.model.Simple.setSortMethods()

by Ian Horst :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I run profiling using firebug profile on:
var f1 = function (a, b) {return true;};
var f2 = function (a, b) {return f1(b, a);};

When I run 1000000 calls, I get stable performance penalty of:
* 350ms on Intel I7 920 using Mozilla/5.0 (X11; U; Linux x86_64;
en-GB; rv:1.9.1) Gecko/20090701 Gentoo Firefox/3.5
* 1600ms on Intel 2.8Ghz HT using Firefox 3.0 on ArchLinux

So far it seems that it makes sense to use f2() to sort small tables
below 1000-1500 rows in worst case scenarios.
Performance wise it's better to use predefined descending function.

I'll run tests using patch made by Derrell tomorrow.

---
Ian

2009/7/8 Derrell Lipman <derrell.lipman@...>:

> On Wed, Jul 8, 2009 at 10:21 AM, dmbaggett <dave@...> wrote:
>>
>>
>> The argument given in the source for having two methods is "performance
>> reasons". But swapping parameters obviously causes no performance
>> degradation.
>
> Actually, I don't believe that's true. It imposes an extra function call for
> each two items that are compared. Depending upon the sort algorithm that's
> implemented in the native Array.sort() and how out-of-order the items are to
> begin with, this means a likely minimum number of extra function calls is
> the number of rows in the table, and the actual number could be much, much
> greater.
>>
>> For the new (to-be-named) enhanced table model which I recently submitted
>> as
>> an enhancement, this is a trivial change.
>>
>> The only question is whether we want to do anything to avoid breaking
>> existing code as this will constitute an API change.
>
> See my proposed implementation that handles this and associated comments in
> bug #2553:
>   http://bugzilla.qooxdoo.org/show_bug.cgi?id=2553
>
> Derrell
>
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> qooxdoo-devel mailing list
> qooxdoo-devel@...
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@...
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Re: qx.ui.table.model.Simple.setSortMethods()

by Derrell Lipman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ian, thanks for running the tests. Please attach results (both these and tomorrow's) to the ticket so they don't get lost.

Thanks,

Derrell


On Wed, Jul 8, 2009 at 12:13 PM, Ian Horst <ian.horst@...> wrote:
I run profiling using firebug profile on:
var f1 = function (a, b) {return true;};
var f2 = function (a, b) {return f1(b, a);};

When I run 1000000 calls, I get stable performance penalty of:
* 350ms on Intel I7 920 using Mozilla/5.0 (X11; U; Linux x86_64;
en-GB; rv:1.9.1) Gecko/20090701 Gentoo Firefox/3.5
* 1600ms on Intel 2.8Ghz HT using Firefox 3.0 on ArchLinux

So far it seems that it makes sense to use f2() to sort small tables
below 1000-1500 rows in worst case scenarios.
Performance wise it's better to use predefined descending function.

I'll run tests using patch made by Derrell tomorrow.

---
Ian

2009/7/8 Derrell Lipman <derrell.lipman@...>:
> On Wed, Jul 8, 2009 at 10:21 AM, dmbaggett <dave@...> wrote:
>>
>>
>> The argument given in the source for having two methods is "performance
>> reasons". But swapping parameters obviously causes no performance
>> degradation.
>
> Actually, I don't believe that's true. It imposes an extra function call for
> each two items that are compared. Depending upon the sort algorithm that's
> implemented in the native Array.sort() and how out-of-order the items are to
> begin with, this means a likely minimum number of extra function calls is
> the number of rows in the table, and the actual number could be much, much
> greater.
>>
>> For the new (to-be-named) enhanced table model which I recently submitted
>> as
>> an enhancement, this is a trivial change.
>>
>> The only question is whether we want to do anything to avoid breaking
>> existing code as this will constitute an API change.
>
> See my proposed implementation that handles this and associated comments in
> bug #2553:
>   http://bugzilla.qooxdoo.org/show_bug.cgi?id=2553
>
> Derrell
>
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> qooxdoo-devel mailing list
> qooxdoo-devel@...
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@...
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel



--
The trick to education is to teach people in such a way that they don't realize they're learning until it's too late.
 - Harold Eugene "Doc" Edgerton ("Poppa Flash"), 1903-1990, fabled MIT professor and inventor of the stroboscopic flash


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@...
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel