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

Pages: 1-

hashtables are shit

Name: Anonymous 2013-06-14 23:07

Why doesn't my hashtable work
also look i made somethign with C
http://pastebin.com/1a2kq4nF

Name: Anonymous 2013-06-14 23:26

Have a good hard look at this function and tell me where it's going wrong (besides the obnoxious code style).


int
_hashtable_hash
(
        char*   key
)
{
        int hash = 0;
        char c = key[0];
        while (c != '\0') {
                hash += (c * 1459 + 2593)%3457;
                c++;
        }
        return hash;
}

Name: Anonymous 2013-06-15 0:07

c++ lol

Name: Anonymous 2013-06-15 0:52

>>3
What

Name: Anonymous 2013-06-15 1:15

>>2
Holy moly, this is so bad it's hilarious

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-06-15 3:38

>>2,5
Works quite well if all the strings in your hashtable begin with different letters, actually you can't find a better hash function in that case.

Name: Anonymous 2013-06-15 3:50

>>4
reminds me of my pascal days... thinking booleans were magical..

var breaker as magical_boolean;
var count as integer;
breaker := count < 3;
do while(not breaker)
  count := count + 1;
  end;

Name: Anonymous 2013-06-15 3:57

...could you make a language do that? and would it be worth it?
can see a few things that would be trouble, eg a := not b; b := a; would be a problem..

Name: Anonymous 2013-06-15 4:06

>>6
It doesn't work at all unless the string is empty.

Name: Anonymous 2013-06-15 4:07

I guess it'd just amount to automatic code generation though.. but what about on large parallel systems? =)

Name: >>9 2013-06-15 4:07

>>9
I suppose it does if you take overflow into account, but still.

Name: Anonymous 2013-06-15 4:10

>>4
here

        int i=0;
        while (c != '\0') {
                hash += (c * 1459 + 2593)%3457;
                i++;
                c = key[i];
        }

Name: Anonymous 2013-06-15 4:16

What has that got to do with C++

Name: Anonymous 2013-06-15 4:18

>>13
It's the most hilarious line from OP-faggot's code.

Name: Anonymous 2013-06-15 4:23

>>14
Oh, yeah

Name: Anonymous 2013-06-15 4:28

cudder may tell you how to do it as ~ *c++; ?, but i'm terrible with pointers..

Name: Anonymous 2013-06-15 4:47

>>16
I don't actually know C
int hash(char* key){
    int hash = 0;
    while (*key != '\0'){
        hash += (*key * 1459 + 2593)%3457;
        key++;}
    return hash;}

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-06-15 5:50


static int hashes[] = {
  0, 854, 259, -1795, -1851, -3366, -6340, -7316, -9751, -10188, -12084, -15439, -16796, -19612, -20430, -22707,
  -22986, -24724, -27921, -29120, -31778, -32438, -34557, -34678, -36258, -39297, -40338, -42838, -43340, -45301, -48721, -50143,
  -53024, -53907, -56249, -56593, -58396, -61658, -62922, -65645, -66370, -68554, -68740, -70385, -73489, -74595, -77160, -77727,
  -79753, -79781, -81268, -84214, -85162, -87569, -87978, -89846, -93173, -94502, -97290, -98080, -100329, -100580, -102290, -105459,
  -106630, -109260, -109892, -111983, -112076, -113628, -116639, -117652, -120124, -120598, -122531, -125923, -127317, -130170, -131025, -133339,
  -133655, -135430, -138664, -139900, -142595, -143292, -145448, -145606, -147223, -150299, -151377, -153914, -154453, -156451, -156451, -157910,
  -160828, -161748, -164127, -164508, -166348, -169647, -170948, -173708, -174470, -176691, -176914, -178596, -181737, -182880, -185482, -186086,
  -188149, -188214, -189738, -192721, -193706, -196150, -196596, -198501, -201865, -203231, -206056, -206883, -209169, -209457, -211204, -214410,
  -215618, -214680, -211744, -210267, -210249, -208233, -207676, -205121, -204025, -200931, -199296, -199120, -196946, -196231, -193518, -192264,
  -189012, -187219, -186885, -184553, -183680, -180809, -179397, -175987, -174036, -173544, -171054, -170023, -166994, -165424, -165313, -163204,
  -162554, -159906, -158717, -155530, -153802, -153533, -151266, -150458, -147652, -146305, -142960, -141074, -140647, -138222, -137256, -134292,
  -132787, -132741, -130697, -130112, -127529, -126405, -123283, -121620, -121416, -119214, -118471, -115730, -114448, -111168, -109347, -108985,
  -106625, -105724, -102825, -101385, -97947, -95968, -95448, -92930, -91871, -88814, -87216, -87077, -84940, -84262, -81586, -80369,
  -77154, -75398, -75101, -72806, -71970, -69136, -67761, -64388, -62474, -62019, -59566, -58572, -55580, -54047, -53973, -51901,
  -51288, -48677, -47525, -44375, -42684, -42452, -40222, -39451, -36682, -35372, -32064, -30215, -29825, -27437, -26508, -23581,
  -22113, -22104, -20097, -19549, -17003, -15916, -12831, -11205, -11038, -8873, -8167, -5463, -4218, -975, 809, 1134 };

int hash(char *key) {
 return hashes[key[0]];
}


OMG OPTIMISED

Name: Anonymous 2013-06-15 5:55

>>18
it's spelt with a Z motherfucker

Name: Anonymous 2013-06-15 6:01

>>18
what about for typing? ;)

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-06-15 6:43

>>19
No it isn't, you bloody Yank.

Name: Anonymous 2013-06-15 6:47

>>21
Wrong again. Spread 'em.

Name: Anonymous 2013-06-15 6:51

>>21
You're right, according to the rules of pussy spelling there's an "s" there.

Name: Anonymous 2013-06-15 6:52

[b][i][o]ZOMG OPTIMISED[/b][/i][/o]

Name: Anonymous 2013-06-15 7:09

int
hashtable_linearprobe
(
        int n
)
{
        return n+1;
}
 
int
hashtable_quadraticprobe
(
        int n
)
{
        return n*n;
}

Name: cyphar 2013-06-15 7:44

Here's mine:
https://github.com/cyphar/ohmic

I tried to make it as easy to understand as possible.

Name: Anonymous 2013-06-15 9:32

>>18
i think hashes[0] = 0 is out..
% 3457 so i think maybe a range of -3457 to 3456, alternating positive / negative might just be faster? ;)

Name: Anonymous 2013-06-15 9:35

*hint* % 3457 ?
was that the number of bins?

Name: Anonymous 2013-06-15 9:36

zOMG ZOPTIMIZED ZIEG HEIL

Name: Anonymous 2013-06-15 9:38

... hash = (c * 1459 + 2593 + hash) % 3457; ?

Name: Anonymous 2013-06-15 11:13

>>25
Implement int anus_probe(int n)

Name: Anonymous 2013-06-15 11:16

int
hashtable_anusprobe
(
        int n
)
{
        return n+n*anus(n);
}

Name: Anonymous 2013-06-15 12:14

Name: Anonymous 2013-06-15 12:32

Who needs another amateur piece of C/C++ shit?

Name: Anonymous 2013-06-15 15:06

>>34
His professor.

Name: Anonymous 2013-06-15 15:40

>>34
need to thrown out from C++:
1. all OOP,
2. overloading, including the operators
3. referenses,
4. templates
5. exceptions
add LUA as standard library
and replace preprocessor to PHP
that's all

Name: Anonymous 2013-06-15 18:30

c++;  makes c bigger but returns the same value.

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