There was a small mishmash of argument order, as seen on the table:
| Traits<T>::equals(U, T) | Traits<T>::equals(T, U)
============= | ======================= | =======================
uses equals() | HashMap | Vector, HashTable
defines equals() | *String[^1] | ByteBuffer
[^1]: String, DeprecatedString, their Fly-type equivalents and KString.
This mostly meant that you couldn't use a StringView for finding a value
in Vector<String>.
I'm changing the order of arguments to make the trait type itself first
(`Traits<T>::equals(T, U)`), as I think it's more expected and makes us
more consistent with the rest of the functions that put the stored type
first (like StringUtils functions and binary_serach). I've also renamed
the variable name "other" in find functions to "entry" to give more
importance to the value.
With this change, each of the following lines will now compile
successfully:
Vector<String>().contains_slow("WHF!"sv);
HashTable<String>().contains("WHF!"sv);
HashMap<ByteBuffer, int>().contains("WHF!"sv.bytes());
This makes it so these algorithms are usable with arbitrary iterators,
as opposed to just instances of AK::SimpleIterator.
This commit also makes the requirement of ::index() in find_index()
explicit, as previously it was accepting any iterator.
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 *
Problem:
- `find` is implemented inside of each container. This coupling
requires that each container needs to individually provide `find`.
Solution:
- Decouple the `find` functionality from the container. This allows
provides a `find` algorithm which can work with all
containers. Containers can still provide their own `find` in the
case where it can be optimized.
- This also allows for searching sub-ranges of a container rather than
the entire container as some of the container-specific member
functions enforced.
Note:
- @davidstone's talk from 2015 C++Now conference entitled "Functions
Want to be Free" encourages this style:
(https://www.youtube.com/watch?v=_lVlC0xzXDc), but it does come at
the cost of composability.
- A logical follow-on to this is to provide a mechanism to use a
short-hand function which automatically searches the entire
container. This could automatically use the container-provided
version if available so that functions which provide their own
optimized version get the benefit.