Re: [Bro-Dev] set and vector operators

2018-04-25 Thread Vern Paxson
Hmmm thinking about it, we can get away with '&' with minimal keyword
conflict because there's such an easy (and natural-to-presume) fix -
namely, rather than "x" you use "x & attrkeyword".  Now
there's no problem, since the lexer only recognizes ""
as a unit, with no whitespace allowed.

Given that, here's my updated proposal, with 'c' standing for values of
type count:

s1 + s2 Set union
s1 - s2 Set difference
s1 | s2 Set union
s1 & s2 Set intersection
s1 ^ s2 Set symmetric difference

s + e   The set resulting from adding the element 'e' to
the set 's'
s - e   The set resulting from removing the element 'e' from
the set 's', if present

s1 {+=, -=, |=, &=, ^=} s2
Perform the corresponding set operation between
s1 and s2 and put the result in s1.
s {+=, -=} e
Add or remove the element e from the set s

c1 | c2
c1 & c2 Bitwise or/and/xor of two count values
c1 ^ c2 

c1 {|=, &=, ^=} c2
Perform the corresponding bitwise operation between
c1 and c2 and put the result in c1.

v += e  Append the element 'e' to the vector 'v'

s += v  Add the elements of 'v' to 's'
s -= v  Remove the elements of 'v' from 's', if present

How does that sound?

Vern
___
bro-dev mailing list
bro-dev@bro.org
http://mailman.icsi.berkeley.edu/mailman/listinfo/bro-dev


Re: [Bro-Dev] set and vector operators

2018-04-25 Thread Vern Paxson
> On Wed, Apr 25, 2018 at 10:40 -0700, you wrote:
> 
> > s1 + s2 Set union (for sets of the same type, of course)
> > s1 || s2Set union
> 
> (What's the difference between the two? Or do you mean either one or
> the other?)

No difference.  It just seems to me that we need something for intersection,
and using existing operators, the natural for that is "&&".  Once we have
that, might as well support "||" for union.  But given symmetry with other
operators, "+" should work too.

> Like Justin, I was also thinking "|" and "&" might be more intuitive.

If we didn't have the keyword issue with , then I could see that.
But that strikes me as a significant drawback.  (Also, if we do add these,
then a user might reasonably expect them to work bitwise for count's.  We
could then consider implementing that too I guess.)

> other languages mgiht also coerce set operands into booleans in such a
> context, so that, e.g., "s1 || s2" evaluates to true if either is
> non-empty. 

Hey I don't care about other seriously busted languages! ;-)

> I see the problem with the parser but maybe adding keywords is the way
> to go.

Yuck.

> > s += e  Add the element 'e' to set 's'
> > (same as the current "add s[e]")
> > s -= e  Remove the 'e' element from 's', if present
> > (same as the current "delete s[e]")
> 
> I'd skip these. I don't think we should add an additional set of
> operators for things that Bro already supports

I actually feel the opposite, that "add" is clunky ("delete" a bit less so)
and thus these are more natural.  But in particular it seems we ought to
support these due to needing to support "v += e" (which is the one that
I most want!).

> > s1 += s2Same as "s1 = s1 + s2"
> 
> (Or s1 |= s2 if we pick "|" for union.)

Yeah, if we bite off the '&'-keyword ugliness.  Ugh.

> > v += e  Append the element 'e' to the vector 'v'
> 
> That's probably the most requested Bro operator ever! :)

Yee-up, per my note above!

> > v += s  Append the elements of 's' to the vector 'v',
> > with the order not being defined
> 
> This one I'm unsure about. The point about the order being undefined
> seems odd. If I don't care about order, wouldn't I stay with a set?

I do have a use case, but I agree it's odd; let me revisit it to see if
I really do need it.  I might instead settle for "vector of set[xxx]".

Vern
___
bro-dev mailing list
bro-dev@bro.org
http://mailman.icsi.berkeley.edu/mailman/listinfo/bro-dev


Re: [Bro-Dev] set and vector operators

2018-04-25 Thread Robin Sommer


On Wed, Apr 25, 2018 at 10:40 -0700, you wrote:

>   s1 + s2 Set union (for sets of the same type, of course)
>   s1 || s2Set union

(What's the difference between the two? Or do you mean either one or
the other?)

Like Justin, I was also thinking "|" and "&" might be more intuitive.
"||"/"&&" is really typically associated with boolean contexts, and
other languages mgiht also coerce set operands into booleans in such a
context, so that, e.g., "s1 || s2" evaluates to true if either is
non-empty. 

I see the problem with the parser but maybe adding keywords is the way
to go.

>   s += e  Add the element 'e' to set 's'
>   (same as the current "add s[e]")
>   s -= e  Remove the 'e' element from 's', if present
>   (same as the current "delete s[e]")

I'd skip these. I don't think we should add an additional set of
operators for things that Bro already supports, that's seems confusing
to me (like Perl :)

>   s1 += s2Same as "s1 = s1 + s2"

(Or s1 |= s2 if we pick "|" for union.)

>   v += e  Append the element 'e' to the vector 'v'

That's probably the most requested Bro operator ever! :)

>   v += s  Append the elements of 's' to the vector 'v',
>   with the order not being defined

This one I'm unsure about. The point about the order being undefined
seems odd. If I don't care about order, wouldn't I stay with a set?

Robin

-- 
Robin Sommer * ICSI/LBNL * ro...@icir.org * www.icir.org/robin
___
bro-dev mailing list
bro-dev@bro.org
http://mailman.icsi.berkeley.edu/mailman/listinfo/bro-dev


Re: [Bro-Dev] set and vector operators

2018-04-25 Thread Azoff, Justin S

> On Apr 25, 2018, at 1:40 PM, Vern Paxson  wrote:
> 
> I'm working on some scripts that use sets and vectors, sometimes together,
> and am finding it clunky that Bro doesn't offer much in the way of operators
> for this.  To that end, I'm thinking of implementing some along the following
> lines, where values starting with 's' are sets, 'v' are vectors, and 'e'
> are type-compatible elements:
> 
>   s1 + s2 Set union (for sets of the same type, of course)
>   s1 || s2Set union
> 
>   s1 && s2Set intersection
>   s1 - s2 Set difference
> 
>   s += e  Add the element 'e' to set 's'
>   (same as the current "add s[e]")
>   s -= e  Remove the 'e' element from 's', if present
>   (same as the current "delete s[e]")
> 
>   s1 += s2Same as "s1 = s1 + s2"
>   s1 -= s2Same as "s1 = s1 - s2"
> 
>   v += e  Append the element 'e' to the vector 'v'
>   v += s  Append the elements of 's' to the vector 'v',
>   with the order not being defined
> 
>   s += v  Add the elements of 'v' to 's'
>   s -= v  Remove the elements of 'v' from 's', if present
> 
> These strike me as pretty straightforward, but please chime in if you
> have comments!

That's very similar to what python does, except they use & and | instead of && 
and ||.
I think they do that because 'set or' is closer to 'bitwise or' than 'logical 
or'

They also use ^ for symmetric difference.

>>> a=set([1,2,3])
>>> b=set([2,3,4])
>>> a & b
{2, 3}
>>> a | b
{1, 2, 3, 4}
>>> a - b
{1}
>>> b - a
{4}
>>> a ^ b
{1, 4}



— 
Justin Azoff



___
bro-dev mailing list
bro-dev@bro.org
http://mailman.icsi.berkeley.edu/mailman/listinfo/bro-dev


Re: [Bro-Dev] set and vector operators

2018-04-25 Thread Vern Paxson
> That's very similar to what python does, except they use & and | instead of 
> && and ||.
> I think they do that because 'set or' is closer to 'bitwise or' than 'logical 
> or'

Yeah, I thought of that, but Bro currently doesn't have any '&' or '|'
operators, which makes me reluctant to add them just for this.  '&' is
particularly problematic, as it would introduce ambiguity as to whether
"" means the redef attribute, or "use the 'and' operator on the value
of the variable 'redef'".  We'd have to add a bunch of reserved words
to accommodate this.

> They also use ^ for symmetric difference.

(same here re being a new operator)

Vern
___
bro-dev mailing list
bro-dev@bro.org
http://mailman.icsi.berkeley.edu/mailman/listinfo/bro-dev


[Bro-Dev] set and vector operators

2018-04-25 Thread Vern Paxson
I'm working on some scripts that use sets and vectors, sometimes together,
and am finding it clunky that Bro doesn't offer much in the way of operators
for this.  To that end, I'm thinking of implementing some along the following
lines, where values starting with 's' are sets, 'v' are vectors, and 'e'
are type-compatible elements:

s1 + s2 Set union (for sets of the same type, of course)
s1 || s2Set union

s1 && s2Set intersection
s1 - s2 Set difference

s += e  Add the element 'e' to set 's'
(same as the current "add s[e]")
s -= e  Remove the 'e' element from 's', if present
(same as the current "delete s[e]")

s1 += s2Same as "s1 = s1 + s2"
s1 -= s2Same as "s1 = s1 - s2"

v += e  Append the element 'e' to the vector 'v'
v += s  Append the elements of 's' to the vector 'v',
with the order not being defined

s += v  Add the elements of 'v' to 's'
s -= v  Remove the elements of 'v' from 's', if present

These strike me as pretty straightforward, but please chime in if you
have comments!

Vern
___
bro-dev mailing list
bro-dev@bro.org
http://mailman.icsi.berkeley.edu/mailman/listinfo/bro-dev