Open
Conversation
…o bst Merging branch bst.
…o bst sdf building a binary search tree.
…ctures into traversal-bst g g Lines starting with '#' will be ignocquire post_order_trav. red, and an empty message aborts
…ures into balance-bst ng tests for left and right rotations.#
…ures into balance-bst merging branch.
… branch 'balance-bst' of https://github.com/chamberi/data-structures into balance-bst
SeleniumK
reviewed
Jan 30, 2017
| * g.breadth_first_travers(start): Returns the path list for the entire graph with a breadth first traversal. | ||
| - get(key) - should return the value stored with the given key | ||
| - set(key, val) - should store the given val using the given key | ||
| - _hash(key) - should hash the key provided (note that this is an internal api) |
|
|
||
| def __init__(self, hash_type='additive'): | ||
| """Init function for the Hash Table class.""" | ||
| self._num_buckets = 50000 |
| """Init function for the Hash Table class.""" | ||
| self._num_buckets = 50000 | ||
| self._container = [[] for i in range(0, self._num_buckets)] | ||
| self._type = hash_type |
There was a problem hiding this comment.
consider what you want to happen if a user inputs an invalid hash type.
| for each in self._container[hashed_value]: | ||
| if each[0] == key: | ||
| return each[1] | ||
| return 'Key not in hash table.' |
There was a problem hiding this comment.
very pythonic returns, but do you really want to be returning a string? Would it make more sense to raise an error?
| return self._colin_ben_hash(key) | ||
|
|
||
| def _additive_hash(self, key): | ||
| return sum([ord(each) for each in key]) % self._num_buckets |
| def _additive_hash(self, key): | ||
| return sum([ord(each) for each in key]) % self._num_buckets | ||
|
|
||
| def _colin_ben_hash(self, key): |
There was a problem hiding this comment.
Hah. I like the name, make sure to document this hash function!
| # num = int(str(ord(each))[::-1]) | ||
| # ords.append([num, next(sieve)]) | ||
| # a_sum = sum([(each[0] << next(sieve)) * (each[1] << next(sieve)) for each in ords]) | ||
| # return a_sum % self._num_buckets |
| def test_table_correct(colin_ben_filled_hash_table): | ||
| """Testing that get works correctly.""" | ||
| count = 0 | ||
| for line in open('/usr/share/dict/words'): |
| def test_table_correct2(additive_filled_hash_table): | ||
| """Testing that get works correctly.""" | ||
| # import pdb; pdb.set_trace() | ||
| for line in open('/usr/share/dict/words'): |
There was a problem hiding this comment.
you seem to be opening this dictionary a lot...is there a way to speed this up and reuse one data structure?
added 2 commits
February 9, 2017 13:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.