Does ASH have a way of testing value inclusion in ordered collections?

five35

New member
I need to create a collection which I can iterate over in a specific order as well as test for inclusion. Because maps always sort by key and can't be tested for value inclusion (that I know of; I'm very new to ASH scripting), I haven't been able to implement this as a single data structure. Instead, I'm currently using two; one for iteration order and another for inclusion testing (see below). Is there a way around this?

Code:
string[3] MY_DATA_ORDERED;

MY_DATA_ORDERED[0] = "First";
MY_DATA_ORDERED[1] = "Second";
MY_DATA_ORDERED[2] = "Third";

boolean[string] MY_DATA;

foreach index in MY_DATA_ORDERED MY_DATA[MY_DATA_ORDERED[index]] = true;

// Now I can iterate in order:
foreach index in MY_DATA_ORDERED print(MY_DATA_ORDERED[index]);

// Or test for inclusion:
if (MY_DATA contains "Second") print("All is well.");
if (MY_DATA contains "Fourth") print("Something screwy is going on!");
 
Last edited:

heeheehee

Developer
Staff member
Sort of.

Plural typed constants are technically ArrayLists under the hood, and iteration order is the same as definition order.

e.g.

Code:
boolean [string] foo = $strings[a,b,c,a];

foreach s in foo {
	print(s);
}

print(foo contains "a");

> call test.ash
a
b
c
a
true

That said, if you want to work with a dynamic array, building an inverted index (or something similar, e.g. what you're doing) is the most "obvious" way to solve your problem (assuming your map value is a primitive type).
 

five35

New member
Interesting! I had no idea plural typed constants could be used that way. I'll dig into them and see if I can come up with something that's easier to read than what I have now.

Thanks!
 
Top