package org.antlr.codebuff.misc;

import java.util.Arrays;
import java.util.List;

public class ClassifierResultCacheKey {
	int[] features;
	List<Integer> Y;

	public ClassifierResultCacheKey(int[] features, List<Integer> y) {
		this.features = features;
		Y = y;
	}

	@Override
	public int hashCode() {
		int h = 0;
		for (int feature : features) {
			h += feature << 7;
		}
		return h + System.identityHashCode(Y)<<7;
	}

	@Override
	public boolean equals(Object obj) {
		if ( !(obj instanceof ClassifierResultCacheKey) ) return false;
		ClassifierResultCacheKey other = (ClassifierResultCacheKey) obj;
		return Arrays.equals(features, other.features) &&
			Y == other.Y;
	}

	@Override
	public String toString() {
		return Arrays.toString(features)+"/"+System.identityHashCode(Y);
	}
}

@@ -27,16 +27,62 @@
 .misc;%0A%0A
+import org.antlr.v4.runtime.misc.MurmurHash;%0A%0A
 import j
@@ -354,12 +354,37 @@
 nt h
- = 0
+ash = MurmurHash.initialize()
 ;%0A%09%09
@@ -422,19 +422,45 @@
 %09%09%09h
- +=
+ash = MurmurHash.update(hash,
  feature
  %3C%3C 
@@ -459,21 +459,17 @@
 ture
- %3C%3C 7
+)
 ;%0A%09%09%7D%0A%09%09
 retu
@@ -468,48 +468,121 @@
 %7D%0A%09%09
-return h + System.identityHashCode(Y)%3C%3C7
+hash = MurmurHash.update(hash, System.identityHashCode(Y));%0A%09%09return MurmurHash.finish(hash, features.length + 1)
 ;%0A%09%7D
@@ -637,16 +637,62 @@
 %7B%0A%09%09if (
+obj == this) %7B%0A%09%09%09return true;%0A%09%09%7D%0A%09%09else if (
  !(obj i
@@ -729,16 +729,21 @@
 eKey) ) 
+%7B%0A%09%09%09
 return f
@@ -748,16 +748,20 @@
  false;%0A
+%09%09%7D%0A
 %09%09Classi

use better hash function