Jump to content
Sign in to follow this  
PolywickStudio

Set matching and fast searching in TDictionary<integer1, TDicationary<integer2, integer3>>?

Recommended Posts

Let's say you have a set of repeat numbers:

 

 TDictionary<integer1, TDicationary<integer2, integer3>>

 

[1, [2, 1]]

[1, [1, 2]]

[1, [1, 3]]

(huge... like 30000)

[2, [2, 1]]

[2, [1, 2]]

[2, [1, 3]]

...

[3, [2, 1]]

[3, [1, 2]]

[3, [1, 3]]

 

 

What would be a fast way to select all numbers with

[x, [x, 1]], then [x, [x, 2]] ?

 

 

I do a loop but there must be a faster way than loop the loop.

Share this post


Link to post

I can't help, but this looks like you are trying to make that dictionary construct work like a database.

Share this post


Link to post

Don't think of the problem as how to write the code effectively given the data structure. Think of the problem as choosing a combination of data structure and algorithm to solve your problem. In other words, ask about the underlying problem, and be prepared to consider a variety of other data structures, which in concert with the right algorithm might perform best.

  • Like 2

Share this post


Link to post

Use this

LDic: TDictionary<TPair<Integer, Integer>, Integer>;

 

To search by values of the dictionary the complexity will be O(2 * N) = O(N) by looping the LDic.Values.

Share this post


Link to post

I don't understand the original problem - please describe exactly the data in a complete but small enough sample and the way you want it to be organized/shown.

Share this post


Link to post
6 minutes ago, Stefan Glienke said:

I don't understand the original problem - please describe exactly the data in a complete but small enough sample and the way you want it to be organized/shown.

Yes, we need to know the original problem.

@PolywickStudio
Another consideration, I believe that your performance problem does not involve this search, because a loop of 60,000 items comparing integers is 0 milliseconds.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×