Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Pretty fast hash map

Name: Anonymous 2014-09-22 13:01

Hey /frog/

check out my hash map implementation

in C of course

struct entry {
int key;
int hash;
int value;
};
static int hash(int key) { return key % 256; }

struct HashMap {
struct entry entries[999];
};

/* The API is below */

/* initialize new hash map */
void hashmap_init(HashMap* h) {
for (int i=0; i<999;i++) { h->entries[i].key = -1; }
}

/* find key from hashmap, return pointer to value
returned pointer is valid as long as HashMap is alive
*/
int* hashmap_find(HashMap* h, int k) {
for (int i=0; i<999;i++) {
if (hash(k) == h->entries[i].hash) {
if (k == h->entries[i].key) {
return &h->entries[i].value;
}
}
}
for (int i=0;i<999; i++) {
if (h->entries[i] < 0) {
h->entries[i].key = k;
h->entries[i].hash =hash(k);
return &h->entries[i].value
}
}
return 0;
}

Name: Anonymous 2014-09-22 13:08

>>1
static int hash(int key) { return key % 256; }
epic

Name: Anonymous 2014-09-22 14:23

Shit, totaly shit.

Name: Anonymous 2014-09-22 15:11

>>3
Sure, it's shit, but is it Abelson shit?

I believe it is since it can't even compile

Name: Anonymous 2014-09-22 15:32

>>4
Does Abelson shit?

Name: Anonymous 2014-09-22 18:40

>>3

What do you mean shit?

You it's shit because you don't like the way code looks.
maybe
{
i should
indent
}
like this??

or maybe you want ___variables____ _with underscores___ ??

or maybe you just envy my code :--)

Name: Anonymous 2014-09-22 19:53

They are called Hash Table(s, you fuckin retard. I was wondering why there was no ``hash map'' in the index of my C data structures textbook.

Name: Anonymous 2014-09-22 23:37

>>7
It looks like a bad implementation of a database table

Name: Anonymous 2014-09-23 0:32

>>7
)

Name: Anonymous 2014-09-23 3:18

>>7
Normal hash tables use a linked list or some shit in case of collisions usually.

Name: Anonymous 2014-09-23 5:07

>>1
That was PICO LISP Quality!

Name: Anonymous 2014-09-23 11:59

>>11
wats wrong wif picolisp?

Name: Anonymous 2014-09-23 13:09

Name: Anonymous 2014-09-23 13:51

I wonder why you even take the hash since you spend O(n) time anyway...

Don't change these.
Name: Email:
Entire Thread Thread List