Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this project, you will implement a data abstraction called a hash map in C . using a header file named strmap.h . This version

For this project, you will implement a data abstraction called a hash map in C.using a header file named strmap.h. This version will map strings to arbitrary values. You will implement it as a utility that can be compiled with and used by any application. You will turn in your code in a file named strmap.c.
#include // for printf, ONLY IN strmap_dump
#include // for strcmp
#include // for malloc/calloc
#define MAX_BUCKETS 10000
#define MIN_BUCKETS 10
typedef struct strmap_e {
char *sme_key;
void *sme_value;
struct strmap_e *sme_next;
} smel_t;
typedef struct sm {
smel_t **strmap_buckets; // array of pointers to elements
unsigned int strmap_size; // # elements in the table
unsigned int strmap_nbuckets; // size of the array
} strmap_t;
/* Create a new hashtab, initialized to empty. */
strmap_t *strmap_create(int numbuckets);
/* Insert an element with the given key and value.
* Return the previous value associated with that key, or null if none.
*/
void *strmap_put(strmap_t *m, char *key, void *value);
/* return the value associated with the given key, or null if none */
void *strmap_get(strmap_t *m, char *key);
/* remove the element with the given key and return its value.
Return null if the hashtab contains no element with the given key */
void *strmap_remove(strmap_t *m, char *key);
/* return the # of elements in the hashtab */
int strmap_getsize(strmap_t *m);
/* return the # of buckets in the hashtab */
int strmap_getnbuckets(strmap_t *m);
/* print out the contents of each bucket */
void strmap_dump(strmap_t *m);

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 Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago