summaryrefslogtreecommitdiff
path: root/AK/HashMap.h
AgeCommit message (Collapse)Author
2023-05-19AK: Add FIXMEs to HashMap copy-construct and copy-assignBen Wiederhake
This underlines that we still copy-construct and copy-assign HashMaps. Primarily, this makes it easier to develop towards OOM-safe(r) internal data structures, by providing a reminder (the FIXME) and an easy error- checking switch (just change it to "delete" to see some of the errors).
2023-05-19AK: Rewrite HashMap::clone signature with template-args and constBen Wiederhake
2023-03-03AK: Add missing const qualifier to HashCompatible HashMap::contains()Linus Groh
2023-02-12AK: Add function 'shallow_clone()' to HashMapKenneth Myhra
This makes a shallow clone of the HashMap, the items temselves are not cloned in any way.
2023-02-02AK: Define HashMap::take to find and remove a value from the mapTimothy Flynn
2023-02-02AK: Return a constant reference from HashMap's constant get() overrideTimothy Flynn
We cannot return a mutable reference from a constant function.
2023-01-24AK: Make HashMap::try_ensure work with a fallible construction callbackNico Weber
Co-authored-by: Timothy Flynn <trflynn89@pm.me>
2022-12-16AK: Add a try_ensure() method to HashMapEli Youngs
2022-12-11AK: Let HashMap also take a ValueTraitsAli Mohammad Pur
We were previously using Traits<V>, take that frrom the template parameters instead. This is needed by the Jakt runtime.
2022-12-10AK: Remove HashMap::ensure_capacityThomas Queiroz
This is not perfect, since the constuctor can still fail.
2022-12-03Everywhere: Run clang-formatLinus Groh
2022-11-26AK: Make it possible to not `using` AK classes into the global namespaceAndreas Kling
This patch adds the `USING_AK_GLOBALLY` macro which is enabled by default, but can be overridden by build flags. This is a step towards integrating Jakt and AK types.
2022-05-08AK+LibGUI: Pass predicate to *_matching() methods by const referenceVitaly Dyachkov
2022-04-04AK: Return Optional<ConstPeekType> for HashMap::get() constAli Mohammad Pur
While the previous implementation always copied the object, returning a non-const reference to a const object is not valid.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-07AK: Remove return value from HashTable::remove() and HashMap::remove()Andreas Kling
This was only used by remove_all_matching(), where it's no longer used.
2022-03-07AK: Simplify HashTable::remove_all_matching()Andreas Kling
Just walk the table from start to finish, deleting buckets as we go. This removes the need for remove() to return an iterator, which is preventing me from implementing hash table auto-shrinking.
2022-01-29AK: Support using custom comparison operations for hash compatible keysIdan Horowitz
2022-01-21AK: Support setting with non copyable keys in HashMapIdan Horowitz
2022-01-05AK: Make Hash{Map,Table}::remove_all_matching() return removal successAndreas Kling
These functions now return whether one or more entries were removed.
2022-01-05AK: Add HashMap::remove_all_matching(predicate)Andreas Kling
This removes all matching entries from a hash map in a single pass.
2021-12-15AK: Enable fast path for removal by hash-compatible key in HashMap/TableHendiadyoin1
2021-12-15AK: Allow hash-compatible key types in Hash[Table|Map] lookupHendiadyoin1
This will allow us to avoid some potentially expensive type conversion during lookup, like form String to StringView, which would allocate memory otherwise.
2021-11-11AK: Allow to clear HashTables/Maps with capacityHendiadyoin1
2021-11-11AK: Make HashTable and HashMap try_* functions return ErrorOr<T>Andreas Kling
This allows us to use TRY() and MUST() with them.
2021-09-20AK+LibC: Remove SERENITY_LIBC_BUILD guard around `<initializer_list>`Andrew Kaster
This was required before commit 5f724b6ca1aae3a5a8c7189069649e8a9347cca2 when we were building LibC before libstdc++ headers were available in the sysroot. However as noted in that commit, we never actually needed to be building LibC before libstdc++, so we can go ahead and remove this ancient hack.
2021-09-12AK: Add the ability to hash the contents of a AK::HashMapBrian Gianforcaro
2021-09-10AK: Add OOM safe interface to HashTable/MapHediadyoin1
This adds a new HashSetResult only returned by try_set, to signal allocation failure during setting.
2021-09-10AK: Remove a redundant double find-call in HashMap::ensureIdan Horowitz
If the value was found there's no reason to search for it again.
2021-09-04AK: Add HashMap::ensure(key, callback)Andreas Kling
This function ensures that a key is present in the HashMap. If it's not present, it is inserted, and the corresponding value is initialized with whatever the callback returns. It allows us to express this: auto it = map.find(key); if (it == map.end()) { map.set(it, make_a_value()); it = map.find(key); } auto& value = it->value; Like this: auto& value = map.ensure(key, [] { return make_a_value(); }); Note that the callback is only invoked if we have to insert a missing key into the HashMap. This is important in case constructing the default value is expensive or otherwise undesirable.
2021-07-21AK: Sprinkle [[nodiscard]] on HashMap and HashTableAndreas Kling
2021-07-21AK: Remove unused HashMap::remove_one_randomly()Andreas Kling
2021-07-13HashMap: Rename finders with a more accurate and self-descripting namengc6302h
2021-06-15AK: Add a missing `using AK::OrderedHashMap` statementIdan Horowitz
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-05-18AK: Let HashMap export its key and value typesAli Mohammad Pur
2021-05-08AK: Add a non-const overload to HapMap::get()Itamar
Additionally, the const version of get() returns Optional<ConstPeekType> for smart pointers. For example, if the value in the HashMap is OwnPtr<u32>, HashMap::get() const returns Optional<const u32*>.
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 HashMap functions with [[nodiscard]]Brian Gianforcaro
2021-02-08Everywhere: Remove unnecessary headers 4/4Ben Wiederhake
Arbitrarily split up to make git bisect easier. These unnecessary #include's were found by combining an automated tool (which determined likely candidates) and some brain power (which decided whether the #include is also semantically superfluous).
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-12-29AK: Add HashMap(std::initializer_list<Entry>) constructorLinus Groh
This allows us to construct a HashMap from an initializer list like so: HashMap<K, V> hash_map = { { K, V }, { K, V } { K, V } };
2020-11-12AK: Prefer using instead of typedefLenny Maiorani
Problem: - `typedef` is a keyword which comes from C and carries with it old syntax that is hard to read. - Creating type aliases with the `using` keyword allows for easier future maintenance because it supports template syntax. - There is inconsistent use of `typedef` vs `using`. Solution: - Use `clang-tidy`'s checker called `modernize-use-using` to update the syntax to use the newer syntax. - Remove unused functions to make `clang-tidy` happy. - This results in consistency within the codebase.
2020-09-25Meta+AK: Make clang-format-10 cleanBen Wiederhake
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-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: Add HashMap::find() with customizable finder callbackAndreas Kling
This will allow clients to search the map without having to instantiate a key value.