-
Notifications
You must be signed in to change notification settings - Fork 186
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
How to serialize Decimal and still keep the results in order (bitwise comparison) #610
Comments
Hi @KKould, I'm not sure I quite understand the question here - but admittedly, I'm unfamiliar with RocksDB. If this is about key clustering, this may be more suitable to ask on the RocksDB project. That said - I'll try to provide a couple of answers:
I'm not sure if this helps at all. If not, if you could please provide some further context it may help direct me a bit more. |
Hi @paupino Implement Memory Comparable: After serialization, it can still be sorted (same order as before serialization) I tried |
Another thing you could try is to implement this manually. For example:
Then recombine them for your requirements. The code you've linked seems to write precision, scale then mantissa. You could emulate this by calculating the precision (i.e. length of the mantissa), followed by scale, followed by mantissa. Perhaps that would do the trick? i.e. in pseudo like code let mantissa = number.mantissa();
let scale = number.scale();
let precision = mantissa.ilog10() + 1;
// This is not space efficient
let mut bytes = Vec::new();
bytes.extend(precision.to_be_bytes());
bytes.extend(scale.to_be_bytes());
bytes.extend(mantissa.to_be_bytes()); |
I will store Decimal as a Key in RocksDB, but how can I keep Decimal in order after serialization and arrange Decimal in a more reasonable manner?
The text was updated successfully, but these errors were encountered: