Sorting a vector of intervals.

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?

Tomasz

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