mirror of
https://github.com/matrix-construct/construct
synced 2024-06-08 04:58:58 +02:00
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
|
// parallel util; returns bitset
|
||||||
uint64_t exists(const vector_view<const id::event> &);
|
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.
|
// Equality tests the event_id only! know this.
|
||||||
bool operator==(const event &a, const event &b);
|
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;
|
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
|
uint64_t
|
||||||
ircd::m::exists(const vector_view<const id::event> &event_ids)
|
ircd::m::exists(const vector_view<const id::event> &event_ids)
|
||||||
{
|
{
|
||||||
|
|
|
@ -87,17 +87,12 @@ const
|
||||||
return auth_event(i++);
|
return auth_event(i++);
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto mask
|
|
||||||
{
|
|
||||||
m::exists({ids, i})
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto ret
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,17 +114,12 @@ const
|
||||||
return prev_event(i++);
|
return prev_event(i++);
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto mask
|
|
||||||
{
|
|
||||||
m::exists({ids, i})
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto ret
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue