-
Notifications
You must be signed in to change notification settings - Fork 172
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
pht: Fix wrong output from Prefix::toString #183
base: master
Are you sure you want to change the base?
Conversation
toString function should only output the string representation of the prefix in bits (0s and 1s). More information is confusing and not useful as it requires to parse the string.
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, just a few minor things
src/indexation/pht.cpp
Outdated
*/ | ||
static std::string blobToString(const Blob &bl) { | ||
static std::string blobToString(const Blob &bl, size_t nbr = 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.
This is a method that returns a string representation of n first bits of a Blob.
- method name is not accurate. It doesn't convert a Blob to a string.
- nbr should not be optional (we manipulate bits, not bytes), allowing to simplify line 37. One could argue nbr is not a good argument name (type size_t already tells it's a number).
- optional, at your preference: might be private, non-static in Prefix, using size_ directly (use and design are specific to Prefix).
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.
method name is not accurate. It doesn't convert a Blob to a string.
May be firstBitsToString
?
nbr should not be optional (we manipulate bits, not bytes), allowing to simplify line 37. One could argue nbr is not a good argument name (type size_t already tells it's a number).
I agree.
optional, at your preference: might be private, non-static in Prefix, using size_ directly (use and design are specific to Prefix).
If you look at the historic of the files pht.cpp
and pht.h
, you'll see that it was first the case (see 2d8fe50). Not much is said as to why it was changed. I guess that we found that the function was not depending on the state of the instance of Prefix and could apply to other objects directly like Blob
. However, I think that we can limit ourselves to the Prefix
class for our needs as of now, like you suggest.
A refactoring error led to blobToString outputing garbage. This patch fixes the issue and enables output of a number of bits other than multiple of 8.
6cfd593
to
c0e39b5
Compare
*/ | ||
static std::string blobToString(const Blob &bl) { | ||
std::string Prefix::firstBitsToString(const Blob &bl, size_t len) const { |
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.
If you choose to make it a non-static method, you should remove the second argument and checks, and use size_ directly (otherwise shall remain static). Also compute len/8 out of loops like in previous implementation.
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.
@aberaud: In the case of toString
, the ouput is the bit string up to size_
bits since this is the most expected behavior. However, one could like to get the whole bit string of the prefix for debugging purposes. To be honest, this function is mostly being used in debugging purposes. That's why I left it this way.
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.
Looks ok for me :)
But I would probably just move the BlobToString with the Blob definition in order to be able to print a Blob if needed ( without rewriting this function ).
Then just call BlobToString from firstBitsToString
Manipulating bits one-by-one is not common in IT, we usually manipulate bytes (groups of 8 bits). Prefix exists to represent a serie of bits and bitsToString is the method to print content or mask of a Prefix. |
If you want to argue on this, I'll ask you then: "What is the data of which the
I don't think that it's an implementation "detail". It's an important information. It contains the whole key for which we yield all prefixes.
This is already the case in my last uploaded version. Finally, keep in mind that another valuable information is part of |
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.
Prefix is the abstraction to represent a specific serie of bits, using Blob inside is an implementation detail, that's just the current design, not really up for interpretation. If you want to print a different prefix, then build this other Prefix and print it.
Anyway at this point I don't really care. The only actual issue to solve is to make sure that either the method is static or removes the len parameter.
0733bb6
to
0abd288
Compare
0d272df
to
8b6dcb1
Compare
I realize that this PR has been opened for a very long time and I have not found time to work on this again yet. Since I cannot say as of now when I will find the time to work on this again, I think that the best is to close this for consistency of the list of ongoing PRs. Let anyone be free to take this work and produce a mergeable version of it. |
@sim590 Thanks I'll follow up on this PR |
46380ab
to
0afa408
Compare
f05b60d
to
dfd0a09
Compare
966e620
to
fe6676f
Compare
dht::indexation::blobToString
had been written from older code. Therefore, minor refactoring errors led to wrong output from the function. This PR fixes those errors and also limits the output ofPrefix::toString
to the bits ofPrefix::content_
. An additional method for bits ofPrefix::flags_
is now provided asPrefix::flagsToString
.