11-04-2008 08:00 AM
Can anyone tellme how to sort the ListField.
Currently I am using String collection set like below
I need to sort the items in the list.
11-04-2008 08:07 AM
Please see my earlier posts on the RIM collections and rants against databases specifically because
these are available. But, fwiw, I think Arrays with the parallel parameter was my choice ( esp if you can reduce
your dates to longs, this would be a natural):
$ grep -il "public.*sort(" *.txt
$ grep -il sort *.txt
11-04-2008 08:18 AM
11-04-2008 02:45 PM
I just got my test code to work- seems to sort 50 zip codes quite well ( at least they look like they are ordered
by how close they are to me, LOL, haven't done detailed check yet but it is easy to ask the server to return
100's of them). Anyway, I recommended and used sort with the parallel option specifically to remove the
comparator overhead. My presumption is that the long keyed sort is implemented in native code and
doesn't have the overhead of any arbitrary comparator. The pointer swaps are presumably fast.
If you have dates as keys, longs are a natural anyway. I made an index on the fly - Euclid wouldn't approve
but for a quick test I used scaled lat/long difference squared - but if you took more care and can scale
things to longs or ints and retain your key arrays, it may be worth removing the compartor overhead.
11-06-2008 05:14 AM
11-06-2008 07:36 AM
AFAIK, there are two issues: 1) the Comparator vs keys and 2) the array<->Vector conversion.
From what I have seen of list field, it is really neutral and you could write your own either way.
I'm still trying to work out the details for my "database" system but I'm probably going to make
all my gui components use arrays and write a few structs to include a target data array along with
some long index arrays and various names. The attraction of Vector is the arbitrary length that hides all
the fixed length problems. Presumably this is implemented in native code and is fast but I don't think
there are analogues of System.arraycopy etc. For sure, if you have a dynamic list, need a really wierd key computation
per pair, then a vector sort with a comparator function may be the way to go. If you have keys that reduce to longs or
ints, have a static list that is easily represented as an array, I think the array sort with parallel option is probably better.
I'm not sure what strategy SQL would use to do a high-dimensional
proximity look up, but I'm going to need things like "closes few points to randomly selected centers" and
thing I can do reasonably well making stuff up as I go along.
11-06-2008 04:33 PM
I just ran my first app having converted the listfield and related classes to use arrays, not vectors.
It hadn't occured to me but if you load these from a DOM, you have some idea on an upper bound for how many
things you will load so the size issue is not a big problem. Anyway, from creation from a DOM ( this will change when
I get my SAX handler to work) to sorting and display, the encapsulated array seems like a good way to go.
I'll be creating many indicies on the fly ( I finally got accurate spherical distance metrics for GPS
point array manipulation ) and the collections themselves have zero volatility so this may not be for
everyone but looks good in this case.
Given the RIM sorting/binsearch things where a hashtable doesn't quite get it, I think this will be a good approach for a database as all of these things are Persistable.
Implementing an SQL similar query capability doesn't seem to be that difficult.