ircd:Ⓜ️:event: Add exists_count() convenience; simplify various popcounts.

This commit is contained in:
Jason Volk 2023-02-05 13:25:45 -08:00
parent e621e20afc
commit dc873d8c8f
4 changed files with 22 additions and 14 deletions

View File

@ -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);

View File

@ -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)
{

View File

@ -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;
}

View File

@ -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;
}