## judy-devel

 Eternity Problem with Judy-Arrays (UPDATE) From: Schaeferhaus - 2009-05-20 11:26:19 ```A proposal of a new (simpler? better?) Judy-arrays API. Hier an example for JudyL functions. ----------------------------------------------------------------------- #include struct judy_s { Pcvoid_t *judy; }; typedef struct judy_s judy; typedef Word_t value_t; // or typedef uintptr_t value_t; /*32/64 bits-value*/ judy *judynew() { 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); } main() { judy *judy = judynew(); //... judydestroy(judy); } ```
 Re: Eternity Problem with Judy-Arrays (UPDATE) From: john skaller - 2009-05-20 11:59:46 ```On 20/05/2009, at 9:26 PM, Schaeferhaus wrote: > > A proposal of a new (simpler? better?) Judy-arrays API. > Hier an example for JudyL functions. > ----------------------------------------------------------------------- Unfortunately, you can't make a safe interface in C. In C++ you can do better, in Felix it is possible to do it properly. It's easy to make mistakes .. > > #include > > struct judy_s { Pcvoid_t *judy; }; > typedef struct judy_s judy; > typedef Word_t value_t; // or typedef uintptr_t value_t; /*32/64 > bits-value*/ > > judy *judynew() { return NULL; } this won't work so well because below you write judy->judy and that fails if the first judy there is NULL. instead you should just do the same cast you do on the next line .. except .. > > value_t *judylins(judy *judy, value_t x) { return (Word_t > *)JudyLIns((PPvoid_t)judy, x, NULL); } This cast isn't legal is it? You cannot cast a * to a struct to a void** directly. You would need to write (void**)(void*)judy first casting to void*. BTW: the use of aliases like PPvoid_t is a bad idea IMHO. What does it mean? Have to look it up. Why typedef something as simple as void**? Better to spell it out. > > 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); } > -- john skaller skaller@... ```
 AW: Eternity Problem with Judy-Arrays (UPDATE) From: Schaeferhaus - 2009-05-20 12:47:59 ```This is only a proposal. You must do all calls by passing the address of judy. Ex. judylins(&judy, x), judylget(&judy, x)... If you don't want this, then you must change the judynew (and also judydestroy) to judy *judynew() { return calloc(1, sizeof(struct judy_s)); } Writing an interface in C like this is not new. Note that this interface is consistent, you have not to think about, passing parameters by reference or by value (like actually in Judy). Regards! ----- Ursprüngliche Mail ---- Von: john skaller An: Schaeferhaus CC: judy-devel@...; Doug Baskins Gesendet: Mittwoch, den 20. Mai 2009, 13:59:33 Uhr Betreff: Re: Eternity Problem with Judy-Arrays (UPDATE) On 20/05/2009, at 9:26 PM, Schaeferhaus wrote: > > A proposal of a new (simpler? better?) Judy-arrays API. > Hier an example for JudyL functions. > ----------------------------------------------------------------------- Unfortunately, you can't make a safe interface in C. In C++ you can do better, in Felix it is possible to do it properly. It's easy to make mistakes .. > > #include > > struct judy_s { Pcvoid_t *judy; }; > typedef struct judy_s judy; > typedef Word_t value_t; // or typedef uintptr_t value_t; /*32/64 bits-value*/ > > judy *judynew() { return NULL; } this won't work so well because below you write judy->judy and that fails if the first judy there is NULL. instead you should just do the same cast you do on the next line .. except .. > > value_t *judylins(judy *judy, value_t x) { return (Word_t *)JudyLIns((PPvoid_t)judy, x, NULL); } This cast isn't legal is it? You cannot cast a * to a struct to a void** directly. You would need to write (void**)(void*)judy first casting to void*. BTW: the use of aliases like PPvoid_t is a bad idea IMHO. What does it mean? Have to look it up. Why typedef something as simple as void**? Better to spell it out. > > 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); } > -- john skaller skaller@... ```
 Re: AW: Eternity Problem with Judy-Arrays (UPDATE) From: john skaller - 2009-05-20 17:20:40 ```On 20/05/2009, at 10:21 PM, Schaeferhaus wrote: > > This is only a proposal. > You must do all calls by passing the address of judy. > Ex. judylins(&judy, x), judylget(&judy, x)... Ah, i see, i missed that sorry! -- john skaller skaller@... ```