473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Faster way to retreive records from collection by the passed key

Hi,

I would like to have a multiple key dictionary to find a value
based on the given key.

Here is the example to demonstrate what I mean.

I have an Employee class

Public class Employee

{

Int m_EmpId;

String m_EmpName;

Float m_Salary;

String m_Department;

}

Like this I have a collection of objects and I need to retrieve a record
based on the passed Employee id or employee name. Looping through an
arraylist is too slow. And there is no dictionary available to combine both
keys. So I need to maintain two dictionary classes if I want it faster.

Is there any better way to find the record faster?

Thanks in advance.

Cheers,

Venkat

Oct 26 '06 #1
2 1552
Like this I have a collection of objects and I need to retrieve a
record based on the passed Employee id or employee name. Looping
through an arraylist is too slow. And there is no dictionary available
to combine both keys. So I need to maintain two dictionary classes if
I want it faster.

Is there any better way to find the record faster?
Well, you could just add the same item to a Hashtable twice with different
keys.

Best Regards,
Dustin Campbell
Developer Express Inc.
Oct 26 '06 #2
That's probably the easiest way to do it. Probably best write it with
two Hashtables (Dictionary<>s in 2.0), and leave it like that until you
get to performance optimization.

If you have *a lot* of data, it may not be the most efficient. If you
find that you're constrained, most likely by memory but also maybe
slightly by performance, you could try one of the following:

1. Create your own collection data structure that contains a master
collection in a data structure, and parallel searchable data structures
as the indices. It's up to you to guarantee referential integrity
between the indices and the master structure. This is complicated but
will give you the best performance if you design it right.

2. Use some sort of DataSet. Various project parameters will determine
if a typed DataSet is appropriate. You'll be able to perform selects
against it based on any key. I've never used them, but I believe you
may even be able to add indices. You get the generic DataSet overhead,
but it's rather efficient in most cases.
Stephan

Dustin Campbell wrote:
Like this I have a collection of objects and I need to retrieve a
record based on the passed Employee id or employee name. Looping
through an arraylist is too slow. And there is no dictionary available
to combine both keys. So I need to maintain two dictionary classes if
I want it faster.

Is there any better way to find the record faster?

Well, you could just add the same item to a Hashtable twice with different
keys.

Best Regards,
Dustin Campbell
Developer Express Inc.
Oct 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: seberino | last post by:
I've been reading the beloved Paul Graham's "Hackers and Painters". He claims he developed a web app at light speed using Lisp and lots of macros. It got me curious if Lisp is inherently faster...
10
by: Willem | last post by:
Looking for some opinions on alternatives to programming with Access. I find that quite often I need to loop through my recordsets (first to last) performing calculations and was wondering if...
4
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a...
7
by: Michael Maes | last post by:
Hello, How would I retreive only the numbers out of a string? Regex.Replace(mString, -Expression-, "") eg: mString = "AZE|@#{1^2#{[^3ert/.?" should return '123' TIA, Michael
2
by: Quina | last post by:
Hi there, i'm building an windows application to manage my disc collection. I also want to enable it with cd recognition features on audio CDs. In order to do this I must submit the CD info...
5
by: Joris De Groote | last post by:
Hi, I have a question, wich goes faster (The table has 15000 rows in it and growing every day)? - at the start of the program run a querry and put this in a dataset and during the program...
2
by: Umut Tezduyar | last post by:
I have a control derived from ComposeteDataBoundControl. Control doesn't retreive it's state information. I am going to frick out! What should I do more? I added two codes. One is for Default.aspx...
6
by: satish mullapudi | last post by:
Hi All, I am getting strange situation. These r the steps I have followed: 1. Created an EMPLOYEE table with around 14 fields & 688038 records. (so a large table indeed). 2. Tried to delete all...
1
by: sreemathy2000 | last post by:
Hi, My requirement is to read a CSV file which has around 40,000 records and insert into DB. I have the CSV read and stored in a collection object which is passed to the Webservice. My client...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.