-
Notifications
You must be signed in to change notification settings - Fork 224
MultiSimhash #70
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
base: master
Are you sure you want to change the base?
MultiSimhash #70
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,6 +168,22 @@ def distance(self, another): | |
| return ans | ||
|
|
||
|
|
||
| class MultiSimhash(Simhash): | ||
| def __init__(self, simhashes): | ||
| multi_f = 0 | ||
| if not isinstance(simhashes, Iterable): | ||
| raise Exception('Value passed is not a list of simhashes') | ||
| for i in simhashes: | ||
| multi_f = multi_f + i.f | ||
| if multi_f % 8: | ||
| raise Exception('Simhashes do not the same length (f)') | ||
| multi_value = self._concatenate_simhashes(simhashes) | ||
| super(MultiSimhash, self).__init__(value=multi_value, f=multi_f, hashfunc=simhashes[0].hashfunc) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before using
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, will add some check to look if its empty or not. |
||
|
|
||
| def _concatenate_simhashes(self, objs): | ||
| digests = [int_to_bytes(obj.value, obj.f_bytes) for obj in objs] | ||
| return bytes_to_int(b''.join(digests)) | ||
|
|
||
| class SimhashIndex(object): | ||
|
|
||
| def __init__(self, objs, f=64, k=2, log=None): | ||
|
|
||
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.
Hi, could you explain here, what do you want to check?
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.
Hi, well looking at it twice, that code doesn't make much sense. I will change it to check them all 1 by 1 to the length of the first simshash.