diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-05-06 13:28:52 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-06 13:28:52 +0200 |
commit | fafdda8902e25e39c0e8484252a8e17271ed4538 (patch) | |
tree | bcef66a3dfb32dcf76f0fefc6a38c11619fa5d38 /AK | |
parent | ac67a2ed5e0362bc2873096bc53c84f49361a6f4 (diff) | |
download | serenity-fafdda8902e25e39c0e8484252a8e17271ed4538.zip |
AK: Change HashTable and HashMap size/capacity to be ints.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/HashMap.h | 4 | ||||
-rw-r--r-- | AK/HashTable.h | 38 |
2 files changed, 21 insertions, 21 deletions
diff --git a/AK/HashMap.h b/AK/HashMap.h index df802f6702..a2f54cf216 100644 --- a/AK/HashMap.h +++ b/AK/HashMap.h @@ -48,8 +48,8 @@ public: } bool is_empty() const { return m_table.is_empty(); } - unsigned size() const { return m_table.size(); } - unsigned capacity() const { return m_table.capacity(); } + int size() const { return m_table.size(); } + int capacity() const { return m_table.capacity(); } void clear() { m_table.clear(); } void set(const K&, const V&); diff --git a/AK/HashTable.h b/AK/HashTable.h index 1ae17b6b62..7a02060141 100644 --- a/AK/HashTable.h +++ b/AK/HashTable.h @@ -46,8 +46,8 @@ public: ~HashTable() { clear(); } bool is_empty() const { return !m_size; } - unsigned size() const { return m_size; } - unsigned capacity() const { return m_capacity; } + int size() const { return m_size; } + int capacity() const { return m_capacity; } void set(const T&); void set(T&&); @@ -108,7 +108,7 @@ public: } private: friend class HashTable; - explicit Iterator(HashTable& table, bool is_end, typename DoublyLinkedList<T>::Iterator bucket_iterator = DoublyLinkedList<T>::Iterator::universal_end(), unsigned bucket_index = 0) + explicit Iterator(HashTable& table, bool is_end, typename DoublyLinkedList<T>::Iterator bucket_iterator = DoublyLinkedList<T>::Iterator::universal_end(), int bucket_index = 0) : m_table(table) , m_bucket_index(bucket_index) , m_is_end(is_end) @@ -125,7 +125,7 @@ public: } HashTable& m_table; - unsigned m_bucket_index { 0 }; + int m_bucket_index { 0 }; bool m_is_end { false }; typename DoublyLinkedList<T>::Iterator m_bucket_iterator; }; @@ -186,7 +186,7 @@ public: } private: friend class HashTable; - ConstIterator(const HashTable& table, bool is_end, typename DoublyLinkedList<T>::ConstIterator bucket_iterator = DoublyLinkedList<T>::ConstIterator::universal_end(), unsigned bucket_index = 0) + ConstIterator(const HashTable& table, bool is_end, typename DoublyLinkedList<T>::ConstIterator bucket_iterator = DoublyLinkedList<T>::ConstIterator::universal_end(), int bucket_index = 0) : m_table(table) , m_bucket_index(bucket_index) , m_is_end(is_end) @@ -204,7 +204,7 @@ public: } const HashTable& m_table; - unsigned m_bucket_index { 0 }; + int m_bucket_index { 0 }; bool m_is_end { false }; typename DoublyLinkedList<T>::ConstIterator m_bucket_iterator; }; @@ -225,16 +225,16 @@ public: void remove(Iterator); private: - Bucket& lookup(const T&, unsigned* bucket_index = nullptr); - const Bucket& lookup(const T&, unsigned* bucket_index = nullptr) const; - void rehash(unsigned capacity); + Bucket& lookup(const T&, int* bucket_index = nullptr); + const Bucket& lookup(const T&, int* bucket_index = nullptr) const; + void rehash(int capacity); void insert(const T&); void insert(T&&); Bucket* m_buckets { nullptr }; - unsigned m_size { 0 }; - unsigned m_capacity { 0 }; + int m_size { 0 }; + int m_capacity { 0 }; }; template<typename T, typename TraitsForT> @@ -281,7 +281,7 @@ void HashTable<T, TraitsForT>::set(const T& value) template<typename T, typename TraitsForT> -void HashTable<T, TraitsForT>::rehash(unsigned new_capacity) +void HashTable<T, TraitsForT>::rehash(int new_capacity) { new_capacity *= 2; #ifdef HASHTABLE_DEBUG @@ -289,14 +289,14 @@ void HashTable<T, TraitsForT>::rehash(unsigned new_capacity) #endif auto* new_buckets = new Bucket[new_capacity]; auto* old_buckets = m_buckets; - unsigned old_capacity = m_capacity; + int old_capacity = m_capacity; m_buckets = new_buckets; m_capacity = new_capacity; #ifdef HASHTABLE_DEBUG kprintf("reinsert %u buckets\n", old_capacity); #endif - for (unsigned i = 0; i < old_capacity; ++i) { + for (int i = 0; i < old_capacity; ++i) { for (auto& value : old_buckets[i].chain) { insert(move(value)); } @@ -348,7 +348,7 @@ auto HashTable<T, TraitsForT>::find(const T& value) -> Iterator { if (is_empty()) return end(); - unsigned bucket_index; + int bucket_index; auto& bucket = lookup(value, &bucket_index); auto bucket_iterator = bucket.chain.find(value); if (bucket_iterator != bucket.chain.end()) @@ -361,7 +361,7 @@ auto HashTable<T, TraitsForT>::find(const T& value) const -> ConstIterator { if (is_empty()) return end(); - unsigned bucket_index; + int bucket_index; auto& bucket = lookup(value, &bucket_index); auto bucket_iterator = bucket.chain.find(value); if (bucket_iterator != bucket.chain.end()) @@ -378,7 +378,7 @@ void HashTable<T, TraitsForT>::remove(Iterator it) } template<typename T, typename TraitsForT> -typename HashTable<T, TraitsForT>::Bucket& HashTable<T, TraitsForT>::lookup(const T& value, unsigned* bucket_index) +typename HashTable<T, TraitsForT>::Bucket& HashTable<T, TraitsForT>::lookup(const T& value, int* bucket_index) { unsigned hash = TraitsForT::hash(value); #ifdef HASHTABLE_DEBUG @@ -392,7 +392,7 @@ typename HashTable<T, TraitsForT>::Bucket& HashTable<T, TraitsForT>::lookup(cons } template<typename T, typename TraitsForT> -const typename HashTable<T, TraitsForT>::Bucket& HashTable<T, TraitsForT>::lookup(const T& value, unsigned* bucket_index) const +const typename HashTable<T, TraitsForT>::Bucket& HashTable<T, TraitsForT>::lookup(const T& value, int* bucket_index) const { unsigned hash = TraitsForT::hash(value); #ifdef HASHTABLE_DEBUG @@ -409,7 +409,7 @@ template<typename T, typename TraitsForT> void HashTable<T, TraitsForT>::dump() const { kprintf("HashTable{%p} m_size=%u, m_capacity=%u, m_buckets=%p\n", this, m_size, m_capacity, m_buckets); - for (unsigned i = 0; i < m_capacity; ++i) { + for (int i = 0; i < m_capacity; ++i) { auto& bucket = m_buckets[i]; kprintf("Bucket %u\n", i); for (auto& e : bucket.chain) { |