Skip to content

feat(known-key): add OwnedValue & OwnedObject lookup support to KnownKey - #470

Open
Aditya-9-6 wants to merge 2 commits into
simd-lite:mainfrom
Aditya-9-6:feat/known-key-owned-support
Open

Aditya-9-6 wants to merge 2 commits into
simd-lite:mainfrom
Aditya-9-6:feat/known-key-owned-support

Conversation

@Aditya-9-6

Copy link
Copy Markdown

Summary

Currently, KnownKey provides fast O(1) hashed key lookup methods (lookup, map_lookup, lookup_mut, map_lookup_mut) exclusively for BorrowedValue and BorrowedObject.

This PR adds complete support for OwnedValue and OwnedObject to KnownKey, allowing applications using owned DOM representations to benefit from pre-computed hash lookups without re-hashing key strings.

Proposed Changes

  • KnownKey::lookup_owned: Fast O(1) lookup on &OwnedValue.
  • KnownKey::map_lookup_owned: Fast O(1) lookup on &owned::Object.
  • KnownKey::lookup_owned_mut: Mutable O(1) lookup on &mut OwnedValue.
  • KnownKey::map_lookup_owned_mut: Mutable O(1) lookup on &mut owned::Object.
  • Unit Tests: Added test_known_key_owned() in src/known_key.rs.

Verification

  • cargo test --features known-key: All unit tests, integration tests, and doc-tests passed cleanly.
  • cargo clippy --features known-key: Passed with 0 warnings/errors.

@Licenser Licenser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not a fan of adding a bunch off _owned functions that feels like a fairly painful API to use. Would it be possible to make the functions generic over the target instead?

Replace separate _owned functions with KnownKeyTarget and KnownKeyTargetMut
traits, making lookup and lookup_mut generic across BorrowedValue,
OwnedValue, and map objects.

Also generalize map_lookup and map_lookup_mut across any HashMap with
ObjectHasher whose key borrows as &str.
@Aditya-9-6

Copy link
Copy Markdown
Author

Great suggestion! I've refactored the API to make \lookup\ and \lookup_mut\ generic over the target using \KnownKeyTarget\ and \KnownKeyTargetMut\ traits (implemented for \BorrowedValue, \OwnedValue, and map objects), and generalized \map_lookup\ and \map_lookup_mut\ across any \HashMap<K, V, ObjectHasher>\ where \K: Borrow.

All separate _owned\ methods have been removed, and all unit tests, doctests, and clippy pass cleanly.

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