Skip to content

Hash table#6

Open
chamberi wants to merge 87 commits into
masterfrom
hash-table
Open

Hash table#6
chamberi wants to merge 87 commits into
masterfrom
hash-table

Conversation

@chamberi
Copy link
Copy Markdown
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.#
Comment thread README.MD
* 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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thorough documentation. Nice.

Comment thread src/hash_table.py

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

Choose a reason for hiding this comment

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

So many buckets! :)

Comment thread src/hash_table.py
"""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
Copy link
Copy Markdown

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.

Comment thread src/hash_table.py
for each in self._container[hashed_value]:
if each[0] == key:
return each[1]
return 'Key not in hash table.'
Copy link
Copy Markdown

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?

Comment thread src/hash_table.py
return self._colin_ben_hash(key)

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

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

Comment thread src/hash_table.py
def _additive_hash(self, key):
return sum([ord(each) for each in key]) % self._num_buckets

def _colin_ben_hash(self, key):
Copy link
Copy Markdown

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!

Comment thread src/hash_table.py
# 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
Copy link
Copy Markdown

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.

Comment thread src/test_hash_table.py
def test_table_correct(colin_ben_filled_hash_table):
"""Testing that get works correctly."""
count = 0
for line in open('/usr/share/dict/words'):
Copy link
Copy Markdown

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?

Comment thread src/test_hash_table.py
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'):
Copy link
Copy Markdown

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.

3 participants