[Zeek] Sorting a vector of intervals.

anthony kasza anthony.kasza at gmail.com
Sat May 16 13:48:31 PDT 2020


The sort function's second argument must be a function. Below, I use an
anonymous function but you could also define and declare it. Think of this
second function as a map function which is applied to the vector you're
sorting.
Sorting is done in place, too. So you may want to add a copy() function to
your definition of vo.


event zeek_init() {
  local v: vector of interval = vector(1min,2min,1min,4min,6min,1min);
  local vo : vector of interval = sort(copy(v), function(a: interval, b:
interval): int {return a > b ? 1 : -1;} );
  for (i in vo) {
    print vo[i];
  }
}

-AK


On Sat, May 16, 2020, 13:03 Tomek Koziak <ttomek.koziak at gmail.com> wrote:

> Hi All,
> When I try to run the following code
>
> event zeek_init()
> {
> local v: vector of interval = vector(1min,2min,1min,4min,6min,1min);
> local vo : vector of interval = sort(v);
>     for (i in vo){
>     print vo[i];
>     }
> }
>
> I get the expected output by as well I obtain the following error:
> line 4: comparison function required for sort() with non-integral types
> (sort(v)) fatal error: errors occurred while initializing
>
> I have followed the documentation.
> https://docs.zeek.org/en/current/scripts/base/bif/zeek.bif.zeek.html#sort
> But I quite don't understand the part about the comparison function as a
> second argument. What parameter should be placed as a second argument?
> <https://docs.zeek.org/en/current/scripts/base/bif/zeek.bif.zeek.html#sort>
>
> Tomasz
> _______________________________________________
> Zeek mailing list
> zeek at zeek.org
> http://mailman.ICSI.Berkeley.EDU/mailman/listinfo/zeek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ICSI.Berkeley.EDU/pipermail/zeek/attachments/20200516/7df752ee/attachment.html 


More information about the Zeek mailing list