Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm trying to implement an open-hashing hash table and implement a hashable object type, Birthday, that can be used as a key into the hash

I'm trying to implement an open-hashing hash table and implement a hashable object type, Birthday, that can be used as a key into the hash table in Python 3

I have to create a class called "Birthday" using the following:

Three attributes for birth day, birth month, birth year

A constructor method that accepts the day, month, and year as parameters.

A __str__ method to provide a string representation of the Birthday object.

A __hash__ method that returns an integer as the sum of of the day, month, and year, mod 12. So if day=1, month=11, year = 1990, then this method would return (1+11+1990)%12, which is 10.

An __eq__ method to test if two Birthday objects have the same attribute value.

I have to place the implementation in a module called Birthday.py and create a __main__ section where you test instantiating Birthday objects, printing them, and calling the __hash__ method.

I also have to create a main file that will create an empty hash table, read in a list of birthdays from the supplied bdaylist.txt file, for each birthday, create a Birthday object, and add the tuple (Birthday,i) to the appropriate list in the hash table, where "i" is the line number from the input file, output the total length of the list at each of the hash locations.

Since the Birthday object's hash function hashes to integers in the range [0,12), I need to create a hash table with 12 empty lists in it. Here's what I have so far for this:

hashtable = []

for i in range(12):

hashtable.append([])

Here is the sample output:

Hash location 0 has 10 elements in it Hash location 1 has 12 elements in it Hash location 2 has 8 elements in it Hash location 3 has 10 elements in it Hash location 4 has 5 elements in it Hash location 5 has 7 elements in it Hash location 6 has 7 elements in it Hash location 7 has 11 elements in it Hash location 8 has 4 elements in it Hash location 9 has 8 elements in it Hash location 10 has 8 elements in it Hash location 11 has 10 elements in it

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

=+impact when these municipalities build stadiums and arenas?

Answered: 1 week ago