-
Notifications
You must be signed in to change notification settings - Fork 99
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
HaloDB.size and HaloDB.contains method #27
base: master
Are you sure you want to change the base?
Conversation
@akhodakivskiy Do you still need this feature. If so, please update and rebase |
156e96f
to
a821fab
Compare
Rebased. Thanks! |
int size(byte[] key) { | ||
InMemoryIndexMetaData metaData = inMemoryIndex.get(key); | ||
if (metaData == null) { | ||
return 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.
perhaps this should be -1 since 0 is a valid value size. Then -1 indicates the key is not present, and 0 indicates a value of size 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.
Good point, fixed. Method HaloDB.get
also returns 0
for keys that are not stored. I was following the same logic. But I agree that it should return -1
for abscent keys.
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.
Interesting... HaloDB.get returns a byte[], but HaloDBInternal has another get method that takes a ByteBuffer and reads the value into it (or truncating it if the value is larger than the buffer). This returns the number of bytes copied into the buffer, and 0 when not present.
However, this method is not used anywhere. Its not tested, its not used by the public facing API, it seems to be dead (and untested!) code.
a821fab
to
0329bbb
Compare
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.
Oops, I meant to comment, not review.
@@ -40,6 +40,10 @@ public static HaloDB open(String directory, HaloDBOptions opts) throws HaloDBExc | |||
} | |||
} | |||
|
|||
public int size(byte[] key) { |
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.
Is 'size' the right name? there is already a size
method that returns the number of elements. To avoid confusion, we should consider a different name. Perhaps entrySize
or valueSize
?
Also, the public API in HaloDB.java should document the expected behavior -- something like Returns the size of the value if present, or -1 if not present.
Adding two features: