Skip to content

Conversation

@chamberi
Copy link
Owner

No description provided.

CCallahanIV and others added 30 commits January 16, 2017 12:44
…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
William Benjamin Shields and others added 27 commits January 23, 2017 15:43
…ures into balance-bst

ng tests for left and right rotations.#
* 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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thorough documentation. Nice.


def __init__(self, hash_type='additive'):
"""Init function for the Hash Table class."""
self._num_buckets = 50000

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So many buckets! :)

"""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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this one liner

def _additive_hash(self, key):
return sum([ord(each) for each in key]) % self._num_buckets

def _colin_ben_hash(self, key):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to remove corpse code.

def test_table_correct(colin_ben_filled_hash_table):
"""Testing that get works correctly."""
count = 0
for line in open('/usr/share/dict/words'):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are you closing this file?

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'):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you seem to be opening this dictionary a lot...is there a way to speed this up and reuse one data structure?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants