mirror of
https://github.com/zeek/zeek.git
synced 2025-10-12 03:28:19 +00:00
Switch TopkVal to store IntrusivePtr<BroType>
This commit is contained in:
parent
43f513ca44
commit
d35e5520f8
2 changed files with 14 additions and 17 deletions
|
@ -23,12 +23,12 @@ Element::~Element()
|
||||||
Unref(value);
|
Unref(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopkVal::Typify(BroType* t)
|
void TopkVal::Typify(IntrusivePtr<BroType> t)
|
||||||
{
|
{
|
||||||
assert(!hash && !type);
|
assert(!hash && !type);
|
||||||
type = t->Ref();
|
type = std::move(t);
|
||||||
auto tl = make_intrusive<TypeList>(IntrusivePtr{NewRef{}, t});
|
auto tl = make_intrusive<TypeList>(type);
|
||||||
tl->Append({NewRef{}, t});
|
tl->Append(type);
|
||||||
hash = new CompositeHash(std::move(tl));
|
hash = new CompositeHash(std::move(tl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ TopkVal::TopkVal(uint64_t arg_size) : OpaqueVal(topk_type)
|
||||||
elementDict = new PDict<Element>;
|
elementDict = new PDict<Element>;
|
||||||
elementDict->SetDeleteFunc(topk_element_hash_delete_func);
|
elementDict->SetDeleteFunc(topk_element_hash_delete_func);
|
||||||
size = arg_size;
|
size = arg_size;
|
||||||
type = nullptr;
|
|
||||||
numElements = 0;
|
numElements = 0;
|
||||||
pruned = false;
|
pruned = false;
|
||||||
hash = nullptr;
|
hash = nullptr;
|
||||||
|
@ -55,7 +54,6 @@ TopkVal::TopkVal() : OpaqueVal(topk_type)
|
||||||
elementDict = new PDict<Element>;
|
elementDict = new PDict<Element>;
|
||||||
elementDict->SetDeleteFunc(topk_element_hash_delete_func);
|
elementDict->SetDeleteFunc(topk_element_hash_delete_func);
|
||||||
size = 0;
|
size = 0;
|
||||||
type = nullptr;
|
|
||||||
numElements = 0;
|
numElements = 0;
|
||||||
hash = nullptr;
|
hash = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +71,6 @@ TopkVal::~TopkVal()
|
||||||
bi++;
|
bi++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Unref(type);
|
|
||||||
delete hash;
|
delete hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +91,7 @@ void TopkVal::Merge(const TopkVal* value, bool doPrune)
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( ! same_type(type, value->type) )
|
if ( ! same_type(type.get(), value->type.get()) )
|
||||||
{
|
{
|
||||||
reporter->Error("Cannot merge top-k elements of differing types.");
|
reporter->Error("Cannot merge top-k elements of differing types.");
|
||||||
return;
|
return;
|
||||||
|
@ -199,8 +196,8 @@ VectorVal* TopkVal::GetTopK(int k) const // returns vector
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto vector_index = make_intrusive<TypeList>(IntrusivePtr{NewRef{}, type});
|
auto vector_index = make_intrusive<TypeList>(type);
|
||||||
vector_index->Append({NewRef{}, type});
|
vector_index->Append(type);
|
||||||
auto v = make_intrusive<VectorType>(std::move(vector_index));
|
auto v = make_intrusive<VectorType>(std::move(vector_index));
|
||||||
auto t = make_intrusive<VectorVal>(std::move(v));
|
auto t = make_intrusive<VectorVal>(std::move(v));
|
||||||
|
|
||||||
|
@ -284,9 +281,9 @@ void TopkVal::Encountered(Val* encountered)
|
||||||
// ok, let's see if we already know this one.
|
// ok, let's see if we already know this one.
|
||||||
|
|
||||||
if ( numElements == 0 )
|
if ( numElements == 0 )
|
||||||
Typify(encountered->GetType().get());
|
Typify(encountered->GetType());
|
||||||
else
|
else
|
||||||
if ( ! same_type(type, encountered->GetType().get()) )
|
if ( ! same_type(type.get(), encountered->GetType().get()) )
|
||||||
{
|
{
|
||||||
reporter->Error("Trying to add element to topk with differing type from other elements");
|
reporter->Error("Trying to add element to topk with differing type from other elements");
|
||||||
return;
|
return;
|
||||||
|
@ -416,7 +413,7 @@ broker::expected<broker::data> TopkVal::DoSerialize() const
|
||||||
|
|
||||||
if ( type )
|
if ( type )
|
||||||
{
|
{
|
||||||
auto t = SerializeType(type);
|
auto t = SerializeType(type.get());
|
||||||
if ( ! t )
|
if ( ! t )
|
||||||
return broker::ec::invalid_data;
|
return broker::ec::invalid_data;
|
||||||
|
|
||||||
|
@ -484,7 +481,7 @@ bool TopkVal::DoUnserialize(const broker::data& data)
|
||||||
if ( ! t )
|
if ( ! t )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Typify(t.get());
|
Typify(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t i = 0;
|
uint64_t i = 0;
|
||||||
|
@ -505,7 +502,7 @@ bool TopkVal::DoUnserialize(const broker::data& data)
|
||||||
for ( uint64_t j = 0; j < *elements_count; j++ )
|
for ( uint64_t j = 0; j < *elements_count; j++ )
|
||||||
{
|
{
|
||||||
auto epsilon = caf::get_if<uint64_t>(&(*v)[idx++]);
|
auto epsilon = caf::get_if<uint64_t>(&(*v)[idx++]);
|
||||||
auto val = bro_broker::data_to_val((*v)[idx++], type);
|
auto val = bro_broker::data_to_val((*v)[idx++], type.get());
|
||||||
|
|
||||||
if ( ! (epsilon && val) )
|
if ( ! (epsilon && val) )
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -161,9 +161,9 @@ private:
|
||||||
*
|
*
|
||||||
* @param t type that is tracked
|
* @param t type that is tracked
|
||||||
*/
|
*/
|
||||||
void Typify(BroType* t);
|
void Typify(IntrusivePtr<BroType> t);
|
||||||
|
|
||||||
BroType* type;
|
IntrusivePtr<BroType> type;
|
||||||
CompositeHash* hash;
|
CompositeHash* hash;
|
||||||
std::list<Bucket*> buckets;
|
std::list<Bucket*> buckets;
|
||||||
PDict<Element>* elementDict;
|
PDict<Element>* elementDict;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue