HashTable with separate chaining and struct [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash 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.







share|improve this question













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
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1




    Does this even compile? Those typedef declarations aren't terminated.
    – Toby Speight
    May 15 at 10:12
















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.







share|improve this question













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
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1




    Does this even compile? Those typedef declarations aren't terminated.
    – Toby Speight
    May 15 at 10:12












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.







share|improve this question













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.









share|improve this question












share|improve this question




share|improve this question








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
If this question can be reworded to fit the rules in the help center, please edit the question.




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
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 1




    Does this even compile? Those typedef declarations aren't terminated.
    – Toby Speight
    May 15 at 10:12












  • 1




    Does this even compile? Those typedef declarations 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















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Python Lists

Aion

JavaScript Array Iteration Methods