Array of idNumbers, or collection of objects?

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Array of idNumbers, or collection of objects?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:10 pm

by pillick >> Fri, 26 Jul 2002 2:43:20 GMT

Say I have an object with many fields, one of which is the field idNumber. I have a collection class for this object, which uses idNumber as the primary key.

For one of my processes, the only part of the object I am interested in is the idNumber. Should I use a collection of the objects themselves, or just use an array of the idnumbers?

The collections or arrays have to be stored persistantly. So I am worried about the amount of space to store each of these, as well as the preformance of searching for particular idNumbers.

So which should I use?

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Array of idNumbers, or collection of objects?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:10 pm

by cdshearer >> Fri, 26 Jul 2002 3:44:08 GMT

Hi

If you use an array, with just the idNumbers in it, you will have to do some sort of search on it - most likely a sequential search (although if you keep it sorted, you could do a binary search, but you'd have to write it yourself).

If you use a collection then you'd be doing a keyed lookup - if you're looking up the object based upon the idNumber, presumeably you already know the idNumber, so you just want to know whether the object exists or not. So you'd be doing something like:

if allXxxxObjectsByIdNumber[idNumber] <> null then
// ...

The only object involved in the lookup is the dictionary itself. JADE won't need to load the object as you never reference its fields. So, this will be fast.

Craig


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 36 guests