Skip to content

[IDX-7035] Misc. API improvements#42

Open
dalloriam wants to merge 4 commits into
feature/IDX-7025-conceptsfrom
feature/IDX-7025-api-improvements
Open

[IDX-7035] Misc. API improvements#42
dalloriam wants to merge 4 commits into
feature/IDX-7025-conceptsfrom
feature/IDX-7025-api-improvements

Conversation

@dalloriam

@dalloriam dalloriam commented May 20, 2026

Copy link
Copy Markdown
Contributor

Changes

  • Add Cache::find_or_insert() (src)
  • Use <=> operator for comparing keys/key views when possible (src)
  • Add CompositeKey (src)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the cache API and heterogeneous lookup support by adding a reusable composite key type, extending transparent equality to support three-way comparisons, and introducing a find_or_insert convenience API with accompanying tests.

Changes:

  • Add cachemere::CompositeKey<...> with Abseil hashing support (including consistent hashing for std::string vs std::string_view).
  • Extend detail::TransparentEq to fall back to <=> when == is not available, enabling more heterogeneous comparison patterns.
  • Add Cache::find_or_insert API and tests validating the insertion/caching behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/src/detail/heterogeneous_lookup_tests.cpp Adds coverage for heterogeneous comparisons using <=>.
tests/src/detail/composite_key_tests.cpp New tests for CompositeKey construction, comparison, hashing, and heterogeneous lookup in a cache.
tests/src/cache_tests.cpp Adds test ensuring find_or_insert only calls the factory once and caches the result.
tests/CMakeLists.txt Registers the new composite key test file in the test target.
include/cachemere/detail/transparent_eq.h Adds <=>-based equality fallback for transparent comparisons.
include/cachemere/detail/traits.h Adds string/string_view traits and a FactoryFn concept used for find_or_insert.
include/cachemere/composite_key.h Introduces CompositeKey with tuple-based storage and Abseil hashing.
include/cachemere/cache.h Adds find_or_insert API and implementation.
include/cachemere.h Exposes composite_key.h from the umbrella header.
CMakeLists.txt Adds composite_key.h to the interface sources.
Comments suppressed due to low confidence (1)

include/cachemere/detail/traits.h:51

  • FactoryFn's template parameter order (FactoryFn<T, K, V>) doesn't match how it's being used in cache.h (where Fn is the callable). Consider redefining the concept as template<typename Fn, typename K, typename V> concept FactoryFn = ... and use const K& (and possibly std::invoke) in the requires-expression so lambdas/functions match naturally without requiring copies.
template<typename T, typename K, typename V>
concept FactoryFn = requires(T t, K key) {
    { t(key) } -> std::convertible_to<V>;
};

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread include/cachemere/cache.h Outdated
Comment thread include/cachemere/cache.h Outdated
Comment thread include/cachemere/detail/traits.h
Comment thread include/cachemere/detail/transparent_eq.h
Comment thread include/cachemere/composite_key.h
@dalloriam
dalloriam force-pushed the feature/IDX-7025-concepts branch from dedc204 to 56b7e9c Compare May 21, 2026 15:05
@dalloriam
dalloriam force-pushed the feature/IDX-7025-api-improvements branch from 8a83016 to 93dfa25 Compare May 21, 2026 15:44
@dalloriam dalloriam changed the title IDX-7025 API improvements [IDX-7035] API improvements May 21, 2026
@dalloriam dalloriam changed the title [IDX-7035] API improvements [IDX-7035] Misc. API improvements May 21, 2026
@dalloriam
dalloriam marked this pull request as ready for review May 21, 2026 15:51
@dalloriam
dalloriam force-pushed the feature/IDX-7025-concepts branch from 56b7e9c to 3229d5b Compare May 27, 2026 12:47
@dalloriam
dalloriam force-pushed the feature/IDX-7025-api-improvements branch from 93dfa25 to b3f9034 Compare May 27, 2026 12:50
@dalloriam
dalloriam requested a review from bourque-julien May 28, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants