Comparing like aggregates

Fluxxdog

Active member
I was wondering if Mafia had built in support for comparing aggregates, such as seeing if $items[alpha,bravo,charlie] had any matches in $items[alpha,beta,gamma] Hadn't found anything but I figured I'd ask rather than reinvent the hoverboard.

...I want my hoverboard dangit!
 

Veracity

Developer
Staff member
Sounds like you'd like "intersection( map, map )". And, presumably, "union( map, map )" and "difference( map, map )". Those are all "set" operations, but since an ASH map cannot have duplicate elements, they should be doable.

ASH does not have them. currently, but they should be doable. And probably reasonably "fun" to implement. Make a Feature Request.
 

Veracity

Developer
Staff member
I've thought about this, and it's a lot more complicated than I indicated.

- item arrays, as you used in your example, are arrays, not maps. Thus, they CAN have duplicates:

> ashq foreach it in $items[snorkel, disco ball, snorkel ] print( it )

snorkel
disco ball
snorkel

So, we'd have to convert the arrays into sets, perform the operation (intersection, union, set_difference), and turn the result back into an array.

- maps cannot have duplicate elements, but they have both a key and a value. We can do (intersection, union, set_difference) on the keyset - but which value gets stored in the resulting map? If I have two maps that map int to int, one has 2->3, the other has 2->4, what IS the (intersection, union, set_difference)? The intersection is probably empty, and the union and set_difference probably includes BOTH mappings - which is not possible with a map.

It's still an interesting problem, but it's not straightforward - and there's a fair amount of specification, needed, to define what is the correct and useful syntax and behavior. Perhaps it only would work on arrays - which is exactly what you were asking about, anyway. :)
 

Catch-22

Active member
Hmm.. Although set operation support would be nice, for simple aggregate comparison, couldn't this still be done using arrays? asList.Contains or sort then binarySearch?
 
Last edited:

Fluxxdog

Active member
Just thinking, simplest example for use would be Azazael's talismans, specifically, the Backstage. In order to ensure you have the items you need, you need 2 items out of each of two sets of three. I'll use Bognort's and Stinkface's preference's for this:
Code:
boolean[item]BogStinkWant=$items[giant marshmallow,gin-soaked blotter paper,beer-scented teddy bear]; //Bognort wants white, Stinkface wants booze
boolean[item]BogStinkHave;
foreach piece in BogStinkWant{ BogStinkHave[piece]=available_amount(piece).to_boolean();}
if(count(intersection(BogStinkHave,BogStinkWant))>=2) do_something();
And like I said, that's probably the simplest.
 
Top