> I can smell a challenge in the air ...

Ron, looks like Adam blew us all out of the water!

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Adam Cameron
Sent: Monday, 10 January 2005 1:36 PM
To: CFAussie Mailing List
Subject: [cfaussie] Re: Removing duplicates from a list

> Thanks for the tip David. The udf uses the same technique that I'm
currently using.. i.e. loop over the list and use listFind to remove
duplicates. The reason I'm looking for a simpler method is to reduce
processing time for large lists. Encapsulating it in a udf is handy though
..

This got me thinking about how much I have always hated people's (including
myself) propensity for looping over lists to do any processing of them (see
Sean's comment about how lists suck), and being left with the thought "there
*must* be a better way".

So I had a wee looksee @ the Java API (I'm a Java newbie, so any excuse to
have a gander around is welcomed, in my view).

I came up with this lot:

l1 = "somelist";
l2 = createObject("java",
"java.util.HashSet").init(listToArray(l1)).toString();

HashSets don't allow duplicates, but will accept duplicates in the
initialisation data, so intrinsically dedupe the incoming list.

There's not much performance difference between the UDF (I'm testing with
the case-sensitive one) and the HashSet methods for short lists, but the
Java method comes into its own with longer lists.

I'm building a list of UUIDs, then concatenating it onto itself.
Interestingly... the lists are taking far longer to build than either
deduping process.

20 items:
UDF: 0ms
Java: 0ms

200 items:
UDF: 0-15ms
Java: 0ms

2000 items:
UDF: 250ms
Java: 0ms

20000 items:
UDF: 26000ms
Java: 80ms

Needless to say, using lists that long is simply not the best way to go
about things from the outset, but sometimes one's hand is forced with in
these matters.

And it's always good to know that there's more than one way to skin a cat
:-)

-- 

Adam

---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to
[EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/

---
You are currently subscribed to cfaussie as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/

Reply via email to