Skip to content

Conversation

@linrongbin16
Copy link
Contributor

@linrongbin16 linrongbin16 commented Mar 11, 2025

Close #62 .

This PR adds a new API retain, it works similar to HashMap::retain. It passes a predicate function f to detect whether an item inside the cache should be removed.

The predicate f has below signature:

Fn(&Key, &Val) -> bool

Note:

  1. This API won't change the hot/cold/hit information inside the cache.
  2. The difference with HashMap::retain is the f signature, the &val is immutable.
  • TODO: Fix compiling issues, lint/clippy and add test cases.

@linrongbin16 linrongbin16 marked this pull request as draft March 11, 2025 10:06
@linrongbin16 linrongbin16 marked this pull request as ready for review March 12, 2025 09:03
@linrongbin16
Copy link
Contributor Author

Update: I added 2 test cases for both sync::Cache and unsync::Cache and turns out it works.

@linrongbin16 linrongbin16 requested a review from arthurprs March 12, 2025 09:52
Copy link
Owner

@arthurprs arthurprs left a comment

Choose a reason for hiding this comment

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

LGTM, just a comment change

@arthurprs arthurprs merged commit 79beaff into arthurprs:master Mar 12, 2025
7 checks passed
@linrongbin16 linrongbin16 deleted the retain2 branch March 12, 2025 21:40
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.

Can we have an API similar to HashMap::retain?

2 participants