I find myself in a scenario where I need to manage a queue of objects, keeping them in the order they were added to the list, while being able to remove them by their key without causing a null pointer or array out of bounds exception to occur. It seems like the OrderedDictionary object is ideal, but it doesn’t exist in the version of Mono that comes with Unity 2.6, so I need to either make it from scratch or find an alternative data structure that will accommodate the functionality I need.
The easiest way to do such a thing is just implement a heap. Requires to write 3 rather simple methods and a private array, thats it
basing on that you can implement a small priority queue and you are fine to go
I’m still really confused about how to go about making this data structure and could use a little more information or references. All the examples I am finding seem too complex or simply incomplete and don’t make sense to me. I am going to have to present this project on Monday morning, so it’s beginning to stress me out as this is really holding up the rest of my development progress.
I am adding a numeric key and an object that it pertains to as an entry to the SortedList. I was expecting it to work like a FIFO queue with the additional ability to remove key/value pairs from somewhere in the middle of the list and automatically resize to prevent index out of range exceptions. HOWEVER, it seems that by default it is sorting the entire list alphanumerically by key every time a new key/value pair is inserted. I found this under the remarks of the GetKey method in the msdn documentation:
“The index sequence is based on the sort sequence. When an element is added, it is inserted into SortedList in the correct sort order, and the indexing adjusts accordingly. When an element is removed, the indexing also adjusts accordingly. Therefore, the index of a specific key/value pair might change as elements are added or removed from the SortedList object.”
This is clearly NOT AT ALL what I want and has set me back by several days. PLEASE SOMEBODY SAVE ME.