Skip to content

Port lru cache to use std::unordered_map - #145

Merged
wengxt merged 2 commits into
masterfrom
map
Nov 2, 2026
Merged

wengxt merged 2 commits into
masterfrom
map

Conversation

@wengxt

@wengxt wengxt commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

While we store the graph pointer, it won't be dangling as graph is owned
by pinyin context anyway.

Summary by CodeRabbit

  • Improvements
    • Pinyin matching now recognizes equivalent input paths more consistently when reusing cached results. This includes paths with apostrophe-prefixed segments, while preserving the existing matching behavior.

While we store the graph pointer, it won't be dangling as graph is owned
by pinyin context anyway.
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 34 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 067fb2d1-0e2a-4008-b5ec-38bffaf10c33
Commits

Reviewing files that changed from the base of the PR and between 195c57f and 613ec60.

Files selected for processing: 2
  • src/libime/core/lrucache.h
  • src/libime/pinyin/pinyindictionary.cpp

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1cbbf8a6-39e4-4979-a88a-c3e73bd5010a
Commits

Reviewing files that changed from the base of the PR and between 6fec305 and 195c57f.

Files selected for processing: 3
  • src/libime/core/lrucache.h
  • src/libime/pinyin/pinyindictionary.cpp
  • src/libime/pinyin/pinyinmatchstate_p.h

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

LRUCache now supports configurable hash and equality types for compatible-key lookup. Pinyin cache helpers hash and compare segment paths against string keys, and dictionary code uses these helpers for match-result and trie-node caches.

Changes: Pinyin cache lookup

Layer / File(s) Summary
Configurable LRUCache lookup
src/libime/core/lrucache.h
LRUCache uses standard unordered-map types with configurable hash and equality objects. Its find method accepts a compatible key.
Pinyin path hashing and equality
src/libime/pinyin/pinyinmatchstate_p.h
PinyinStringHasher converts and hashes segment paths. PinyinStringEqual compares paths with strings, and both cache aliases use these types.
Pinyin dictionary cache lookups
src/libime/pinyin/pinyindictionary.cpp
The dictionary code removes its separate path hasher and uses the Pinyin helper types to find cache entries by path and create string keys.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Merge Risk: Minimal · previous review 195c5

No actionable merge-blocking issue is established; the change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Port lru cache to use std::unordered_map" matches the main change in src/libime/core/lrucache.h, where LRUCache moves from boost::unordered_map and boost::hash to std::unordered_map, std::h…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Port lru cache to use std::unordered_map" matches the main change in src/libime/core/lrucache.h, where LRUCache moves from boost::unordered_map and boost::hash to std::unordered_map, std::hash, and std::equal_to. The pinyin changes support this port by adding a PinyinStringHasher and PinyinStringEqual for the caches. The title is specific and short, and it names the primary change. It does not mention the pinyin-side hasher and equality work, but that is a supporting detail.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 9 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

🟢 Approval recommended

The review found no unresolved actionable issues in the changed cache and lookup implementations, with the noted downstream compatibility considerations not treated as active blockers.

No open issues 🎉

What changed in this PR

Ports the LRU cache from Boost containers to std::unordered_map and adds graph-aware heterogeneous lookup for equivalent pinyin paths.

Changes:

  • Replaces Boost unordered-map usage with configurable standard-library hash and equality functors.
  • Adds transparent hashing and equality for pinyin strings and segment graph paths.
  • Updates pinyin dictionary cache construction and lookup behavior.
File Summary Review notes
src/​libime/​pinyin/​pinyinmatchstate_p.h Adds graph-aware transparent hashing and equality for pinyin paths and updates cache types. No actionable issues identified.
src/​libime/​pinyin/​pinyindictionary.cpp Uses graph-specific cache functors and heterogeneous path lookups. No actionable issues identified.
src/​libime/​core/​lrucache.h Migrates the LRU cache to std::unordered_map with configurable hash and equality types. Moderate, 1 vote: Removing the existing heterogeneous find API may cause source incompatibility for downstream users. Moderate, 1 vote: Changing the default hash from boost::hash<K> to std::hash<K> may break existing users whose key types lack a standard hash specialization.

Review effort: Lite

@wengxt
wengxt merged commit e03eeda into master Nov 2, 2026
7 checks passed
@wengxt
wengxt deleted the map branch November 2, 2026 00:01
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