- Home /
Is there an unsorted hashtable-like container?
Hello everybody,
I'm currently using a hashtable, but that doesn't fit my needs. Is there a similiar container with KeyValue pairs that does not sort it's items in any way but keeps them in the order I added them? I don't want to write a custom type unless it's neccessary because I'd also have to rewrite a lot of code. Also I can not alter the Keys to enforce a specific order. The container should be useable in javascript.
Thanks in advance.
Edit: Since I can not leave comments, I'll abuse the edit function, please forgive me :~)
@Mike: Well, that doesn't look too promising. I guess I'll have to implement my own container. Thank you for your help!
@Ricardo: Thanks for pointing that out. I was under the impression that only non-generic types work in js.
@Sejster: Enums are constant data types, but I need to alter the values. Also I can't iterate over them.
Any .Net class library you get will be usable in UnityScript, as that ends up compiled to the same runtime.
Answer by Mike 3 · Jun 09, 2010 at 09:13 AM
It may be possible that ListDictionary does what you want, though it specifically says that the order is not guaranteed over different versions of .NET, so it's possible the implementation will change
http://msdn.microsoft.com/en-us/library/system.collections.specialized.listdictionary.aspx
Answer by Sejster · Jun 09, 2010 at 03:54 PM
If your values are integers and you don't add values at runtime, then you could just do a C++-like enum in JavaScript:
var yourEnum = {"monday":1, "tuesday":2, "wednesday":3, ...}
Debug.Log("Value of monday: " + yourEnum.monday);
It's not typesafe like a C++ enum, and its restricted to string-integer pairs, but maybe that's sufficient for your needs.