All pastes #545156 Raw Edit

Mine

public text v1 · immutable
·published 2007-06-06 18:29 UTC
rendered paste body
#include <stdio.h>
#define num_of_lists 2048

typedef struct node
{
	char* data;
	node* next;	
}

unsigned int hasher(char* word)
{
	unsigned int l = strlen(word), n;
	while(l--) n += word[l];
	return n%num_of_lists;
}

void check_hash_table(char* word, node** table)
{
	node* list_node;
	unsigned int hash;
	hash = hasher(word);
	list_node = table[hash];
	while(list_node->next != 0){
		list_node = list_node->next;
		if(strcmp(list_node->data,word)) continue;
		return 0;
	}
	list_node->next = malloc(sizeof(struct node));
	list_node = list_node->next;
	list_node->next = 0;
	list_node->data = malloc(strlen(word)+1);
	strcpy(list_node->data, word);
	return 1;
}

void main(void)
{
	unsigned int i;
	node hash_table[num_of_lists+1];

	for(i=0;i<num_of_lists+1;i++){
		hash_table[i]->data = 0;
		hash_table[i]->next = 0;
	}

	for(i=1;i<=argc;i++){
		if(check_hash_table(argv[i],hash_table)) printf("%s",argv[i]);
	}
	
}