summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/Hash-Util/Util.xs23
-rw-r--r--hv_func.h20
2 files changed, 28 insertions, 15 deletions
diff --git a/ext/Hash-Util/Util.xs b/ext/Hash-Util/Util.xs
index 3210200ae7..0687f7f4ce 100644
--- a/ext/Hash-Util/Util.xs
+++ b/ext/Hash-Util/Util.xs
@@ -70,17 +70,28 @@ hash_seed()
void
-hash_value(string)
+hash_value(string,...)
SV* string
- PROTOTYPE: $
+ PROTOTYPE: $;$
PPCODE:
- STRLEN len;
- char *pv;
+{
UV uv;
+ STRLEN len;
+ char *pv= SvPV(string,len);
+ if (items<2) {
+ PERL_HASH(uv, pv, len);
+ } else {
+ STRLEN seedlen;
+ char *seedbuf= SvPV(ST(1),seedlen);
+ if ( seedlen < PERL_HASH_SEED_BYTES ) {
+ sv_dump(ST(1));
+ Perl_croak(aTHX_ "seed len must be at least %d long only got %d bytes", PERL_HASH_SEED_BYTES, seedlen);
+ }
- pv= SvPV(string,len);
- PERL_HASH(uv,pv,len);
+ PERL_HASH_WITH_SEED(seedbuf, uv, pv, len);
+ }
XSRETURN_UV(uv);
+}
void
hash_traversal_mask(rhv, ...)
diff --git a/hv_func.h b/hv_func.h
index 473ec466a7..1923f3ec20 100644
--- a/hv_func.h
+++ b/hv_func.h
@@ -28,38 +28,38 @@
#if defined(PERL_HASH_FUNC_SIPHASH)
# define PERL_HASH_FUNC "SIPHASH_2_4"
# define PERL_HASH_SEED_BYTES 16
-# define PERL_HASH(hash,str,len) (hash)= S_perl_hash_siphash_2_4(PERL_HASH_SEED,(U8*)(str),(len))
+# define PERL_HASH_WITH_SEED(seed,hash,str,len) (hash)= S_perl_hash_siphash_2_4((seed),(U8*)(str),(len))
#elif defined(PERL_HASH_FUNC_SUPERFAST)
# define PERL_HASH_FUNC "SUPERFAST"
# define PERL_HASH_SEED_BYTES 4
-# define PERL_HASH(hash,str,len) (hash)= S_perl_hash_superfast(PERL_HASH_SEED,(U8*)(str),(len))
+# define PERL_HASH_WITH_SEED(seed,hash,str,len) (hash)= S_perl_hash_superfast((seed),(U8*)(str),(len))
#elif defined(PERL_HASH_FUNC_MURMUR3)
# define PERL_HASH_FUNC "MURMUR3"
# define PERL_HASH_SEED_BYTES 4
-# define PERL_HASH(hash,str,len) (hash)= S_perl_hash_murmur3(PERL_HASH_SEED,(U8*)(str),(len))
+# define PERL_HASH_WITH_SEED(seed,hash,str,len) (hash)= S_perl_hash_murmur3((seed),(U8*)(str),(len))
#elif defined(PERL_HASH_FUNC_DJB2)
# define PERL_HASH_FUNC "DJB2"
# define PERL_HASH_SEED_BYTES 4
-# define PERL_HASH(hash,str,len) (hash)= S_perl_hash_djb2(PERL_HASH_SEED,(U8*)(str),(len))
+# define PERL_HASH_WITH_SEED(seed,hash,str,len) (hash)= S_perl_hash_djb2((seed),(U8*)(str),(len))
#elif defined(PERL_HASH_FUNC_SDBM)
# define PERL_HASH_FUNC "SDBM"
# define PERL_HASH_SEED_BYTES 4
-# define PERL_HASH(hash,str,len) (hash)= S_perl_hash_sdbm(PERL_HASH_SEED,(U8*)(str),(len))
+# define PERL_HASH_WITH_SEED(seed,hash,str,len) (hash)= S_perl_hash_sdbm((seed),(U8*)(str),(len))
#elif defined(PERL_HASH_FUNC_ONE_AT_A_TIME_HARD)
# define PERL_HASH_FUNC "ONE_AT_A_TIME_HARD"
# define PERL_HASH_SEED_BYTES 8
-# define PERL_HASH(hash,str,len) (hash)= S_perl_hash_one_at_a_time_hard(PERL_HASH_SEED,(U8*)(str),(len))
+# define PERL_HASH_WITH_SEED(seed,hash,str,len) (hash)= S_perl_hash_one_at_a_time_hard((seed),(U8*)(str),(len))
#elif defined(PERL_HASH_FUNC_ONE_AT_A_TIME)
# define PERL_HASH_FUNC "ONE_AT_A_TIME"
# define PERL_HASH_SEED_BYTES 4
-# define PERL_HASH(hash,str,len) (hash)= S_perl_hash_one_at_a_time(PERL_HASH_SEED,(U8*)(str),(len))
+# define PERL_HASH_WITH_SEED(seed,hash,str,len) (hash)= S_perl_hash_one_at_a_time((seed),(U8*)(str),(len))
#elif defined(PERL_HASH_FUNC_ONE_AT_A_TIME_OLD)
# define PERL_HASH_FUNC "ONE_AT_A_TIME_OLD"
# define PERL_HASH_SEED_BYTES 4
-# define PERL_HASH(hash,str,len) (hash)= S_perl_hash_old_one_at_a_time(PERL_HASH_SEED,(U8*)(str),(len))
+# define PERL_HASH_WITH_SEED(seed,hash,str,len) (hash)= S_perl_hash_old_one_at_a_time((seed),(U8*)(str),(len))
#endif
-#ifndef PERL_HASH
+#ifndef PERL_HASH_WITH_SEED
#error "No hash function defined!"
#endif
#ifndef PERL_HASH_SEED_BYTES
@@ -81,6 +81,8 @@
# endif
#endif
+#define PERL_HASH(hash,str,len) PERL_HASH_WITH_SEED(PERL_HASH_SEED,hash,str,len)
+
/*-----------------------------------------------------------------------------
* Endianess, misalignment capabilities and util macros
*