RE: My EuGrid improvement

new topic     » goto parent     » topic index » view thread      » older message » newer message

> > 
> 
> The solution for sorting that I have come up with is that I will 
> continue to use the built-in Euphoria sort as the default sorting 
> method.  I have fixed a bug in this which meant that the sorting 
> sometimes went awry.
> 
> However, you will be able to specify a sorting routine id at grid and/or 
> 
> at individual column level to plug in any custom sort routine that you 
> want.  I considered making nat_sort the default but one of my design 
> goals (yep I *do* have them) is to minimise dependencies on other 
> libraries.  I think that this solution is the most flexible.
> 

Yes, that is a better final solution.  One thing you might do is to put 
the nat_compare() function right in the eugrid.ew file (feel free) and 
then you could possibly have it as one of the sorts easily available 
just as a convenience thing -- just stick it in there and set a global 
constant with its routine_id.

> With regard to floating point numbers, at the moment the sort is 
> performed on the underlying data, rather than the sprintf'd 
> representation of it.  As the underlying data can be a number then as it 
> 
> stands there might be a problem in sorting fp numbers as in your 
> example.  I could modify the sort code to always convert number data to 
> formatted strings before performing the sort comparison. This would 
> inevitably slow things down slightly when sorting large datasets.  I 
> could also make this behaviour optional by a new grid/column property 
> e.g. EGW_SORT_STRING or something.
> 
> What do you think?
> 

Ah... I thought the fact that it was sorting strings instead of numbers 
was the cause of the problem for numerical columns in the first place.  
If it is sorting on the underlying set, then numerical columns should 
sort correctly using regular compare already.  I thought they weren't?

In my particular program, I have numerical columns, but they're all 
sprintf'd in advance and none of them are specified as numerical in 
EuGrid, so I need to use nat_compare_str() to get them right.


So to amend my earlier comments, if you alter the current version of 
EuGrid, you should use plain nat_compare() instead of nat_compare_str(). 
 nat_compare() will compare any two objects -- atoms or sequences -- and 
so will do numerical comparisons on the underlying set correctly (it is 
the same as compare() in that case).  The "natural order" part only 
kicks in when it is comparing two strings...

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu