-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Added doctest to double_hash.py #11020
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
Changes from 1 commit
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -35,6 +35,33 @@ def __hash_double_function(self, key, data, increment): | |||||||||
return (increment * self.__hash_function_2(key, data)) % self.size_table | ||||||||||
|
||||||||||
def _collision_resolution(self, key, data=None): | ||||||||||
""" | ||||||||||
Examples: | ||||||||||
|
||||||||||
1. Try to add three data elements when the size is three | ||||||||||
>>> dh = DoubleHash(3) | ||||||||||
>>> dh.insert_data(10) | ||||||||||
>>> dh.insert_data(20) | ||||||||||
>>> dh.insert_data(30) | ||||||||||
>>> dh.keys() | ||||||||||
{1: 10, 2: 20, 0: 30} | ||||||||||
|
||||||||||
2. Try to add three data elements when the size is two | ||||||||||
>>> dh = DoubleHash(2) | ||||||||||
>>> dh.insert_data(10) | ||||||||||
>>> dh.insert_data(20) | ||||||||||
>>> dh.insert_data(30) | ||||||||||
>>> dh.keys() | ||||||||||
{10: 10, 9: 20, 8: 30} | ||||||||||
|
||||||||||
3. Try to add three data elements when the size is one | ||||||||||
>>> dh = DoubleHash(2) | ||||||||||
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.
Suggested change
Typo 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.
I tested adding elements to DoubleHash with size 1, to my surprise it resulted in getting stuck in infinite loop, where a new hash value tries to be calculated but is unable to. For now I have changed that part of test. I'll soon be raising an issue and also will try to fix it. |
||||||||||
>>> dh.insert_data(10) | ||||||||||
>>> dh.insert_data(20) | ||||||||||
>>> dh.insert_data(30) | ||||||||||
>>> dh.keys() | ||||||||||
{10: 10, 9: 20, 8: 30} | ||||||||||
""" | ||||||||||
i = 1 | ||||||||||
new_key = self.hash_function(data) | ||||||||||
|
||||||||||
|
@@ -50,3 +77,9 @@ def _collision_resolution(self, key, data=None): | |||||||||
i += 1 | ||||||||||
|
||||||||||
return new_key | ||||||||||
|
||||||||||
|
||||||||||
if __name__ == "__main__": | ||||||||||
import doctest | ||||||||||
|
||||||||||
doctest.testmod() |
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.
Cool