Hello, Would it be possible to relicense hash-pjw under LGPLv2+ or v3+? It is quite a useful function and I'd like to use it in gnutls and libtasn1 (I could re-implement it but I'd like to avoid that if possible). Also would it be possible to have a version that works with non-null terminated strings? (patch attached).
A question on this function is why do you use char *s to describe input and not unsigned char*? Given that h is unsigned anyway I don't see the purpose for having s signed. regards, Nikos
diff --git a/lib/hash-pjw.c b/lib/hash-pjw.c index 0966598..8ee7c27 100644 --- a/lib/hash-pjw.c +++ b/lib/hash-pjw.c @@ -38,3 +38,15 @@ hash_pjw (const void *x, size_t tablesize) return h % tablesize; } + +size_t +hash_pjw_s (const void *x, size_t x_size, size_t tablesize) +{ + const unsigned char *s; + size_t i, h = 0; + + for (i=0; i<x_size; i++) + h = s[i] + ((h << 9) | (h >> (SIZE_BITS - 9))); + + return h % tablesize; +} diff --git a/lib/hash-pjw.h b/lib/hash-pjw.h index 6404916..5d39877 100644 --- a/lib/hash-pjw.h +++ b/lib/hash-pjw.h @@ -21,3 +21,4 @@ The result is platform dependent: it depends on the size of the 'size_t' type and on the signedness of the 'char' type. */ extern size_t hash_pjw (void const *x, size_t tablesize) _GL_ATTRIBUTE_PURE; +extern size_t hash_pjw_s (void const *x, size_t x_size, size_t tablesize) _GL_ATTRIBUTE_PURE;