Our Services

Get 15% Discount on your First Order

[rank_math_breadcrumb]

CSE 1320 Assignment 5 This assignment covers hash maps, macros, and makefiles. Your code must compile without any warnings or errors and run without segmentation faults to receive credit. Any allocate

CSE 1320 Assignment 5

This assignment covers hash maps, macros, and makefiles.

Your code must compile without any warnings or errors and run without segmentation faults to receive credit. Any allocated memory must be freed.

Adding a Makefile

When working with larger codebases, it is easy to get overwhelmed. Any obstacles encountered, no matter how small, can seem insurmountable. Our first task is to modify the Makefile for our project. This will make it simple to compile our project and test the different components we will be adding.

Feel free to use the example we did in class or the cookbook from makefiletutorial.com to get started.

Tasks

  • Modify the Makefile with the following targets:
    • release: Builds the full project normally. The executable should be placed in a build directory.
    • debug: Builds the project with the flags -g -Wall.
  • Verify that your Makefile works by building the project and running it (requires all tasks complete).

Collision Resolution using Quadratic Probing

One flaw of linear probing for collision resolution is that samples tend to cluster together in different parts of the map. An alternative open addressing scheme that does not suffer from clustering is quadratic probing.

Quadratic probing computes a new index based on the result of a hash function and quadratic function. Let h(k) be the original hash function. The new index is computed as

h(k,i)=(h(k)+c1i+c2i2) mod n.

Complete the function int quadratic_probe(int hash, int i, int n, int c1, int c2) that computes the function above. The input arguments are:

  • int hash – The original hash value computed by the hash function.
  • int i – The parameter i as described above.
  • int n – The size of the hash map.
  • int c1 – The first coefficient of the function.
  • int c2 – The second coefficient of the function.

This function will also allow you to explore the effects of changing the coefficients c1 and c2. In most cases, you might use a default implementation where c1=c2=1. For this case, create a macro that defines a function call default_probe(hash, i, n) to call the function quadratic_probe(hash, i, n, 1, 1).

Add these functions to hash_map_utils.(c|h). The macro definition should be placed after the declaration in hash_map_utils.h.

Tasks

  • Implement quadratic_probe in hash_map_utils.c.
  • Add macro for function.
  • Verify that the function works by running the tests using make test.

Monster Map

Create a program that uses a hash map with open addressing via quadratic probing and incremental rehashing. The hash map will store monster_s objects using the same data format as assignment 2.

monster_s struct

typdef struct {    char *name;    char *type;    int hp;    int ac;    int str;    int dex;    int con; } monster_s;

The keys for this map will be the names of each monster_s.

Adding a Monster

The program should allow users to add monsters from stdin as well as the ability to import from a CSV file. For the first task, implement option 1 on the main menu in monster_map.c by first creating a new monster_s object using data entered by the user and then inserting that into the hash map. There are already functions provided to do both of these things.

When adding an individual monster_s, make sure they are not already in the hash map. If it is, warn the user and return to the main menu. Test that your code works by compiling and running it. You should be able to add a few monsters without incident.

Complete this task by finishing the add_monster function in monster_utils.c. The function takes as input a hash map and a pointer to a monster_s object. If the pointer to monster_s is NULL, the function should call create_monster to create a new monster from user input.

Tasks

  • Create a new monster using create_monster in monster_utils.c.
  • Verify the monster is unique by using the search function.
  • If it is unique, add it to the hash map.
  • If it already exists, free the memory allocated for this monster.
  • Verify that your code works by running make test.

Bulk Import from CSV File

For option 2, the program should load data from a CSV file and insert the unique entries in the hash map. Since we know ahead of time how many samples are to be added, the map size should be reserved to accommodate all entries without rehashing.

One approach to implementing this option would be:

  1. Load all monsters from a CSV file into an array (use array_s).
  2. Determine the unique entries in the array using search. Remove any entries from the array that are already in the map.
  3. Insert the entries into the map based on the number of unique monsters by completing the bulk_insert function in monster_map.c.

The first step should be completed by filling out the load_monsters_csv function in monster_utils.c. This function should read the file line by line and create a monster_s object for each line. The function should return an array_s object containing all the monsters in the file. Once the monsters are loaded, you should pass the array to the bulk_insert function.

The third step requires some consideration since the map may currently be in the process of rehashing. In that case, the current rehashing should be immediately completed. Then the map should be resized again such that all unique entries from the file can be entered without triggering another rehash.

