how to select datastructure?

  • Thread starter Thread starter ×ורי
  • Start date Start date
×

×ורי

hii all

I am using in my win apllications some data objects. manager can have many
employees.
I am not sure how to store the employees. is the best way by dictionary(by
manager id)?
what is the best data structure :I want it by the bestpractise and also to
have fast way to get emp by manager.
thanks
 
hii all

I am using in my win apllications some data objects. manager can have many
employees.
I am not sure how to store the employees. is the best way by dictionary(by
manager id)?
what is the best data structure :I want it by the bestpractise and also to
have fast way to get emp by manager.
thanks

For that particular use case a Dictionary<Manager, Employee> would be
a good fit. But, in general, there is no one-size-fits-all data
structure for doing this sort of thing. In fact, you may want to
consider using different data structures for different use cases.
There are a lot of factors to consider so it's impossible to give one
broad general recommendation.
 
×ורי said:
I am using in my win apllications some data objects. manager can have many
employees.
I am not sure how to store the employees. is the best way by dictionary(by
manager id)?
what is the best data structure :I want it by the bestpractise and also to
have fast way to get emp by manager.

Dictionary<Manager,List<Employee>>

Arne
 
Brian said:
For that particular use case a Dictionary<Manager, Employee> would be
a good fit.

No. It does not support "manager can have many employees".

Dictionary<Manager, List<Employee>> does.

Arne
 
what is the key?
if I understand right, th efirst value is the key. can a object(like
manager) be the key?
thanks
 
what is the key?
if I understand right, th efirst value is the key. can a object(like
manager) be the key?
thanks

Sure, as long as it overrides Equals and GetHashCode. You could also
use the integer id of the Manager as well. I prefer the first method
because it makes it unambiguously clear regarding the purpose of the
dictionary.
 
I will read about getHashCode
what is the best way to fill up the dictionary, if in the db there are 2
tables?(one for emp, with managerid as foraight key, and managers table)
I am using ms acess db . is the best way to bring as 2 tables?or joined table?
thanks!!
 
×ורי said:
what is the key?
if I understand right, th efirst value is the key. can a object(like
manager) be the key?

Yes.

But you need to design for it to get consistent behavior.

Arne
 
Back
Top