Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

what is suggesting for table in memory with ability of search on two keys?

4 views
Skip to first unread message

mttc

unread,
Nov 24, 2008, 5:42:35 AM11/24/08
to
I have dynamic list (100 rec) of record (it's not come from DB) that
have some field. and I need two or more keys for quick search. let's
talk about Person record with ID and Phone. How I do that?
(in short, I looking equipollent for dotnet Datatable)

What is best?
+maintain Hashtable for each key
+make a iterate over the list

Or have another way?

Lew

unread,
Nov 24, 2008, 9:52:35 AM11/24/08
to
mttc wrote:
> I have dynamic list (100 rec) of record (it's not come from DB) that
> have some field. and I need two or more keys for quick search. let's
> talk about Person record with ID and Phone. How I do that?
> (in short, I looking equipollent for dotnet Datatable)

What is "equipollent"?

> What is best?
> +maintain Hashtable for each key

Don't use Hashtable; it's been out of date since 1998. Use HashMap or other Map.

> +make a iterate over the list
>
> Or have another way?

You might need to maintain more than one lookup structure, perhaps a pair of
HashMaps.

Write your data structures and access methods so that client code doesn't
depend on the inner implementation. That way you can switch from, say, twin
HashMaps to an iteration over a List without having to refactor other code.

--
Lew

J. Davidson

unread,
Nov 24, 2008, 11:03:29 AM11/24/08
to
Lew wrote:
> mttc wrote:
>> I have dynamic list (100 rec) of record (it's not come from DB) that
>> have some field. and I need two or more keys for quick search. let's
>> talk about Person record with ID and Phone. How I do that?
>> (in short, I looking equipollent for dotnet Datatable)
>
> What is "equipollent"?
>
>> What is best?
>> +maintain Hashtable for each key
>
> Don't use Hashtable; it's been out of date since 1998. Use HashMap or
> other Map.
>
>> +make a iterate over the list
>>
>> Or have another way?
>
> You might need to maintain more than one lookup structure, perhaps a
> pair of HashMaps.

And you might not. If the key types are all completely separate, you may
be able to get away with using a HashMap<Object,ValueType> and putting
each value in at each of its separate keys.

Encapsulate it, though, in a MultiMap class or whatever you want to call it.

- jenny

Arne Vajhøj

unread,
Nov 24, 2008, 8:43:44 PM11/24/08
to

I would start with ArrayList<Person> and if performance
needs a boost then add HashMap<Integer,Person> and
HashMap<String,Person>.

There are no problems having multiple structure
because they all only have refs to the Person
objects.

Arne

Martien Verbruggen

unread,
Nov 24, 2008, 11:42:36 PM11/24/08
to
On Mon, 24 Nov 2008 09:52:35 -0500,
Lew <no...@lewscanon.com> wrote:
> mttc wrote:
>> I have dynamic list (100 rec) of record (it's not come from DB) that
>> have some field. and I need two or more keys for quick search. let's
>> talk about Person record with ID and Phone. How I do that?
>> (in short, I looking equipollent for dotnet Datatable)
>
> What is "equipollent"?

I think the OP meant 'equivalent'.
>
Martien
--
|
Martien Verbruggen | 640K (of RAM) ought to be enough for anybody.
| -- Bill Gates, 1981
|

Roedy Green

unread,
Nov 25, 2008, 12:19:29 AM11/25/08
to
On Mon, 24 Nov 2008 02:42:35 -0800 (PST), mttc <mtcz...@yahoo.com>
wrote, quoted or indirectly quoted someone who said :

>I have dynamic list (100 rec) of record (it's not come from DB) that
>have some field. and I need two or more keys for quick search. let's
>talk about Person record with ID and Phone. How I do that?

Two HashMaps on the same set of objects.

See http://mindprod.com/jgloss/hashmap.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
"Humanity is conducting an unintended, uncontrolled, globally pervasive experiment
whose ultimate consequences could be second only to global nuclear war."
~ Environment Canada (The Canadian equivalent of the EPA on global warming)

mttc

unread,
Nov 25, 2008, 3:42:53 AM11/25/08
to
thanks for all, so for safe thread I go to use with pair of
ConcurrentHashMap.

Lew

unread,
Nov 25, 2008, 9:55:28 AM11/25/08
to
mttc wrote:
>>> (in short, I looking equipollent for dotnet Datatable)

Lew <no...@lewscanon.com> wrote:
>> What is "equipollent"?

Martien Verbruggen wrote:
> I think the OP meant 'equivalent'.

Really?

--
Lew

Martien Verbruggen

unread,
Nov 25, 2008, 5:27:32 PM11/25/08
to

Yes.

Martien
--
|
Martien Verbruggen | For heaven's sake, don't TRY to be
first...@heliotrope.com.au | cynical. It's perfectly easy to be
| cynical.

0 new messages