-/* Copyright (C) 1995,1996,1997, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997, 2000, 2001, 2003 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
unsigned long
scm_string_hash (const unsigned char *str, size_t len)
{
- if (len > 5)
- {
- size_t i = 5;
- unsigned long h = 264;
- while (i--)
- h = (h << 8) + (unsigned) str[h % len];
- return h;
- }
- else
- {
- size_t i = len;
- unsigned long h = 0;
- while (i)
- h = (h << 8) + (unsigned) str[--i];
- return h;
- }
+ /* from suggestion at: */
+ /* http://srfi.schemers.org/srfi-13/mail-archive/msg00112.html */
+
+ unsigned long h = 0;
+ while (len-- > 0)
+ h = *str++ + h*37;
+ return h;
}
return SCM_INUM(obj) % n; /* SCM_INUMP(obj) */
case scm_tc3_imm24:
if (SCM_CHARP(obj))
- return (unsigned)(scm_downcase(SCM_CHAR(obj))) % n;
+ return (unsigned)(scm_c_downcase(SCM_CHAR(obj))) % n;
switch (SCM_UNPACK (obj)) {
#ifndef SICP
case SCM_UNPACK(SCM_EOL):
default:
return 263 % n;
case scm_tc7_smob:
+ return 263 % n;
+ case scm_tc7_number:
switch SCM_TYP16 (obj) {
case scm_tc16_big:
return SCM_INUM (scm_modulo (obj, SCM_MAKINUM (n)));
- default:
- return 263 % n;
case scm_tc16_real:
{
double r = SCM_REAL_VALUE (obj);
return SCM_INUM (scm_modulo (obj, SCM_MAKINUM (n)));
}
}
+ /* Fall through */
case scm_tc16_complex:
+ case scm_tc16_fraction:
obj = scm_number_to_string (obj, SCM_MAKINUM (10));
+ /* Fall through */
}
+ /* Fall through */
case scm_tc7_string:
return scm_string_hash (SCM_STRING_UCHARS (obj), SCM_STRING_LENGTH (obj)) % n;
case scm_tc7_symbol:
scm_ihashv (SCM obj, unsigned long n)
{
if (SCM_CHARP(obj))
- return ((unsigned long) (scm_downcase (SCM_CHAR (obj)))) % n; /* downcase!?!! */
+ return ((unsigned long) (scm_c_downcase (SCM_CHAR (obj)))) % n; /* downcase!?!! */
if (SCM_NUMP(obj))
return (unsigned long) scm_hasher(obj, n, 10);