Hey guys. Trying to implement associative array with the help of libJudy. Here's small test, that doesn't work. Please, help me to find, where i did wrong?
#include <assert.h>
#include <Judy.h>
typedef struct {
char *hash;
int id;
int views;
} Watch_t;
Pvoid_t dict = (Pvoid_t) NULL;
PWord_t rcw;
char idx[12];
void init_track(Watch_t *track) {
assert(track);
track->id = 0; track->views = 0;
}
int set_to_storage(const unsigned char *key, Watch_t *val) {
PWord_t PV;
JSLI(PV, dict, key);
if (PV) {
PV = (PWord_t) val;
return 0;
} else {
return 1;
}
}
Watch_t *get_from_storage(const unsigned char *key) {
PWord_t PV;
JSLG(PV, dict, key);
if (PV) {
return ((Watch_t *) PV);
} else {
return NULL;
}
}
int main(int argc, char **argv) {
char *hash = "t8xr5nk8jczy";
Watch_t *tr; Watch_t *track;
int bool;
track = (Watch_t *) malloc( sizeof(Watch_t) );
init_track(track);
track->hash = "t8xr5nk8jczy";
track->id = 1; track->views = 16;
bool = set_to_storage((unsigned char *) hash, track);
tr = get_from_storage((unsigned char *) hash);
assert(tr);
fprintf(stderr, "Debug: hash=%s, track views=%d\n", tr->hash, tr->views);
return 0;
}
Working under ubuntu 9.04 and compiler flags is:
gcc -Wall -lJudy test.c -o test
trying to run it with gdb returned no errors.
don't mention unused args. i didn't put here other voids, that are not important at the moment.
Oh, yeah. forgot to say, the wrong is that i couldn't get my data back from dict.