<commit_before>package org.simmetrics.metrics;

import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Map.Entry;

import org.simmetrics.ListMetric;

import com.google.common.base.Preconditions;

/**
 * Kendall tau rank distance is a metric that counts the number of pairwise
 * disagreements between two ranking lists. The larger the distance, the more
 * dissimilar the two lists are. Kendall tau distance is also called bubble-sort
 * distance since it is equivalent to the number of swaps that the bubble sort
 * algorithm would make to place one list in the same order as the other list.
 * <p>
 * 
 * The elements in the lists have to implement {@link Object#hashCode()} and
 * {@link Object#equals(Object)}.
 * <p>
 * 
 * Note that this is not a {@link ListMetric} because it does not accept
 * arbitrary lists. The compared lists have to contain the same elements and a
 * list may not contain duplicate elements.
 * <p>
 * 
 * @see <a href="http://en.wikipedia.org/wiki/Kendall_tau_distance">Wikipedia -
 *      Kendall tau distance</a>
 * 
 * @author mpkorstanje
 *
 * @param <T>
 *            the type of elements contained in the lists
 */
public final class KendallTau<T> {

	private final class UniquePairIterator<S> implements Iterator<Entry<S, S>> {
		private final List<S> a;
		private int iteration = 0;
		private final Iterator<S> outerItter;
		private Iterator<S> innerItter;
		private S outerElementT;

		UniquePairIterator(List<S> a) {
			this.a = a;<commit_msg>Java doc<commit_after>package org.simmetrics.metrics;

import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Map.Entry;

import org.simmetrics.ListMetric;

import com.google.common.base.Preconditions;

/**
 * Kendall tau rank distance is a metric that counts the number of pairwise
 * disagreements between two ranking lists. The larger the distance, the more
 * dissimilar the two lists are.
 * <p>
 * Kendall tau distance is also called bubble-sort distance since it is
 * equivalent to the number of swaps that the bubble sort algorithm would make
 * to place one list in the same order as the other list.
 * <p>
 * The Kendall tau distance and similarity is transitive. 
 * <p>
 * The elements in the lists have to implement {@link Object#hashCode()} and
 * {@link Object#equals(Object)}.
 * <p>
 * 
 * Note that this is not a {@link ListMetric} because it does not accept
 * arbitrary lists. The compared lists have to contain the same elements and a
 * list may not contain duplicate elements.
 * <p>
 * 
 * @see <a href="http://en.wikipedia.org/wiki/Kendall_tau_distance">Wikipedia -
 *      Kendall tau distance</a>
 * 
 * @author mpkorstanje
 *
 * @param <T>
 *            the type of elements contained in the lists
 */
public final class KendallTau<T> {

	private final class UniquePairIterator<S> implements Iterator<Entry<S, S>> {
		private final List<S> a;
		private int iteration = 0;
		private final Iterator<S> outerItter;
		private Iterator<S> innerItter;
		private S outerElementT;

		UniquePairIterator(List<S> a) {
			this.a = a;
{'fraction_non_alphanumeric': 0.09038519866545344, 'fraction_numerical': 0.0006066120715802245, 'mean_word_length': 3.989409984871407, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5629601', 'n_tokens_mistral': 1010, 'n_tokens_neox': 955, 'n_words': 378}