Alternatives to Dictionaries

At the moment I have data being read into my program being generated by a third party device. I am sending this over a string made up of two separate values joined together and separated by a dash and a full stop. I had initially placed this data in a dictionary using the first value as a key (as its a constant) and the second as its value as it could change at any moment.

With the dictionary I was sorting it so that the values were arranged in descending order so that the lowest value was the first entry in the dictionary, the second lowest was the second and so on. I believed this was also updating so that if the 5 entry was suddenly lower than the first, it would move its position to be the first entry of the dictionary and push everything else down one.

To sort the values I was using LINQ with the following code:

// Order by values.
var items = from pair in dictionary
            orderby pair.Value ascending
                select pair;

// Display results.
foreach (KeyValuePair<string, float> pair in items)
{
    Debug.Log(  "Key value: " + pair.Key + " Value: " + pair.Value + "\n"); 
}

By when I ran this on my iPad I was getting a JIT error in Xcode (the data is sent via a plugin from Xcode to Unity). I looked around and it turns out some LINQ functionality doesn't work well with Xcode.

Can someone please suggest another way in which I can sort my data in a similar way which doesn't rely on using LINQ?

edit I need to clarify: with the values being streamed in from a third party device, I need a way to tie to the value to its key. I have a variety of devices sending in data but they all have unique constants which I'm using to tie the value to. That way I know which reading is coming from which device.

And as I didn't say, this is the xCode message I get when I run the above code:

ExecutionEngineException: Attempting to JIT compile method 'System.Linq.OrderedEnumerable1<System.Collections.Generic.KeyValuePair2>:GetEnumerator ()' while running with --aot-only.

Answers


If you want an alternate to Dictionaries, you can use list of classes.

i.e

class ClassName
{
    public float Field1 {get; set;}
    public string Field2 {get; set;}
}

Have a look at List Class


Use a SortedList

or just use a normal List<> and call the sort. you can provide your own sorting strategy by making the items implement IComparable


I think you can make use of Tuple

 List<Tuple<string, float>> toPrint = new List<Tuple<string, float>>();

To read more on Tuples,

Tuples in c#


Need Your Help

Exclude data from being captured by loop-back mode in WASAPI

windows audio wasapi

Is it possible to exclude audio data from being captured by the IAudioClient loop-back mode (AUDCLNT_STREAMFLAGS_LOOPBACK) or to render a audio stream that will not be contained in the loop-back ca...

IE6 PNG-transparency CSS hack not working

css png internet-explorer-6

I looked around and decided to use a CSS approach rather than rely on JS... I figure the kind of corporate users stuck with IE6 might also have JS disabled by IT departments.