mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
AK: HashTable add a constructor that allows preallocation of capacity + Use in CppLexer. (#3147)
1. Add general utility to get array number of elements. 2. Add Needed API to AK::HashTable 3. Refactor CppLexer initialization
This commit is contained in:
parent
fc276946fb
commit
a68650a7b4
Notes:
sideshowbarker
2024-07-19 03:34:48 +09:00
Author: https://github.com/tryfinally
Commit: a68650a7b4
Pull-request: https://github.com/SerenityOS/serenity/pull/3147
Reviewed-by: https://github.com/awesomekling
3 changed files with 166 additions and 135 deletions
|
@ -111,7 +111,12 @@ private:
|
|||
using Bucket = SinglyLinkedList<T>;
|
||||
|
||||
public:
|
||||
HashTable() {}
|
||||
HashTable() { }
|
||||
HashTable(size_t capacity)
|
||||
: m_buckets(new Bucket[capacity])
|
||||
, m_capacity(capacity)
|
||||
{
|
||||
}
|
||||
HashTable(const HashTable& other)
|
||||
{
|
||||
ensure_capacity(other.size());
|
||||
|
@ -164,6 +169,15 @@ public:
|
|||
|
||||
HashSetResult set(const T&);
|
||||
HashSetResult set(T&&);
|
||||
|
||||
template<typename U, size_t N>
|
||||
void set_from(U (&from_array)[N])
|
||||
{
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
set(from_array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
bool contains(const T&) const;
|
||||
void clear();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue