Question on ash data structures

QVamp

Member
I'm having trouble figuring out how to create this data structure in an ash script.

I would like to have a list of items, with each item referring to an set of records. That is, I would essentially like something along the lines of

[item 1] => [record 1, record 2, record 3]
[item 2] => [record 4]

There is not an exact number of records that an item would refer to, so I'm not sure how to create this. The documentation mentions that there are arrays available, would this be the right way to go? If so, it looks like I'd have to declare each one at an outlandish size, so that everything would fit in it. The only other option I can think of is creating doubly-linked lists, but I'd rather not try to do that here if I don't have to. :)
 

jasonharper

Developer
Linked lists aren't even possible in ASH. No object can ever have a direct reference to another object of the same type; the lack of a null value means that such an object would require infinite memory to initialize. That could be worked around by making the links indirect - integer keys into a map, perhaps - but probably overkill for what you're trying to do.

ASH arrays are only useful if you know the exact number of elements in advance, so probably not useful either.

I'd do this as a 2-dimensional map:
[item, int] => record
where the 2nd key is basically used as an array index. Insertions would look something like this:
myMap[myItem, count(myMap[myItem])] = new myRecord(whatever)
This would give multiple entries for the same item increasing 2nd keys starting with 0.
 
Top