Hier a working example: with judysl
---------------------------------------------------------------
#include <stdio.h>
#include <strings.h>
#include <Judy.h>
struct judys { Pcvoid_t *judy; };
typedef struct judys judy;
typedef Word_t value_t; // or typedef uintptr_t word_t;
//-------------------------- judyl API
-------------------------------------------------------
judy *judylnew() { return NULL; }
value_t *judylins(judy *judy, value_t x) { return (Word_t
*)JudyLIns((PPvoid_t)judy, x, NULL); }
value_t *judyldel(judy *judy, value_t x) { return (Word_t
*)JudyLDel((PPvoid_t)judy, x, NULL); }
void judyldestroy(judy *judy) { JudyLFreeArray((PPvoid_t)judy, NULL); }
value_t *judylget(judy *judy, value_t x) { return (Word_t
*)JudyLGet(judy->judy, x, NULL); }
value_t *judylprev(judy *judy, value_t *x) { return (Word_t
*)JudyLPrev(judy->judy, x, NULL); }
value_t *judylnext(judy *judy, value_t *x) { return (Word_t
*)JudyLNext(judy->judy, x, NULL); }
value_t *judylfirst(judy *judy, value_t *x) { return (Word_t
*)JudyLFirst(judy->judy, x, NULL); }
value_t *judyllast(judy *judy, value_t *x) { return (Word_t
*)JudyLLast(judy->judy, x, NULL); }
//----------------------------------------- judysl api
--------------------------------------------------------
judy *judyslnew() { return NULL; }
value_t *judyslins(judy *judy, uint8_t *x) { return (Word_t
*)JudySLIns((PPvoid_t)judy, x, NULL); }
value_t *judysldel(judy *judy, uint8_t *x) { return (Word_t
*)JudySLDel((PPvoid_t)judy, x, NULL); }
void judysldestroy(judy *judy) { JudySLFreeArray((PPvoid_t)judy, NULL); }
value_t *judyslget(judy *judy, uint8_t *x) { return (Word_t
*)JudySLGet(judy->judy, x, NULL); }
value_t *judyslprev(judy *judy, uint8_t *x) { return (Word_t
*)JudySLPrev(judy->judy, x, NULL); }
value_t *judyslnext(judy *judy, uint8_t *x) { return (Word_t
*)JudySLNext(judy->judy, x, NULL); }
value_t *judyslfirst(judy *judy, uint8_t *x) { return (Word_t
*)JudySLFirst(judy->judy, x, NULL); }
value_t *judysllast(judy *judy, uint8_t *x) { return (Word_t
*)JudySLLast(judy->judy, x, NULL); }
int main( int argc, char *argv[]) {
judy *judy_ = judyslnew(), *judy = &judy_;
value_t *val;
FILE *f;
if(argc < 2) { printf("Usage: judy <text file>\n"); exit(-1); }
uint8_t s[1024+1];
if(f = fopen(argv[1],"r")) {
while(fgets(s, 1024, f)) { // insert keys from file
int len = strlen(s); if(s[len-1] == '\n') s[--len] = 0;
value_t *val ;
if(!(val = judyslins(judy, s))) { printf("judyslins failed\n"); exit(-1);
}
*val = *val + 1;
}
rewind(f); int notfound = 0;
while(fgets(s, 1024, f)) { // check keys
int len = strlen(s); if(s[len-1] == '\n') s[--len] = 0;
if(!(val = judyslget(judy, s))) notfound++;
printf("%s count=%d\n", s, *val);
}
printf("%d keys not found\n", notfound);
fclose(f);
// print all keys
for(s[0]='\0', val = judyslfirst(judy, s); val; val = judyslnext(judy, s))
printf("%s, count=%d\n", s, *val);
}
judysldestroy(judy);
}
------------------------------------------------------------------------------
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