[Bro-Dev] set and vector operators

Jon Siwek jsiwek at corelight.com
Thu Apr 26 13:10:34 PDT 2018

On 4/26/18 11:29 AM, Vern Paxson wrote:
>> Just one more thing still: I'm actually feeling pretty strongly
>> against having multiple different operators for the same operation
>> (set union, set addition/removal).

I'm maybe convincing myself that it's at least not that useful or 
there's alternative ways forward that don't introduce redundancies.

> I'm fine with removing "add" and "delete" for sets!  (But seems we gotta
> keep them for a good while for backward compatibility.  Plus, what would
> be the remove operator for tables?  "t -= index" seems pretty weird to me.)

A nice thing about "add" and "delete" for sets is that you can infer the 
data type that you're operating on just looking at the local code/line. 
E.g. say you come back to some code after a few months and see "foo += 
1".  Not obvious what 'foo' is anymore.  Could be vector, set, or count, 

> But I don't think we should forego '+' and '-' for sets.  It would be too
> weird that "v += e" works but "s += e" does not (and "add v[e]" blows, so
> let's not consider going down that path :-P).

Yeah, I agree with that sentiment (on the condition that we did add +/- 
for sets).

I do also notice that you had "s + e" in the proposal and not "v + e". 
Isn't that weird by the same logic or is it just an accidental omission?

> Once we have s += e, we
> certainly should have s -= e.  And once we have "s + e", "s1 + s2" seems
> very natural to me too; I don't relish having to explain "oh *that* doesn't
> work, you have to use s1 | s2" :-P.

That also makes sense, though it's worth seeing what a minimal proposal 
looks like without the contentious '+' operations:

     s1 - s2, s1 -= s2    Set difference
     s1 | s2, s1 |= s2    Set union
     s1 & s2, s1 &= s2    Set intersection
     s1 ^ s2, s1 ^= s2    Set symmetric difference

     c1 | c2, c1 |= c2    Bitwise-or 'count' values
     c1 & c2, c1 &= c2    Bitwise-and 'count' values
     c1 ^ c2, c1 ^= c2    Bitwise-xor 'count' values

The only one now missing that I'd probably find myself using is:

     v += e               Append element to vector

And for that, a BiF or generic script-layer function call (if that were 
possible) would even make me happy:

     push(v, e)

That also could go back to what I was saying before about readability: 
it would then be more obvious than "v += e" regarding what data types 
are involved.

Same idea would apply to "s += v" and "s -= v" (if we were inclined):

     add_to_set(s, v)
     delete_from_set(s, v)

Could that all be an alternative way forward?  Or is it missing other 
important aspects?

- Jon

More information about the bro-dev mailing list