mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 05:58:20 +00:00
Update all BIFs to return IntrusivePtr instead of Val*
This commit is contained in:
parent
d7be84de97
commit
094d6de979
34 changed files with 275 additions and 281 deletions
|
@ -37,7 +37,7 @@ function bloomfilter_basic_init%(fp: double, capacity: count,
|
|||
if ( fp < 0.0 || fp > 1.0 )
|
||||
{
|
||||
reporter->Error("false-positive rate must take value between 0 and 1");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t cells = BasicBloomFilter::M(fp, capacity);
|
||||
|
@ -46,7 +46,7 @@ function bloomfilter_basic_init%(fp: double, capacity: count,
|
|||
name->Len());
|
||||
const Hasher* h = new DoubleHasher(optimal_k, seed);
|
||||
|
||||
return new BloomFilterVal(new BasicBloomFilter(h, cells));
|
||||
return make_intrusive<BloomFilterVal>(new BasicBloomFilter(h, cells));
|
||||
%}
|
||||
|
||||
## Creates a basic Bloom filter. This function serves as a low-level
|
||||
|
@ -74,19 +74,19 @@ function bloomfilter_basic_init2%(k: count, cells: count,
|
|||
if ( k == 0 )
|
||||
{
|
||||
reporter->Error("number of hash functions must be non-negative");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
if ( cells == 0 )
|
||||
{
|
||||
reporter->Error("number of cells must be non-negative");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Hasher::seed_t seed = Hasher::MakeSeed(name->Len() > 0 ? name->Bytes() : 0,
|
||||
name->Len());
|
||||
const Hasher* h = new DoubleHasher(k, seed);
|
||||
|
||||
return new BloomFilterVal(new BasicBloomFilter(h, cells));
|
||||
return make_intrusive<BloomFilterVal>(new BasicBloomFilter(h, cells));
|
||||
%}
|
||||
|
||||
## Creates a counting Bloom filter.
|
||||
|
@ -118,7 +118,7 @@ function bloomfilter_counting_init%(k: count, cells: count, max: count,
|
|||
if ( max == 0 )
|
||||
{
|
||||
reporter->Error("max counter value must be greater than 0");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Hasher::seed_t seed = Hasher::MakeSeed(name->Len() > 0 ? name->Bytes() : 0,
|
||||
|
@ -130,7 +130,7 @@ function bloomfilter_counting_init%(k: count, cells: count, max: count,
|
|||
while ( max >>= 1 )
|
||||
++width;
|
||||
|
||||
return new BloomFilterVal(new CountingBloomFilter(h, cells, width));
|
||||
return make_intrusive<BloomFilterVal>(new CountingBloomFilter(h, cells, width));
|
||||
%}
|
||||
|
||||
## Adds an element to a Bloom filter.
|
||||
|
@ -155,7 +155,7 @@ function bloomfilter_add%(bf: opaque of bloomfilter, x: any%): any
|
|||
else
|
||||
bfv->Add(x);
|
||||
|
||||
return 0;
|
||||
return nullptr;
|
||||
%}
|
||||
|
||||
## Retrieves the counter for a given element in a Bloom filter.
|
||||
|
@ -201,7 +201,7 @@ function bloomfilter_clear%(bf: opaque of bloomfilter%): any
|
|||
if ( bfv->Type() ) // Untyped Bloom filters are already empty.
|
||||
bfv->Clear();
|
||||
|
||||
return 0;
|
||||
return nullptr;
|
||||
%}
|
||||
|
||||
## Merges two Bloom filters.
|
||||
|
@ -230,10 +230,10 @@ function bloomfilter_merge%(bf1: opaque of bloomfilter,
|
|||
! same_type(bfv1->Type(), bfv2->Type()) )
|
||||
{
|
||||
reporter->Error("incompatible Bloom filter types");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return BloomFilterVal::Merge(bfv1, bfv2).release();
|
||||
return BloomFilterVal::Merge(bfv1, bfv2);
|
||||
%}
|
||||
|
||||
## Returns a string with a representation of a Bloom filter's internal
|
||||
|
@ -245,5 +245,5 @@ function bloomfilter_merge%(bf1: opaque of bloomfilter,
|
|||
function bloomfilter_internal_state%(bf: opaque of bloomfilter%): string
|
||||
%{
|
||||
BloomFilterVal* bfv = static_cast<BloomFilterVal*>(bf);
|
||||
return new StringVal(bfv->InternalState());
|
||||
return make_intrusive<StringVal>(bfv->InternalState());
|
||||
%}
|
||||
|
|
|
@ -113,7 +113,7 @@ function hll_cardinality_estimate%(handle: opaque of cardinality%): double
|
|||
|
||||
double estimate = h->Size();
|
||||
|
||||
return new Val(estimate, TYPE_DOUBLE);
|
||||
return make_intrusive<Val>(estimate, TYPE_DOUBLE);
|
||||
%}
|
||||
|
||||
## Copy a HLL cardinality counter.
|
||||
|
|
|
@ -36,7 +36,7 @@ function topk_add%(handle: opaque of topk, value: any%): any
|
|||
probabilistic::TopkVal* h = (probabilistic::TopkVal*) handle;
|
||||
h->Encountered(value);
|
||||
|
||||
return 0;
|
||||
return nullptr;
|
||||
%}
|
||||
|
||||
## Get the first *k* elements of the top-k data structure.
|
||||
|
@ -53,7 +53,7 @@ function topk_get_top%(handle: opaque of topk, k: count%): any_vec
|
|||
%{
|
||||
assert(handle);
|
||||
probabilistic::TopkVal* h = (probabilistic::TopkVal*) handle;
|
||||
return h->GetTopK(k);
|
||||
return IntrusivePtr{AdoptRef{}, h->GetTopK(k)};
|
||||
%}
|
||||
|
||||
## Get an overestimated count of how often a value has been encountered.
|
||||
|
@ -157,7 +157,7 @@ function topk_merge%(handle1: opaque of topk, handle2: opaque of topk%): any
|
|||
|
||||
h1->Merge(h2);
|
||||
|
||||
return 0;
|
||||
return nullptr;
|
||||
%}
|
||||
|
||||
## Merge the second top-k data structure into the first and prunes the final
|
||||
|
@ -183,5 +183,5 @@ function topk_merge_prune%(handle1: opaque of topk, handle2: opaque of topk%): a
|
|||
|
||||
h1->Merge(h2, true);
|
||||
|
||||
return 0;
|
||||
return nullptr;
|
||||
%}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue