summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorHediadyoin1 <leon2002.la@gmail.com>2023-02-21 11:30:52 +0100
committerJelle Raaijmakers <jelle@gmta.nl>2023-02-21 22:13:06 +0100
commitfd8c54d72023561125baa0e9f05f8b7e11997056 (patch)
treea3814193f2ff5173acbf1fed346a80f7e4360536 /AK
parent93945062a734d3a4fcccecfe3206f7b39bf133a3 (diff)
downloadserenity-fd8c54d72023561125baa0e9f05f8b7e11997056.zip
AK: Add `take_first` to HashTable and rename `pop` to `take_last`
This naming scheme matches Vector. This also changes `take_last` to move the value it takes, and delete by known pointer, avoiding a full lookup and potential copies.
Diffstat (limited to 'AK')
-rw-r--r--AK/HashTable.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/AK/HashTable.h b/AK/HashTable.h
index e57d83146d..9ac8c9d507 100644
--- a/AK/HashTable.h
+++ b/AK/HashTable.h
@@ -405,12 +405,21 @@ public:
return has_removed_anything;
}
- T pop()
+ T take_last()
requires(IsOrdered)
{
VERIFY(!is_empty());
- T element = *m_collection_data.tail->slot();
- remove(element);
+ T element = move(*m_collection_data.tail->slot());
+ delete_bucket(*m_collection_data.tail);
+ return element;
+ }
+
+ T take_first()
+ requires(IsOrdered)
+ {
+ VERIFY(!is_empty());
+ T element = move(*m_collection_data.head->slot());
+ delete_bucket(*m_collection_data.head);
return element;
}