-
Notifications
You must be signed in to change notification settings - Fork 125
MurmurHash : Added string constructor and fromString function.
#1300
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
MurmurHash : Added string constructor and fromString function.
#1300
Conversation
johnhaddon
left a comment
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.
Thanks Paul - this looks handy. Comments inline...
include/IECore/MurmurHash.h
Outdated
| std::string toString() const; | ||
| void fromString( const std::string &repr ); |
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 really like the symmetry of these two functions - I think it makes it very clear that we're serialising to a string and deserialising back.
include/IECore/MurmurHash.h
Outdated
| // Construct directly from string representation | ||
| inline explicit MurmurHash( const std::string &repr ); |
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.
Do we need this constructor as well as fromString()? I don't see the need to have two ways of achieving the same thing, and the constructor's semantics seem much less clear. Looking at MurmurHash( variable ) in code I think you could be easily forgiven for thinking that it was equivalent to MurmurHash h; h.append( variable ).
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.
The existing __repr__ function in the python binding (line 52 of MurmurHashBinding.cpp) seems to assume it already exists and produces IECore.MurmurHash( hash.toString() ) as the python representation of a MurmurHash object.
Changes
Outdated
| Improvements | ||
| ------------ | ||
|
|
||
| - Added string constructor and `fromString` function to `IECore.MurmurHash`. |
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 in the section for an already-released version, but needs to be in a new section. If you want the feature to be released in the next 10.4.x version, the PR also needs to be targeted to the RB-10.4 branch.
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.
retargeted to RB-10.4
test/IECore/MurmurHashTest.py
Outdated
| hs = IECore.MurmurHash() | ||
| hs.fromString( s ) |
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 think static MurmurHash fromString(); might provide slightly better ergonomics, so this could just be a one-line hs = MurmurHash.fromString( s ).
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.
done
d8b0a96 to
af0c36e
Compare
af0c36e to
e5018df
Compare
7d69223 to
d55cbb9
Compare
|
Thanks Paul. I'm still a bit uneasy about this string constructor, but at least the new sanity check and exception will catch most invalid uses. Could you squash everything down ready to merge please? You could also move the Improvements section about the Build section in Changes - we try to order things so the more interesting stuff is at the top... |
51de841 to
67807ee
Compare
|
all done |
Adds the ability to reconstruct a IECore.MurmurHash from its string representation, which is useful if you want to store the hash as StringData in a primitive variable for example.
Breaking Changes
None
Checklist