Tasks

  • Complete load_monsters_csv in monster_utils.c
  • Filter out monsters that already exist in the hash map.
  • Convert the unique data to hash_element_t objects and store in a new array_s object.
  • Pass the array to bulk_insert in hash_map_utils.c. You will need to complete this function following the subtasks listed in the function.
  • In hash_map_utils.h, create a macro named MIN_BUCKET_SIZE to calculate the bucket size of a map given the number of keys n and a load factor bound b:

k≥⌈nb⌉

  • Verify that your code works by running make test. Check that the tests for load_monsters_csv, add_monsters, test_macro, and bulk_insert pass.

Requirements

When importing a file to add, gather a collection of unique keys to add before any hash map operations. Once the unique keys are determined (use the search function to check if they already exist), then rehash and resize with at least enough room to store the new keys without rehashing again.

Allocated memory must be freed before the program terminates.

Any function declarations, macros, or struct declarations should be in a corresponding header file.

Searching the Map

Users should be able to search the map using a monster name. To complete option 3, ask the user to enter a monster name and use that as input to the search function that is already provided. If a key exists, print the monster’s details out to stdout. Otherwise, let the user know that the monster does not exist.

For printing monster details, complete the function print_monster in monster_utils.c. This function accepts a void * object as input since the function will be passed as input to the print functions in hash_map_utils.c.

Tasks

  • Complete option 3 in monster_map.c as described above.
  • Finish print_monster in monster_utils.c so that it prints the details of a monster.

Cleaning Up

It is important to free any allocated data that is no longer being used. Complete the free_monster function in monster_utils.c. Note that this function expects a void * object as its first parameter as it will be used as a function pointer. The reasoning is because the hash map functions do not know exactly what type of data they will be storing, so they cannot possibly know how to free a specific data type.

This function should free the data allocated to each string as well as the data for the monster_s object itself.

Tasks

  • Complete the free_monster function in monster_utils.c.
  • Make sure all dynamically allocated memory is freed before the program exits.

Example Runs

Example Output – Import Bulk Monsters

1. Add Monster 2. Import CSV File 3. Search 4. Print Map 5. Exit > 2 Enter filename: monsters.csv 10 unique entries to be added (2 duplicates) out of 12. Rehashing… Import complete.

Example Output – Search

1. Add Monster 2. Import CSV File 3. Search 4. Print Map 5. Exit > 3 Enter a monster name: Rakshasa Rakshasa not found in map. About

2248-cse-1320-001-assignment-5-hash-maps-CSE1320-Assignment5 created by GitHub Classroom

Resources ReadmeLicense MIT license Activity Custom propertiesStars 0 starsWatchers 0 watchingForks 0 forksReleasesNo releases publishedCreate a new releasePackagesNo packages published

Publish your first packageLanguages

  • C66.4%
  • C++33.4%
  • Makefile0.2%

Suggested workflowsBased on your tech stack

  1. CMake based, multi-platform projectsConfigure CMake based, multi-platform projectsBuild and test a CMake based project on multiple platforms.
  2. CMake based, single-platform projectsConfigure CMake based, single-platform projectsBuild and test a CMake based project on a single-platform.
  3. C/C++ with MakeConfigure C/C++ with MakeBuild and test a C/C++ project using Make.

More workflowsDismiss suggestionsFooter

Share This Post

Email
WhatsApp
Facebook
Twitter
LinkedIn
Pinterest
Reddit

Order a Similar Paper and get 15% Discount on your First Order

Related Questions

TNM1 — Task 2: Multipage Website Prototype Competencies 4040.01.1 : User Interface Design Projects The graduate describes user interface design project constructs. 4040.01.2 : User Interface Design Pr

TNM1 — Task 2: Multipage Website Prototype Competencies 4040.01.1 : User Interface Design Projects The graduate describes user interface design project constructs. 4040.01.2 : User Interface Design Process The graduate describes the user interface design process. 4040.01.3 : User Centered Web Design The graduate explains the relationship between the user and the site design. 4040.01.4 : User Interface

IntroductionUser interface and user experience (UI/UX) designer is one of the most popular job titles in the technology industry. UI/UX designers tend to enjoy the challenges associated with creating

IntroductionUser interface and user experience (UI/UX) designer is one of the most popular job titles in the technology industry. UI/UX designers tend to enjoy the challenges associated with creating products that people love. Industry leaders know that design is a substantial competitive advantage, and they are competing for best talents;

