[Python-checkins] CVS: python/dist/src/Modules ucnhash.c,1.2,1.3

Jeremy Hylton python-dev@python.org
Tue, 25 Jul 2000 20:56:09 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv19915/Modules

Modified Files:
	ucnhash.c 
Log Message:
Fix UCNs machine with >= 32bit longs
originally submitted by Bill Tutt

Note: This code is actually going to be replaced in 2.0 by /F's new
database.  Until then, this patch keeps the test suite working.


Index: ucnhash.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/ucnhash.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ucnhash.c	2000/06/29 00:06:39	1.2
--- ucnhash.c	2000/07/26 03:56:06	1.3
***************
*** 12,16 ****
   * http://starship.python.net/crew/amk/python/code/perfect-hash.html
   *
!  * Generated on: Wed Jun 28 03:34:07 2000
   */
  
--- 12,16 ----
   * http://starship.python.net/crew/amk/python/code/perfect-hash.html
   *
!  * Generated on: Fri Jul 14 08:00:58 2000
   */
  
***************
*** 27,44 ****
      register int len;
      register unsigned char *p;
!     register long x;
  
      len = cch;
      p = (unsigned char *) key;
!     x = 1694245428;
      while (--len >= 0)
!         x = (1000003*x) ^ toupper(*(p++));
      x ^= cch + 10;
!     if (x == -1)
!         x = -2;
!     x %= k_cHashElements;
!     /* ensure the returned value is positive so we mimic Python's % operator */
!     if (x < 0)
!       x += k_cHashElements;
      return x;
  }
--- 27,60 ----
      register int len;
      register unsigned char *p;
!     register unsigned long x;
  
      len = cch;
      p = (unsigned char *) key;
!     x = 0x64fc2234;
      while (--len >= 0)
!     {   
!         /* (1000003 * x) ^ toupper(*(p++)) 
!          * translated to handle > 32 bit longs 
!          */
!         x = (0xf4243 * x);
!         x = x & 0xFFFFFFFF;
!         x = x ^ toupper(*(p++));
!     }
      x ^= cch + 10;
!     if (x == 0xFFFFFFFF)
!         x = 0xfffffffe;
!     if (x & 0x80000000) 
!     {
!         /* Emulate 32-bit signed (2's complement) modulo operation */
!         x = (~x & 0xFFFFFFFF) + 1;
!         x %= k_cHashElements;
!         if (x != 0)
!         {
!             x = x + (~k_cHashElements & 0xFFFFFFFF) + 1;
!             x = (~x & 0xFFFFFFFF) + 1;
!         }
!     }
!     else
!         x %= k_cHashElements;
      return x;
  }
***************
*** 49,66 ****
      register int len;
      register unsigned char *p;
!     register long x;
  
      len = cch;
      p = (unsigned char *) key;
!     x = -1917331657;
      while (--len >= 0)
!         x = (1000003*x) ^ toupper(*(p++));
      x ^= cch + 10;
!     if (x == -1)
!         x = -2;
!     x %= k_cHashElements;
!     /* ensure the returned value is positive so we mimic Python's % operator */
!     if (x < 0)
!       x += k_cHashElements;
      return x;
  }
--- 65,98 ----
      register int len;
      register unsigned char *p;
!     register unsigned long x;
  
      len = cch;
      p = (unsigned char *) key;
!     x = 0x8db7d737;
      while (--len >= 0)
!     {   
!         /* (1000003 * x) ^ toupper(*(p++)) 
!          * translated to handle > 32 bit longs 
!          */
!         x = (0xf4243 * x);
!         x = x & 0xFFFFFFFF;
!         x = x ^ toupper(*(p++));
!     }
      x ^= cch + 10;
!     if (x == 0xFFFFFFFF)
!         x = 0xfffffffe;
!     if (x & 0x80000000) 
!     {
!         /* Emulate 32-bit signed (2's complement) modulo operation */
!         x = (~x & 0xFFFFFFFF) + 1;
!         x %= k_cHashElements;
!         if (x != 0)
!         {
!             x = x + (~k_cHashElements & 0xFFFFFFFF) + 1;
!             x = (~x & 0xFFFFFFFF) + 1;
!         }
!     }
!     else
!         x %= k_cHashElements;
      return x;
  }