RLPark 1.0.0
Reinforcement Learning Framework in Java

MurmurHash2.java

Go to the documentation of this file.
00001 package rlpark.plugin.rltoys.algorithms.representations.tilescoding.hashing;
00002 
00003 //Ported by Derek Young from the C version (specifically the endian-neutral
00004 //version) from:
00005 //http://murmurhash.googlepages.com/
00006 //
00007 //released to the public domain - dmy999@gmail.com
00008 public class MurmurHash2 {
00009   @SuppressWarnings("fallthrough")
00010   public static int hash(byte[] data, int seed) {
00011     // 'm' and 'r' are mixing constants generated offline.
00012     // They're not really 'magic', they just happen to work well.
00013     int m = 0x5bd1e995;
00014     int r = 24;
00015 
00016     // Initialize the hash to a 'random' value
00017     int len = data.length;
00018     int h = seed ^ len;
00019 
00020     int i = 0;
00021     while (len >= 4) {
00022       int k = data[i + 0] & 0xFF;
00023       k |= (data[i + 1] & 0xFF) << 8;
00024       k |= (data[i + 2] & 0xFF) << 16;
00025       k |= (data[i + 3] & 0xFF) << 24;
00026 
00027       k *= m;
00028       k ^= k >>> r;
00029       k *= m;
00030 
00031       h *= m;
00032       h ^= k;
00033 
00034       i += 4;
00035       len -= 4;
00036     }
00037 
00038     switch (len) {
00039     case 3:
00040       h ^= (data[i + 2] & 0xFF) << 16;
00041     case 2:
00042       h ^= (data[i + 1] & 0xFF) << 8;
00043     case 1:
00044       h ^= data[i + 0] & 0xFF;
00045       h *= m;
00046     }
00047     h ^= h >>> 13;
00048     h *= m;
00049     h ^= h >>> 15;
00050     return h;
00051   }
00052 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark