Hey, guys. Following the tips from the previous thread i tried to
implement it and here's simple example based on my code.
#include <assert.h>
#include <Judy.h>
typedef struct {
char *hash;
int id;
int views;
} Watch_t;
Pvoid_t dict = (Pvoid_t) NULL;
void init_track(Watch_t *track) {
assert(track);
track->hash = NULL;
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;
Watch_t *tr; Watch_t *track;
int bool;
hash = "t8xr5nk8jczy";
track = (Watch_t *) malloc( sizeof(Watch_t) );
init_track(track);
track->hash = hash;
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;
}
But it doesn't work. set_to_storage says that it's ok and everything's
saved. But when i try to get it from array and print values into
stderr it returns nothing. to be honest, it returns 946564661 for
tr->views. I suppose, it's a kind of max_int or smth. Here's my
compile options:
gcc -Wall -lJudy test.c -o test
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables
unlimited royalty-free distribution of the report engine
for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Judy-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/judy-devel