RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package rlpark.plugin.rltoys.algorithms.representations.tilescoding.hashing; 00002 00003 import java.util.Random; 00004 00005 public class MurmurHashing extends AbstractHashing { 00006 private static final long serialVersionUID = -7644303591039542570L; 00007 private final int seed; 00008 00009 public MurmurHashing(Random random, int memorySize) { 00010 super(memorySize); 00011 seed = random.nextInt(); 00012 } 00013 00014 @Override 00015 protected int hash(int[] coordinates) { 00016 byte[] data = new byte[coordinates.length]; 00017 coordinates[0] = (coordinates[0] - Byte.MIN_VALUE) % (Byte.MAX_VALUE - Byte.MIN_VALUE) + Byte.MIN_VALUE; 00018 for (int i = 0; i < data.length; i++) { 00019 assert coordinates[i] >= Byte.MIN_VALUE && coordinates[i] <= Byte.MAX_VALUE; 00020 data[i] = (byte) coordinates[i]; 00021 } 00022 return (int) (((long) MurmurHash2.hash(data, seed) + Integer.MAX_VALUE) % memorySize); 00023 } 00024 00025 }