summaryrefslogtreecommitdiff
path: root/AK/HashTable.h
AgeCommit message (Collapse)Author
2021-07-21AK: Remove unused private HashTable::lookup_for_reading()Andreas Kling
2021-07-21AK: Sprinkle [[nodiscard]] on HashMap and HashTableAndreas Kling
2021-07-13HashTable: Rename finders with a more accurate and self-descripting namengc6302h
2021-07-11AK: Use kfree_sized() in AK::HashTableAndreas Kling
2021-06-15AK: Add Ordering support to HashTable and HashMapHediadyoin1
Adds a IsOrdered flag to Hashtable and HashMap, which allows iteration in insertion order
2021-06-09AK: Allow changing the HashTable behaviour for sets on existing entriesIdan Horowitz
Specifically, replacing the existing entry or just keeping it and canceling the set.
2021-05-30AK: Make HashTable::operator=(HashTable&&) clear the moved-from tableAndreas Kling
This is consistent with how other AK containers behave when moved from.
2021-05-15AK+LibC: Implement malloc_good_size() and use it for Vector/HashTableGunnar Beutner
This implements the macOS API malloc_good_size() which returns the true allocation size for a given requested allocation size. This allows us to make use of all the available memory in a malloc chunk. For example, for a malloc request of 35 bytes our malloc would internally use a chunk of size 64, however the remaining 29 bytes would be unused. Knowing the true allocation size allows us to request more usable memory that would otherwise be wasted and make that available for Vector, HashTable and potentially other callers in the future.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-11AK: Annotate HashTable functions as [[nodiscard]]Brian Gianforcaro
2021-04-11AK: Make HashTable with capacity constructor explicitBrian Gianforcaro
2021-04-02AK: Inline HashTable writing bucket lookupthislooksfun
The old approach was more complex and also had a very bad edge case with lots of collisions. This approach eliminates that possiblility. It also makes both reading and writing lookups a little bit faster.
2021-04-02AK: Inline the bucket index calculationthislooksfun
The result of the modulo is only used in the array index, so why make the code more complex by calculating it in two different places?
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-01-31HashTable: Correctly pass args to setLenny Maiorani
Problem: - Using regular functions rather than function templates results in the arguments not being deduced. This then requires the same function to be written multiple times and for `move` to be used rather than `forward`. Solution: - Collapse multiple function overloads to a single function template with a deduced argument. This allows the argument to be a forwarding reference and bind to either an l-value or r-value and forward the value.
2021-01-12AK: Simplify constructors and conversions from nullptr_tLenny Maiorani
Problem: - Many constructors are defined as `{}` rather than using the ` = default` compiler-provided constructor. - Some types provide an implicit conversion operator from `nullptr_t` instead of requiring the caller to default construct. This violates the C++ Core Guidelines suggestion to declare single-argument constructors explicit (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit). Solution: - Change default constructors to use the compiler-provided default constructor. - Remove implicit conversion operators from `nullptr_t` and change usage to enforce type consistency without conversion.
2020-10-18AK: Reduce memory writes in HashTable destructorDano Perniš
2020-10-18AK: Implement HashTable assignment in terms of swapDano Perniš
2020-10-18AK: Provide swap() for HashTableDano Perniš
2020-10-16AK: Tune HashTable load factorAndreas Kling
Double the capacity when used+deleted buckets crosses 60% of capacity. This appears to be a sweet spot for performance based on some ad-hoc testing with test-js. :^)
2020-10-15AK: Redesign HashTable to use closed hashingAndreas Kling
Instead of each hash bucket being a SinglyLinkedList, switch to using closed hashing (open addressing). Buckets are chained together via double hashing (hashing the hash until we find an unused bucket.) This greatly reduces malloc traffic, since each added element no longer allocates a new linked list node. Appears performance neutral on test-js. Can definitely be tuned and could use proper management of load factor, etc.
2020-08-16AK: HashTable add a constructor that allows preallocation of capacity + Use ↵Muhammad Zahalqa
in CppLexer. (#3147) 1. Add general utility to get array number of elements. 2. Add Needed API to AK::HashTable 3. Refactor CppLexer initialization
2020-07-09AK: HashTable/HashMap return whether action was performed for set/removeTom
This allows performing an action based on whether something was actually added or removed without having to look it up prior to calling set() or remove().
2020-02-27AK: Expose SinglyLinkedListIterator constructorWilliam McPherson
This commit replaces SinglyLinkedListIterator::universal_end() with an empty SinglyLinkedListIterator(). Piano needs this in order to initialize a member array of iterators without 84 lines of universal_end().
2020-02-24AK: Make HashTable and HashMap use size_t for size and capacityAndreas Kling
2020-02-16AK: Add HashMap, HashTable and Traits to Forward.hAndreas Kling
2020-02-10AK: Remove bitrotted Traits::dump() mechanismAndreas Kling
This was only used by HashTable::dump() which I used when doing the first HashTable implementation. Removing this allows us to also remove most includes of <AK/kstdio.h>.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-08-25AK: Make HashTable.h compile inside the SDL2 portAndreas Kling
2019-08-04HashTable: Use the Bucket type in some places over SinglyLinkedList<T>Andreas Kling
This is just for consistency, and we might want to switch to another bucket type some day.
2019-07-31HashTable: Assert on iteration attempt over table during clear/rehashAndreas Kling
It doesn't seem sane to try to iterate over a HashTable while it's in the middle of being cleared. Since this might cause strange problems, this patch adds an assertion if an iterator is constructed during clear() or rehash() of a HashTable.
2019-06-29AK: Allow HashMap to be used with non-default-constructible values.Andreas Kling
Solve this by adding find() overloads to HashTable and SinglyLinkedList that take a templated functor for comparing the values. This allows HashMap to call HashTable::find() without having to create a temporary Entry for use as the table key. :^)
2019-06-29AK: Defer to Traits<T> for equality comparison in container templates.Andreas Kling
This is prep work for supporting HashMap with NonnullRefPtr<T> as values. It's currently not possible because many HashTable functions require being able to default-construct the value type.
2019-06-29HashTable: Don't use move assignment in set(const T&).Andreas Kling
2019-06-27AK: Use a SinglyLinkedList<T> as HashTable's bucket chain storage.Andreas Kling
We were using a DoublyLinkedList<T> simply because it supported remove(). This patch consolidates the SinglyLinkedList iterators and adds remove().
2019-06-27AK: Consolidate iterators for HashTable and DoublyLinkedList respectively.Andreas Kling
Get rid of the ConstIterator classes for these containers and use templated FooIterator<T, ...> and FooIterator<const T, ...> helpers. This makes the HashTable class a lot easier to read.
2019-06-24AK: Make it possible to move and copy HashMap and HashTable.Andreas Kling
Previously it was only possible to move them, but we should allow copying as well, since it's gonna be useful for many things.
2019-05-28Add clang-format fileRobin Burchell
Also run it across the whole tree to get everything using the One True Style. We don't yet run this in an automated fashion as it's a little slow, but there is a snippet to do so in makeall.sh.
2019-05-27AK: Add ensure_capacity() for HashMap and HashTable.Andreas Kling
These functions make sure that the underlying table can accomodate at least 'capacity' entries before needing a rehash.
2019-05-06AK: Change HashTable and HashMap size/capacity to be ints.Andreas Kling
2019-03-25AK: HashMap::set() didn't save new values for existing keys.Andreas Kling
2019-03-24LibGUI+FileManager: Add a GIcon class to support multi-size icons.Andreas Kling
A GIcon can contain any number of bitmaps internally, and will give you the best fitting icon when you call bitmap_for_size().
2019-02-04AK: Fix leak in HashTable move assignment operator.Andreas Kling
2019-01-30Fix dumb bug in HashTable::clear().Andreas Kling
We forgot to clear the m_buckets pointer. This meant that multiple calls to clear() would cause trouble.
2019-01-19Coding style fixes in AK.Andreas Kling
2018-12-21Yet another pass of style fixes.Andreas Kling
2018-12-04Import a simple text editor I started working on.Andreas Kling
2018-11-07Add some basic setgroups(), getgroups() and initgroups().Andreas Kling
Also teach /bin/id to print the user's supplemental groups.
2018-10-26Implement /proc/PID/vm.Andreas Kling
Refactored SyntheticFileSystem to maintain an arbitrary directory structure. ProcFileSystem creates a directory entry in /proc for each new process.