ircd:Ⓜ️:event: Add exists_count() convenience; simplify various popcounts.
This commit is contained in:
parent
e621e20afc
commit
dc873d8c8f
|
@ -26,6 +26,7 @@ namespace ircd::m
|
|||
|
||||
// parallel util; returns bitset
|
||||
uint64_t exists(const vector_view<const id::event> &);
|
||||
size_t exists_count(const vector_view<const id::event> &);
|
||||
|
||||
// Equality tests the event_id only! know this.
|
||||
bool operator==(const event &a, const event &b);
|
||||
|
|
|
@ -1044,6 +1044,23 @@ ircd::m::operator==(const event &a, const event &b)
|
|||
return a.event_id == b.event_id;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::exists_count(const vector_view<const id::event> &event_ids)
|
||||
{
|
||||
const auto mask
|
||||
{
|
||||
exists(event_ids)
|
||||
};
|
||||
|
||||
const auto ret
|
||||
{
|
||||
__builtin_popcountl(mask)
|
||||
};
|
||||
|
||||
assert(size_t(ret) <= event_ids.size());
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
ircd::m::exists(const vector_view<const id::event> &event_ids)
|
||||
{
|
||||
|
|
|
@ -87,17 +87,12 @@ const
|
|||
return auth_event(i++);
|
||||
});
|
||||
|
||||
const auto mask
|
||||
{
|
||||
m::exists({ids, i})
|
||||
};
|
||||
|
||||
const auto ret
|
||||
{
|
||||
__builtin_popcountl(mask)
|
||||
m::exists_count({ids, i})
|
||||
};
|
||||
|
||||
assert(size_t(ret) <= max && size_t(ret) <= auth_events_count());
|
||||
assert(ret <= max && ret <= auth_events_count());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -114,17 +114,12 @@ const
|
|||
return prev_event(i++);
|
||||
});
|
||||
|
||||
const auto mask
|
||||
{
|
||||
m::exists({ids, i})
|
||||
};
|
||||
|
||||
const auto ret
|
||||
{
|
||||
__builtin_popcountl(mask)
|
||||
m::exists_count({ids, i})
|
||||
};
|
||||
|
||||
assert(size_t(ret) <= max && size_t(ret) <= prev_events_count());
|
||||
assert(ret <= max && ret <= prev_events_count());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue