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 <[email protected]>
An: Schaeferhaus <[email protected]>
CC: [email protected]; Doug Baskins <[email protected]>
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 <Judy.h>
> 
> 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
[email protected]


      

------------------------------------------------------------------------------
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

Reply via email to