In Units V, VI, and VII, you learned about the components of a computer, how a computer works, the internet, networks and network communications, cloud computing, web development, digital identity, so

In Units V, VI, and VII, you learned about the components of a computer, how a computer works, the internet, networks and network communications, cloud computing, web development, digital identity, social media, e-commerce, ethical behavior, databases, and explored two Microsoft Office applications, PowerPoint and Access.  In this assignment, you will

In the previous assignment, the annotated bibliography, you collected 15 – 20 references. Now, you are to craft an analytical research paper. Using the same themes assigned for the previous assignment

In the previous assignment, the annotated bibliography, you collected 15 – 20 references. Now, you are to craft an analytical research paper. Using the same themes assigned for the previous assignment.  GROUP 1: Context-Aware Computing  Prepare a ten (10) page research paper. In the paper, you are to cover the

This week, you will submit the second project, the Desktop Migration Proposal. Using the requirements analysis your manager provided and the Internet research you conducted, submit your recommendation

This week, you will submit the second project, the Desktop Migration Proposal. Using the requirements analysis your manager provided and the Internet research you conducted, submit your recommendation to the assignment folder. As you are writing your recommendation, ensure your analysis and recommendations align with your manager’s priorities and concerns.

In Units I, II, and III, you learned about the history of computers, application and system software, blockchain, cryptocurrency, computer ethics, and explored two Microsoft Office applications, Word

In Units I, II, and III, you learned about the history of computers, application and system software, blockchain, cryptocurrency, computer ethics, and explored two Microsoft Office applications, Word and Excel.  In this assignment you will demonstrate what you have learned in these three units. This assignment will have five parts. 

Research and brainstorm three (3) proposals for a mobile computing solution. Write up a half-page (double-spaced, approx. 250 words) description of each mobile computing solution proposal. Provide an

Research and brainstorm three (3) proposals for a mobile computing solution.  Write up a half-page (double-spaced, approx. 250 words) description of each mobile computing solution proposal. Provide answers to the following questions: 1) What is the 1 sentence summary of the mobile computing solution? 2) Who and how big is

Creating and Submitting your Portfolio Overview Creating a professional cybersecurity portfolio is essential for showcasing your skills, achievements, and growth. This portfolio will serve as a valuab

Creating and Submitting your Portfolio Overview Creating a professional cybersecurity portfolio is essential for showcasing your skills, achievements, and growth. This portfolio will serve as a valuable tool for presenting yourself to universities, scholarship committees, employers, and beyond. Objective:: To design a professional cybersecurity portfolio that markets your academic and

IntroductionFor this project, you will create a personal portfolio website to demonstrate your ability to use HTML, CSS, and JavaScript and resolve software problems in web development environments. Y

IntroductionFor this project, you will create a personal portfolio website to demonstrate your ability to use HTML, CSS, and JavaScript and resolve software problems in web development environments. You will create three HTML pages: a résumé, a cover letter, and a career goals page. As you make your website, you

IntroductionFor this project, you will create a personal portfolio website to demonstrate your ability to use HTML, CSS, and JavaScript and resolve software problems in web development environments. Y

IntroductionFor this project, you will create a personal portfolio website to demonstrate your ability to use HTML, CSS, and JavaScript and resolve software problems in web development environments. You will create three HTML pages: a résumé, a cover letter, and a career goals page. As you make your website, you

Need to report 1 You will submit two reports generated from your developed database. These reports should be meaningful to your database. The report(s) resolve one of the problems that you originally

Need to report 1 You will submit two reports generated from your developed database. These reports should be meaningful to your database. The report(s) resolve one of the problems that you originally identified in your Database Proposal.  The lay out should be appealing to the eye and the design should

Select any example visualization or infographic and imagine the contextual factors have changed: If the selected project was a static work, what ideas do you have for potentially making it usefully in

Select any example visualization or infographic and imagine the contextual factors have changed: If the selected project was a static work, what ideas do you have for potentially making it usefully interactive? How might you approach the design if it had to work on both mobile/tablet and desktop? If the

Excel 365/2021 Capstone – Level 2 Working with Sales Data These instructions are compatible with both Microsoft Windows and Mac operating systems. In this project, you will work with sales data from T

Excel 365/2021 Capstone – Level 2 Working with Sales Data These instructions are compatible with both Microsoft Windows and Mac operating systems. In this project, you will work with sales data from Top’t Corn, a popcorn company with an online store, multiple food trucks, and two retail stores. You will