class JaccardDistance extends FastDistance {

	@Override
	public double calc(double[] array1, double[] array2) {
		if(array1.length > array2.length){
			double[] tmp = array1;
			array1 = array2;
			array2 = tmp;
		}
		int intersect = 0, union = 0;
		for(int i = 0; i < array1.length; i++){
			if(array1[i] != 0 && array2[i] != 0){
				intersect++;
				union++;
			}else if(array1[i] != 0 || array2[i] != 0){
				union++;
			}
		}
		for(int i = array1.length; i < array2.length; i++){
			if(array2[i] != 0){
				union++;
			}
		}
		return 1 - (double) intersect / union;
	}

}