CommaToast
CommaToast

Reputation: 12248

Which languages support multi-key associative arrays?

Which languages support non-scalar associative array keys?

I want to make an array like:

[key1,key2,key3,key4]=>[object]

I guess I'd be satisfied if the multiple keys had to each be scalars, although bonus points if they can be any data type.

Upvotes: 0

Views: 189

Answers (2)

George Phillips
George Phillips

Reputation: 4654

I don't know of any that support them directly. Perl does allow multiple scalar keys in its associative arrays via $var{$key1, $key2} but all that does is automatically concatenate the two values into a larger one and is equivalent to $var{"$key1$;$key2"}. $; is "\034" so there will be unexpected collisions if your key strings contain that value.

The same trick could be applied in any language by serializing the more complex data type into a single string.

Upvotes: 0

Luis Alves
Luis Alves

Reputation: 1286

What you are looking for is called hash tables (or hashmaps). You can implement them in most languages. Some languages already have support for hash tables like c++, java, lisp, python ...

Here are some references for some languages:

Also, from personal experience I found out that they are extreamly easy to work in lisp.

Upvotes: 1

Related Questions