guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 16/19: Merge commit '894d0b894daae001495c748b3352cd79918


From: Andy Wingo
Subject: [Guile-commits] 16/19: Merge commit '894d0b894daae001495c748b3352cd79918d3789'
Date: Thu, 22 Jan 2015 13:54:49 +0000

wingo pushed a commit to branch master
in repository guile.

commit baf90102cf39f4fdfb446df9ba8f4407b88ea794
Merge: 1cd7791 894d0b8
Author: Andy Wingo <address@hidden>
Date:   Thu Jan 22 14:48:40 2015 +0100

    Merge commit '894d0b894daae001495c748b3352cd79918d3789'
    
    Conflicts:
        libguile/hash.c

 libguile/hash.c |    8 +-------
 libguile/hash.h |    4 ++--
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --cc libguile/hash.c
index 0ac67fa,e5568ee..b0bf046
--- a/libguile/hash.c
+++ b/libguile/hash.c
@@@ -45,94 -45,25 +45,88 @@@
  extern double floor();
  #endif
  
 -#define SCM_MIN(A, B) ((A) < (B) ? (A) : (B))
  
 -#if SCM_ENABLE_DEPRECATED == 1
 +/* This hash function is originally from
 +   http://burtleburtle.net/bob/c/lookup3.c by Bob Jenkins, May 2006,
 +   Public Domain.  No warranty.  */
 +
 +#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
 +#define mix(a,b,c) \
 +{ \
 +  a -= c;  a ^= rot(c, 4);  c += b; \
 +  b -= a;  b ^= rot(a, 6);  a += c; \
 +  c -= b;  c ^= rot(b, 8);  b += a; \
 +  a -= c;  a ^= rot(c,16);  c += b; \
 +  b -= a;  b ^= rot(a,19);  a += c; \
 +  c -= b;  c ^= rot(b, 4);  b += a; \
 +}
  
 -unsigned long
 -scm_string_hash (const unsigned char *str, size_t len)
 -{
 -  /* from suggestion at: */
 -  /* http://srfi.schemers.org/srfi-13/mail-archive/msg00112.html */
 +#define final(a,b,c) \
 +{ \
 +  c ^= b; c -= rot(b,14); \
 +  a ^= c; a -= rot(c,11); \
 +  b ^= a; b -= rot(a,25); \
 +  c ^= b; c -= rot(b,16); \
 +  a ^= c; a -= rot(c,4);  \
 +  b ^= a; b -= rot(a,14); \
 +  c ^= b; c -= rot(b,24); \
 +}
  
 -  unsigned long h = 0;
 -  while (len-- > 0)
 -    h = *str++ + h*37;
 -  return h;
 +#define JENKINS_LOOKUP3_HASHWORD2(k, length, ret)                       \
 +  do {                                                                  \
 +    scm_t_uint32 a, b, c;                                               \
 +                                                                        \
 +    /* Set up the internal state.  */                                   \
 +    a = b = c = 0xdeadbeef + ((scm_t_uint32)(length<<2)) + 47;          \
 +                                                                        \
 +    /* Handle most of the key.  */                                      \
 +    while (length > 3)                                                  \
 +      {                                                                 \
 +        a += k[0];                                                      \
 +        b += k[1];                                                      \
 +        c += k[2];                                                      \
 +        mix (a, b, c);                                                  \
 +        length -= 3;                                                    \
 +        k += 3;                                                         \
 +      }                                                                 \
 +                                                                        \
 +    /* Handle the last 3 elements.  */                                  \
 +    switch(length) /* All the case statements fall through.  */         \
 +      {                                                                 \
 +      case 3 : c += k[2];                                               \
 +      case 2 : b += k[1];                                               \
 +      case 1 : a += k[0];                                               \
 +        final (a, b, c);                                                \
 +      case 0:     /* case 0: nothing left to add */                     \
 +        break;                                                          \
 +      }                                                                 \
 +                                                                        \
 +    if (sizeof (ret) == 8)                                              \
 +      ret = (((unsigned long) c) << 32) | b;                            \
 +    else                                                                \
 +      ret = c;                                                          \
 +  } while (0)
 +
 +
 +static unsigned long
 +narrow_string_hash (const scm_t_uint8 *str, size_t len)
 +{
 +  unsigned long ret;
 +  JENKINS_LOOKUP3_HASHWORD2 (str, len, ret);
 +  ret >>= 2; /* Ensure that it fits in a fixnum.  */
 +  return ret;
  }
  
 -#endif
 +static unsigned long
 +wide_string_hash (const scm_t_wchar *str, size_t len)
 +{
 +  unsigned long ret;
 +  JENKINS_LOOKUP3_HASHWORD2 (str, len, ret);
 +  ret >>= 2; /* Ensure that it fits in a fixnum.  */
 +  return ret;
 +}
  
  unsigned long 
- scm_string_hash (const unsigned char *str, size_t len)
- {
-   return narrow_string_hash (str, len);
- }
- 
- unsigned long 
  scm_i_string_hash (SCM str)
  {
    size_t len = scm_i_string_length (str);
diff --cc libguile/hash.h
index d3e42f1,735f8c8..9085bc0
--- a/libguile/hash.h
+++ b/libguile/hash.h
@@@ -27,7 -28,14 +28,6 @@@
  
  
  
- SCM_API unsigned long scm_string_hash (const unsigned char *str, size_t len);
 -#if SCM_ENABLE_DEPRECATED == 1
 -
 -/* Deprecated in 2.0.12.  */
 -SCM_DEPRECATED unsigned long scm_string_hash (const unsigned char *str,
 -                                            size_t len);
 -
 -#endif
 -
  SCM_INTERNAL unsigned long scm_i_locale_string_hash (const char *str,
                                                       size_t len);
  SCM_INTERNAL unsigned long scm_i_latin1_string_hash (const  char *str,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]