x


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.

more ▼

asked Jun 09 '10 at 06:57 AM

newbrand gravatar image

newbrand
159 1 1 10

Any .Net class library you get will be usable in UnityScript, as that ends up compiled to the same runtime.

Jun 09 '10 at 11:22 AM Ricardo
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Jun 09 '10 at 09:13 AM

Mike 3 gravatar image

Mike 3
30.7k 10 67 256

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jun 09 '10 at 03:54 PM

Sejster gravatar image

Sejster
59 3 3 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3571
x183
x58

asked: Jun 09 '10 at 06:57 AM

Seen: 1266 times

Last Updated: Jun 09 '10 at 04:21 PM