Move IntrusivePtr and utility methods to the zeek namespace

This commit is contained in:
Tim Wojtulewicz 2020-06-24 16:40:00 -04:00
parent 4668378d91
commit 9364e6a5b7
255 changed files with 3761 additions and 3730 deletions

View file

@ -18,11 +18,11 @@ static void topk_element_hash_delete_func(void* val)
delete e;
}
void TopkVal::Typify(IntrusivePtr<zeek::Type> t)
void TopkVal::Typify(zeek::IntrusivePtr<zeek::Type> t)
{
assert(!hash && !type);
type = std::move(t);
auto tl = make_intrusive<zeek::TypeList>(type);
auto tl = zeek::make_intrusive<zeek::TypeList>(type);
tl->Append(type);
hash = new CompositeHash(std::move(tl));
}
@ -176,14 +176,14 @@ void TopkVal::Merge(const TopkVal* value, bool doPrune)
}
}
IntrusivePtr<Val> TopkVal::DoClone(CloneState* state)
zeek::IntrusivePtr<Val> TopkVal::DoClone(CloneState* state)
{
auto clone = make_intrusive<TopkVal>(size);
auto clone = zeek::make_intrusive<TopkVal>(size);
clone->Merge(this);
return state->NewClone(this, std::move(clone));
}
IntrusivePtr<VectorVal> TopkVal::GetTopK(int k) const // returns vector
zeek::IntrusivePtr<VectorVal> TopkVal::GetTopK(int k) const // returns vector
{
if ( numElements == 0 )
{
@ -191,8 +191,8 @@ IntrusivePtr<VectorVal> TopkVal::GetTopK(int k) const // returns vector
return nullptr;
}
auto v = make_intrusive<zeek::VectorType>(type);
auto t = make_intrusive<VectorVal>(std::move(v));
auto v = zeek::make_intrusive<zeek::VectorType>(type);
auto t = zeek::make_intrusive<VectorVal>(std::move(v));
// this does no estimation if the results is correct!
// in any case - just to make this future-proof (and I am lazy) - this can return more than k.
@ -269,7 +269,7 @@ uint64_t TopkVal::GetSum() const
return sum;
}
void TopkVal::Encountered(IntrusivePtr<Val> encountered)
void TopkVal::Encountered(zeek::IntrusivePtr<Val> encountered)
{
// ok, let's see if we already know this one.

View file

@ -27,7 +27,7 @@ struct Bucket {
struct Element {
uint64_t epsilon;
IntrusivePtr<Val> value;
zeek::IntrusivePtr<Val> value;
Bucket* parent;
};
@ -55,7 +55,7 @@ public:
*
* @param value The encountered element
*/
void Encountered(IntrusivePtr<Val> value);
void Encountered(zeek::IntrusivePtr<Val> value);
/**
* Get the first *k* elements of the result vector. At the moment,
@ -66,7 +66,7 @@ public:
*
* @returns The top-k encountered elements
*/
IntrusivePtr<VectorVal> GetTopK(int k) const;
zeek::IntrusivePtr<VectorVal> GetTopK(int k) const;
/**
* Get the current count tracked in the top-k data structure for a
@ -125,7 +125,7 @@ public:
*
* @returns cloned TopkVal
*/
IntrusivePtr<Val> DoClone(CloneState* state) override;
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
DECLARE_OPAQUE_VALUE(TopkVal)
@ -153,7 +153,7 @@ private:
* @returns HashKey for value
*/
HashKey* GetHash(Val* v) const; // this probably should go somewhere else.
HashKey* GetHash(const IntrusivePtr<Val>& v) const
HashKey* GetHash(const zeek::IntrusivePtr<Val>& v) const
{ return GetHash(v.get()); }
/**
@ -161,9 +161,9 @@ private:
*
* @param t type that is tracked
*/
void Typify(IntrusivePtr<zeek::Type> t);
void Typify(zeek::IntrusivePtr<zeek::Type> t);
IntrusivePtr<zeek::Type> type;
zeek::IntrusivePtr<zeek::Type> type;
CompositeHash* hash;
std::list<Bucket*> buckets;
PDict<Element>* elementDict;

View file

@ -46,7 +46,7 @@ function bloomfilter_basic_init%(fp: double, capacity: count,
name->Len());
const Hasher* h = new DoubleHasher(optimal_k, seed);
return make_intrusive<BloomFilterVal>(new BasicBloomFilter(h, cells));
return zeek::make_intrusive<BloomFilterVal>(new BasicBloomFilter(h, cells));
%}
## Creates a basic Bloom filter. This function serves as a low-level
@ -86,7 +86,7 @@ function bloomfilter_basic_init2%(k: count, cells: count,
name->Len());
const Hasher* h = new DoubleHasher(k, seed);
return make_intrusive<BloomFilterVal>(new BasicBloomFilter(h, cells));
return zeek::make_intrusive<BloomFilterVal>(new BasicBloomFilter(h, cells));
%}
## Creates a counting Bloom filter.
@ -130,7 +130,7 @@ function bloomfilter_counting_init%(k: count, cells: count, max: count,
while ( max >>= 1 )
++width;
return make_intrusive<BloomFilterVal>(new CountingBloomFilter(h, cells, width));
return zeek::make_intrusive<BloomFilterVal>(new CountingBloomFilter(h, cells, width));
%}
## Adds an element to a Bloom filter.
@ -139,8 +139,8 @@ function bloomfilter_counting_init%(k: count, cells: count, max: count,
##
## x: The element to add.
##
## .. zeek:see:: bloomfilter_basic_init bloomfilter_basic_init2
## bloomfilter_counting_init bloomfilter_lookup bloomfilter_clear
## .. zeek:see:: bloomfilter_basic_init bloomfilter_basic_init2
## bloomfilter_counting_init bloomfilter_lookup bloomfilter_clear
## bloomfilter_merge
function bloomfilter_add%(bf: opaque of bloomfilter, x: any%): any
%{
@ -238,12 +238,12 @@ function bloomfilter_merge%(bf1: opaque of bloomfilter,
## Returns a string with a representation of a Bloom filter's internal
## state. This is for debugging/testing purposes only.
##
##
## bf: The Bloom filter handle.
##
## Returns: a string with a representation of a Bloom filter's internal state.
function bloomfilter_internal_state%(bf: opaque of bloomfilter%): string
%{
BloomFilterVal* bfv = static_cast<BloomFilterVal*>(bf);
return make_intrusive<StringVal>(bfv->InternalState());
return zeek::make_intrusive<StringVal>(bfv->InternalState());
%}

View file

@ -23,7 +23,7 @@ module GLOBAL;
function hll_cardinality_init%(err: double, confidence: double%): opaque of cardinality
%{
CardinalityCounter* c = new CardinalityCounter(err, confidence);
auto cv = make_intrusive<CardinalityVal>(c);
auto cv = zeek::make_intrusive<CardinalityVal>(c);
return cv;
%}
@ -113,7 +113,7 @@ function hll_cardinality_estimate%(handle: opaque of cardinality%): double
double estimate = h->Size();
return make_intrusive<DoubleVal>(estimate);
return zeek::make_intrusive<DoubleVal>(estimate);
%}
## Copy a HLL cardinality counter.
@ -129,7 +129,7 @@ function hll_cardinality_copy%(handle: opaque of cardinality%): opaque of cardin
CardinalityVal* cv = static_cast<CardinalityVal*>(handle);
CardinalityCounter* h = cv->Get();
CardinalityCounter* h2 = new CardinalityCounter(*h);
auto out = make_intrusive<CardinalityVal>(h2);
auto out = zeek::make_intrusive<CardinalityVal>(h2);
return out;
%}

View file

@ -14,7 +14,7 @@
## topk_size topk_sum topk_merge topk_merge_prune
function topk_init%(size: count%): opaque of topk
%{
auto v = make_intrusive<probabilistic::TopkVal>(size);
auto v = zeek::make_intrusive<probabilistic::TopkVal>(size);
return v;
%}
@ -34,7 +34,7 @@ function topk_add%(handle: opaque of topk, value: any%): any
%{
assert(handle);
probabilistic::TopkVal* h = (probabilistic::TopkVal*) handle;
h->Encountered({NewRef{}, value});
h->Encountered({zeek::NewRef{}, value});
return nullptr;
%}