user1673206
user1673206

Reputation: 1711

defining a map with value as array

how can I define a map, so the key is uint32 and the value is array of int32?

there is an option to define that valueSet but keySet has to be also defined with it.

I need a single key to array of integers. I will be happy for example.

thanks in advanced.

EDIT value as struct is ok also

Upvotes: 0

Views: 53

Answers (1)

Some Guy
Some Guy

Reputation: 1797

You can specify the KeyType when creating your map but if you have values of different sizes you have to keep ValueType as any. For example:

mapObj = containers.Map('KeyType','uint32','ValueType','any')
mapObj(2) = int32([1 2 3 4])
>> mapObj(2)

ans =

       1           2           3           4

Obviously the downside is that you can specify some key to take a value of a different type too. Like:

mapObj(3) = 'name'

But I can't imagine this being any real issue in your program. Also a ValueType of struct is not supported yet so you are better off keeping your values as arrays.

Upvotes: 1

Related Questions