And - in case you're looking for an implementation of the 32-bit mumurhash
in PL/I, here's the code I came up with.

Note, mumurash is endian-dependent (you get different values on big-endian
vs. little-endian machines).   Also, the 128-bit version does not generate the
same values as the 32-bit version.

But - I slapped this together from the C source, and verified it got the same
results with the small example found here:

 test: proc options(main);

  mumur3_32: proc(data, nbytes) returns(fixed unsigned bin(32));
    dcl data pointer;
    dcl nbytes fixed bin(31);
   
    if (data = SYSNULL() | nbytes = 0) then
       return (0);
   
    dcl c1 unsigned fixed bin(32) init('cc9e2d51'XU);
    dcl c2 unsigned fixed bin(32) init('1b873593'XU);
   
    dcl nblocks fixed bin(31) init(ISRL(nbytes,2)); /* nbytes/4 */
    dcl blocks(0:(nblocks-1)) unsigned fixed bin(32) based(data);
    dcl tail(0:2) unsigned fixed bin(8) based(tailp);
   
    dcl tailp pointer;
    tailp = pointeradd(data, nbytes * 4);
   
    dcl h unsigned fixed bin(32) init(0);
    dcl i fixed bin(31);
    dcl k unsigned fixed bin(32);
   
    do i=0 to nblocks-1;
       k = blocks(i);
   
       k = k * c1;
       k = ior(isll(k,15), isrl(k, 32-15));
       k = k * c2;
   
       h = ieor(h,k);
       h = ior(isll(h,13), isrl(h, 32-13));
       h = (h * 5) + 'e6546b64'xu;
     end;
   
     k = 0;
     select( iand(nbytes, 3) );
       when(3) do;
         k = ieor(k, isll(tail(2), 16));
         goto case_2;
       end;
       when(2) do;
    case_2: ;
         k = ieor(k, isll(tail(1), 8));
         goto case_1;
       end;
       when(1) do;
    case_1: ;
         k = ieor(k, tail(0));
         k = k * c1;
         k = ieor( isll(k,15), isrl(k,32-15));
         k = k * c2;
         h = ieor(h, k);
       end;
     otherwise; /* do nothing */
    end;
    
    h = ieor(h, nbytes);
   
    h = ieor(h, isrl(h,16));
    h = h * '85ebca6b'xu;
    h = ieor(h, isrl(h,13));
    h = h * 'c2b2ae35'xu;
    h = ieor(h, isrl(h,16));
     
    return(h); 
 end;

  dcl data char(28) init('Some string data to test out');
  dcl val fixed bin(32) unsigned;

  val = mumur3_32(addr(data), length(data));

  put skip list('val is ', val);
 end;


    - Dave R. -

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to