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
Add double to bit encoding for OrderedCode #5816
Conversation
|
8a4d444
to
ba2e33a
Compare
Size Report 1Affected Products
Test Logs |
Size Analysis Report 1This report is too large (1361656 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.Test Logs |
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.
Added some comments and some questions that a JS newbie doesn't know...
*/ | ||
private toOrderedBits(val: number): Uint8Array { | ||
const value = doubleToLongBits(val); | ||
const isNegative = (value[0] & 0x80) !== 0; |
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'm curious why const isNegative = val < 0
is not used? Is it because of the three exceptions listed above?
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.
We are not actually looking at a number that is encoded as a long. Instead, we are looking at the first element of the byte array that is encoded as a number from 0 to 255.
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.
that's my question.. wouldn't it be easier to detect negativeness by checking the number (val
) rather than checking the byte array (value
)?
No action is needed though.
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.
We are checking whether the bit representation is "negative" not the number itself. Maybe the naming could use some improvement, but this is what the original implementation uses.
The tests fail if we just check if val
is negative.
This ports the double encoding from https://github.com/firebase/firebase-android-sdk/blob/master/firebase-firestore/src/main/java/com/google/firebase/firestore/index/OrderedCodeWriter.java
Note that Android does not have tests for this code since it is just a copy of the backend code.