reselect icon indicating copy to clipboard operation
reselect copied to clipboard

LRU implementation with hashmap and doubly linked list

Open kuldeepsinghborana opened this issue 1 year ago • 8 comments

kuldeepsinghborana avatar Feb 19 '24 18:02 kuldeepsinghborana

Deploy Preview for reselect-docs canceled.

Name Link
Latest commit af114daf0fd9e6c0f5857382b598c30269c97e44
Latest deploy log https://app.netlify.com/sites/reselect-docs/deploys/65d39e469dc6de0008edd250

netlify[bot] avatar Feb 19 '24 18:02 netlify[bot]

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

codesandbox-ci[bot] avatar Feb 19 '24 18:02 codesandbox-ci[bot]

this doesn't seem to use the equality function?

EskiMojo14 avatar Feb 19 '24 18:02 EskiMojo14

this doesn't seem to use the equality function?

@EskiMojo14 Yes, the equality function can not be used with a hashmap, we need to iterate throgh the all values which will not give us any advantage our the existing memoiser

kuldeepsinghborana avatar Feb 19 '24 20:02 kuldeepsinghborana

@kuldeepsinghborana yeah, that's a problem, and that's what i was pointing to in the issue thread. We rely on equality checks, not a single key.

markerikson avatar Feb 19 '24 22:02 markerikson

@markerikson @EskiMojo14 @aryaemami59 Can we create a new memoizer that takes a keyGen (key generator) function as an argument? The default keyGen function would convert the supplied argument into a JSON string. Subsequently, our cache Map would utilize this string as a key.

To enhance predictability in the JSON string, we can implement key sorting, ensuring that keys are consistently ordered for every object.

kuldeepsinghborana avatar Feb 21 '24 11:02 kuldeepsinghborana

@kuldeepsinghborana no, just converting values into a string is potentially very expensive. Imagine doing a JSON.stringify() on the entire Redux state for a large app.

markerikson avatar Feb 21 '24 15:02 markerikson

array.join() isn't going to help either. {a: 1} and {a: 2} are both going to stringify to "[object Object]", which is not unique.

markerikson avatar Feb 21 '24 15:02 markerikson