HashTable with separate chaining and struct [closed]

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
I'm pretty new to C and I'm trying to implement a hashtable with chaining for a struct I created:
HASH.h:
#ifndef HASH_H
#define HASH_H
#include <stdio.h>
#include <stdlib.h>
#define MAXNAME 8000
/* Utilizing separate chaining and hashtables to
* save the informations about objectives
*/
typedef struct
unsigned long int id, duration;
char name [MAXNAME];
unsigned long int *dep;
Objective
typedef struct node
Objective objective;
struct node*next;
*link
void hashInit(int m);
link insertBegin(link head, Objective obj);
void objInsert(Objective obj);
#endif
HASH.c:
#include "HASH.h"
#include <stdlib.h>
#include <stdio.h>
static link *heads;
static int M;
int hash(Key value, int m)
return value%m;
void hashInit(int m)
int i;
M = m;
heads = (link*)malloc(M*sizeof(link));
for(i = 0; i < M; i++)
heads[i] = NULL;
link insertBegin(link head, Objective obj)
link new = (link)malloc(sizeof(struct node));
new->value = obj;
new->next = head;
return new;
void objInsert(Objective obj)
int i = hash(key(obj), M);
heads[i] = insertBegin(heads[i], obj);
I'm still in the very beginning and don't have much but I'm just looking for advice on how and if I can improve what I did here, what I might have done wrong, and if I'm on the right path.
c hash-table
closed as off-topic by ChrisWue, Toby Speight, Stephen Rauch, Sam Onela, Mast May 15 at 17:16
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â ChrisWue, Toby Speight, Stephen Rauch, Sam Onela, Mast
add a comment |Â
up vote
3
down vote
favorite
I'm pretty new to C and I'm trying to implement a hashtable with chaining for a struct I created:
HASH.h:
#ifndef HASH_H
#define HASH_H
#include <stdio.h>
#include <stdlib.h>
#define MAXNAME 8000
/* Utilizing separate chaining and hashtables to
* save the informations about objectives
*/
typedef struct
unsigned long int id, duration;
char name [MAXNAME];
unsigned long int *dep;
Objective
typedef struct node
Objective objective;
struct node*next;
*link
void hashInit(int m);
link insertBegin(link head, Objective obj);
void objInsert(Objective obj);
#endif
HASH.c:
#include "HASH.h"
#include <stdlib.h>
#include <stdio.h>
static link *heads;
static int M;
int hash(Key value, int m)
return value%m;
void hashInit(int m)
int i;
M = m;
heads = (link*)malloc(M*sizeof(link));
for(i = 0; i < M; i++)
heads[i] = NULL;
link insertBegin(link head, Objective obj)
link new = (link)malloc(sizeof(struct node));
new->value = obj;
new->next = head;
return new;
void objInsert(Objective obj)
int i = hash(key(obj), M);
heads[i] = insertBegin(heads[i], obj);
I'm still in the very beginning and don't have much but I'm just looking for advice on how and if I can improve what I did here, what I might have done wrong, and if I'm on the right path.
c hash-table
closed as off-topic by ChrisWue, Toby Speight, Stephen Rauch, Sam Onela, Mast May 15 at 17:16
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â ChrisWue, Toby Speight, Stephen Rauch, Sam Onela, Mast
1
Does this even compile? Thosetypedefdeclarations aren't terminated.
â Toby Speight
May 15 at 10:12
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I'm pretty new to C and I'm trying to implement a hashtable with chaining for a struct I created:
HASH.h:
#ifndef HASH_H
#define HASH_H
#include <stdio.h>
#include <stdlib.h>
#define MAXNAME 8000
/* Utilizing separate chaining and hashtables to
* save the informations about objectives
*/
typedef struct
unsigned long int id, duration;
char name [MAXNAME];
unsigned long int *dep;
Objective
typedef struct node
Objective objective;
struct node*next;
*link
void hashInit(int m);
link insertBegin(link head, Objective obj);
void objInsert(Objective obj);
#endif
HASH.c:
#include "HASH.h"
#include <stdlib.h>
#include <stdio.h>
static link *heads;
static int M;
int hash(Key value, int m)
return value%m;
void hashInit(int m)
int i;
M = m;
heads = (link*)malloc(M*sizeof(link));
for(i = 0; i < M; i++)
heads[i] = NULL;
link insertBegin(link head, Objective obj)
link new = (link)malloc(sizeof(struct node));
new->value = obj;
new->next = head;
return new;
void objInsert(Objective obj)
int i = hash(key(obj), M);
heads[i] = insertBegin(heads[i], obj);
I'm still in the very beginning and don't have much but I'm just looking for advice on how and if I can improve what I did here, what I might have done wrong, and if I'm on the right path.
c hash-table
I'm pretty new to C and I'm trying to implement a hashtable with chaining for a struct I created:
HASH.h:
#ifndef HASH_H
#define HASH_H
#include <stdio.h>
#include <stdlib.h>
#define MAXNAME 8000
/* Utilizing separate chaining and hashtables to
* save the informations about objectives
*/
typedef struct
unsigned long int id, duration;
char name [MAXNAME];
unsigned long int *dep;
Objective
typedef struct node
Objective objective;
struct node*next;
*link
void hashInit(int m);
link insertBegin(link head, Objective obj);
void objInsert(Objective obj);
#endif
HASH.c:
#include "HASH.h"
#include <stdlib.h>
#include <stdio.h>
static link *heads;
static int M;
int hash(Key value, int m)
return value%m;
void hashInit(int m)
int i;
M = m;
heads = (link*)malloc(M*sizeof(link));
for(i = 0; i < M; i++)
heads[i] = NULL;
link insertBegin(link head, Objective obj)
link new = (link)malloc(sizeof(struct node));
new->value = obj;
new->next = head;
return new;
void objInsert(Objective obj)
int i = hash(key(obj), M);
heads[i] = insertBegin(heads[i], obj);
I'm still in the very beginning and don't have much but I'm just looking for advice on how and if I can improve what I did here, what I might have done wrong, and if I'm on the right path.
c hash-table
edited May 15 at 2:31
Jamalâ¦
30.1k11114225
30.1k11114225
asked May 15 at 2:25
PTM
191
191
closed as off-topic by ChrisWue, Toby Speight, Stephen Rauch, Sam Onela, Mast May 15 at 17:16
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â ChrisWue, Toby Speight, Stephen Rauch, Sam Onela, Mast
closed as off-topic by ChrisWue, Toby Speight, Stephen Rauch, Sam Onela, Mast May 15 at 17:16
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â ChrisWue, Toby Speight, Stephen Rauch, Sam Onela, Mast
1
Does this even compile? Thosetypedefdeclarations aren't terminated.
â Toby Speight
May 15 at 10:12
add a comment |Â
1
Does this even compile? Thosetypedefdeclarations aren't terminated.
â Toby Speight
May 15 at 10:12
1
1
Does this even compile? Those
typedef declarations aren't terminated.â Toby Speight
May 15 at 10:12
Does this even compile? Those
typedef declarations aren't terminated.â Toby Speight
May 15 at 10:12
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
Does this even compile? Those
typedefdeclarations aren't terminated.â Toby Speight
May 15 at 10:12