Recent Posts
PHP | 10 sec ago
JavaScript | 28 sec ago
None | 29 sec ago
Java | 32 sec ago
None | 34 sec ago
None | 56 sec ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
By Anonymous on the 9th of Feb 2010 08:29:42 PM
Download |
Raw |
Embed |
Report
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned int hashf(const char *buf, size_t len) {
unsigned int h = 0;
size_t i;
for (i = 0; i < len; i++) {
h += buf[i];
h += h << 10;
h ^= h >> 7;
}
h += h << 3;
h ^= h >> 11;
h += h << 15;
return h;
}
int isFull(char *table, size_t size) {
int i;
for (i = 0; i < size; i++) {
if (&table[i] == NULL) {
return 0;
}
}
return 1;
}
int main(int argc, char *argv[]) {
if (argc != 3) return EXIT_FAILURE;
int size = atoi(argv[2]);
char *hashtable[size];
int i;
for (i = 0; i < size; i++) {
hashtable[i] = NULL;
}
FILE *file = fopen(argv[1], "r");
if (file == NULL) {
printf("ERROR OPENING FILE!!!\n");
return EXIT_FAILURE;
}
while (!feof(file)) {
char word[30];
fscanf(file, "%s", word);
if(isFull(*hashtable, size)) {
printf("Error: table full\n");
return EXIT_FAILURE;
}
unsigned int h = hashf(word, strlen(word)) % size;
i = 1;
while (hashtable[h] != NULL) {
h = (hashf(word, strlen(word)) + i*i) % size;
i++;
}
hashtable[h] = word;
printf("laitettu %s paikkaan %d \n", hashtable
[h
], h
);
}
fclose(file);
//Tulostetaan hashi
for (i = 0; i < size; i++) {
if (i == size - 1) {
if (hashtable[i] == NULL) {
} else {
}
} else {
if (hashtable[i] == NULL) {
} else {
}
}
}
return EXIT_SUCCESS;
}
Submit a correction or amendment below.
Make A New Post