This file contains 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
class HashTable: | |
def __init__(self): | |
self.size = 11 | |
self.slots = [None] * self.size | |
self.data = [None] * self.size | |
def put(self,key,data): | |
hashvalue = self.hashfunction(key,len(self.slots)) | |
if self.slots[hashvalue] == None: |
This file contains 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
# in state list: 1 means occupied, 0 means empty and -1 means deleted | |
class Node: | |
def __init__(self, key): | |
self.key = key | |
self.next = None | |
class QuadraticProbing: | |
def __init__(self, size=100, load_factor=0.75): | |
self.items_count = 0 |
This file contains 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
class hashtable_chain(object): | |
'''Chain collision implemented hash table''' | |
def __init__(self, hash_array_size=11): | |
self.size = hash_array_size | |
self.key_values_pairs = [[]]*hash_array_size | |
def _hash_function(self, x): | |
''' Private hash function. | |
Convert x into a string. | |
For each letter in string, position * ord(letter) |
This file contains 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
class MyHashTable: | |
def __init__(self): | |
self.size = 11 | |
self.positions = [None] * self.size | |
self.values = [None] * self.size | |
def put(self,key,value): | |
hashvalue = self.hashfn(key,len(self.positions)) | |
if self.positions[hashvalue] == None: |
This file contains 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
# in state list: 1 means occupied, 0 means empty and -1 means deleted | |
class Node: | |
def __init__(self, key): | |
self.key = key | |
self.next = None | |
class DoubleHashing: | |
def __init__(self, size=100, load_factor=0.75): | |
self.items_count = 0 |
This file contains 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
""" | |
file: hashtable.py | |
language: python3 | |
author: sps@cs.rit.edu Sean Strout | |
author: jeh@cs.rit.edu James Heliotis | |
author: anh@cs.rit.edu Arthur Nunes-Harwitt | |
author: hotchkiss@rit.edu Collin Hotchkiss | |
description: open addressing Hash Table for CS 242 Lecture | |
""" | |
import copy |
This file contains 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
from linked_list import LinkedList | |
class HashTable(object): | |
def __init__(self, items = None): | |
"""Initialize this HashTable and set items if specified""" | |
self.slots = [LinkedList() for i in range(8)] # start with 8 slots | |
self.size = 0 |