On 03/11/2011, at 2:41 AM, Doug Baskins wrote:
> John:
>
> The Judy API has always been awkward. I have never been happy with it.
> I have received a lot of criticism about it over the years. I challenge
> anyone to come up with a better one, but so far there have been no takers
> (that actually deliver a Judy.h file with the prototypes that can possibly
> work).
In C, the value and key types are intended to be polymorphic, but C doesn't
provide and easy way to represent that. This is not your fault.
Contrarily, I think the C function API is "perfect", modulo some possible
compromise choices of the argument and return types. Its actually the macros
I myself dislike because they hide the value/lvalue distinction exposed
by the functions eg JudySLIns requires a pointer to an array but JudySLFirst
only needs the array value.
I also don't like the names First, Next: should really have been GreaterEqual
and Greater. One has to pay attention that First requires a starting key.
In C++ it is possible to do better using templates, however it is not trivial:
for values there are two cases: an integer sized thing OR a pointer,
and the specialisations required to enforce type correctness will probably
fail to handle memory correctly.
In fact I think in Felix it can be done quite nicely because it has
constrained polymorphism and typeclasses, and the management of
pointers can be automatic (using garbage collector).
Anyhow, my actual suggestion was only a minor improvement: how to
help get the array type correct. Functions that accept a void* (JudySLFirst,
etc)
are susceptible to error because in C ANY pointer can convert to a void*.
JudySLIns is safer because it accepts a void** as the array.
The proposal is reasonable in that there is rarely any need to cast the array
types.
The only downside is in C, where you'd have to write:
JudySLArray a = { 0 };
instead of
void *a = 0;
--
john skaller
[email protected]
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Judy-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/judy-devel