-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore: Refactor SortedMap #1666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1. intoduce variant of Redis and Dragonfly implementation and wrap each operation with a dedicated dispatcher operator. The dragonfly implementation path is a noop and not implemented. 2. Introduce a very basic sorted_map_test around Add and move the unrelated old test from sorted_map_test to bptree_set_test. Signed-off-by: Roman Gershman <[email protected]>
src/core/sorted_map.h
Outdated
int Add(double score, sds ele, int in_flags, int* out_flags, double* newscore) { | ||
return std::visit( | ||
Overload{[&](RdImpl& impl) { return impl.Add(score, ele, in_flags, out_flags, newscore); }, | ||
[&](DfImpl& impl) { return impl.Add(score, ele, in_flags, out_flags, newscore); }}, | ||
impl_); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't want to bother you refactoring, but either way... 100LOC less is good 😆
Just a side note, you can use auto-lambdas (template under the hood), so you don't need to type it all out twice, i.e.
visit([](auto& impl) { impl.Add(); }, impl_)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure I can, I thought this feature actually requires explicit override so it will deduce the base class types. checking it now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, it works. PTAL
Signed-off-by: Roman Gershman <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last nit: you don't need the Overload around the lambda 😬
hmm, it won't reduce number of lines, I will leave it as is :) |
intoduce variant of Redis and Dragonfly implementation and wrap each operation with a dedicated dispatcher operator. The dragonfly implementation path is a noop and not implemented.
Introduce a very basic sorted_map_test around Add and move the unrelated old test from sorted_map_test to bptree_set_test.