I am trying to find an efficient way to build a cross reference in C# and I am at a loss so I thought I would ask for ideas. I have tried using a list view, concatenating the source and associated values into a single dimension array, and several other things. My problem is the list of source values is dynamic and can be quite large and everything I have tried has had performance issues.

The only requirements I have are
1) It is must be a memory option because I don't have a database in this program.
2) I can't add a source value multiple times.
3) I need to be able to retrieve the associated value later in the program.

So I don't disclose the true nature of my program, I am going to provide a ficticiuos example.
As I read a file, I need to process each letter by first seeing if it is already in the list and if not, add it and the next available number.
"this is sample data" cross references to t=1, h=2, i=3, s=4, a=5, m=6, p=7, l=8, e=9, d=10
Now I also need to be able to search for a letter such as p to retrieve the cross reference value of 7.

I will disclose that the source values are 3 dimensions coordinates (x, y, z) and there can easily be 200K+ values (many of which are duplicates) so sorting and retrieving values is not as simple as the example makes it look.

Maybe the nature of what I am trying to do will always have performance issues but I am hoping someone comes up with something that I don't know about (I'm not a C# newbie but there still are a lot of thing I don't know about) or a different way of doing it so it doesn't have performance issues.

Recommended Answers

All 2 Replies

How about a dictionary? If you're unfamiliar with dictionaries (also called associative arrays), a dictionary is a hash table of key-value pairs. Keys and values may be just about any type. In your fictitious example the key would be a char or string and the value would be an integer.

Along with what Reverend Jim is saying, since you real data is a more complex type, create a class to represent that data, it could be called Coordinates,and your dictionary would be Dictionary<string,Coordinates> If you need them sorted you can use a SortedDictionary<string,Coordinates>. The links go to the MSDN document page for each.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.