<commit_before>package com.alio.structure;

import java.util.ArrayList;
import java.util.List;

public class Tree<K, W> {

	private List<Node<K, W>> mNodeList;

	public static class Pair<K, W> {

		K k;

		W w;

		public Pair(K k, W w) {
			super();
			this.k = k;
			this.w = w;
		}

		public K getK() {
			return k;
		}

		public void setK(K k) {
			this.k = k;
		}

		public W getW() {
			return w;
		}

		public void setW(W w) {
			this.w = w;
		}

	}

	@SuppressWarnings("hiding")
	private class Node<K, W> {
		K k;
		W w;

		private List<Node<K, W>> mSubNodes;

		private Node(K k) {
			super();
			this.k = k;
			mSubNodes = new ArrayList<>();
		}

		private Node(K k, W w) {
			super();
			this.k = k;
			this.w = w;
			mSubNodes = new ArrayList<>();
		}

		public Node<K, W> getSubNode(List<K> kList, boolean needNewNode) {
			K k = kList.remove(0);
			Node<K, W> kNode = null;
			Node<K, W> temp = new Node<K, W>(k);
			if (mSubNodes.contains(temp)) {
				kNode = mSubNodes.get(mSubNodes.indexOf(temp));
			} else {
				if (needNewNode) {
					kNode = new Node<K, W>(k);
					mSubNodes.add(kNode);
				} else {
					return null;
				}
			}
			if (kList.size() > 0) {
				return kNode.getSubNode(kList, needNewNode);
			} else {
				return kNode;
			}
		}

		public List<Pair<List<K>, W>> dump(List<K> superList) {
			List<Pair<List<K>, W>> result = new ArrayList<>();
			if (w != null) {
				result.add(new Pair<>(superList, w));
			} else {
				List<K> superList1 = null;
				for (Node<K, W> node : mSubNodes) {
					superList1 = new ArrayList<K>();
					superList1.addAll(superList);
					superList1.add(node.getKey());
					result.addAll(node.dump(superList1));
				}
			}
			return result;
		}

		public void setWeight(W w) {
			this.w = w;
		}

		public W getWeight() {
			return this.w;
		}

		public K getKey() {
			return this.k;
		}

		@SuppressWarnings("unchecked")
		@Override
		public boolean equals(Object obj) {
			if (this.k == null && obj == null) {
				return true;
			} else if (this.k == null && obj != null || obj == null && this.k != null) {
				return false;
			} else if (obj instanceof Node) {
				return this.k.equals(((Node<K, W>) obj).k);
			} else {
				return false;
			}
		}

		@Override
		public int hashCode() {
			return this.k.hashCode();
		}

	}

	public Tree() {
		super();
		mNodeList = new ArrayList<>();
	}

	private Node<K, W> getNode(List<K> kList, boolean needNewNode) {
		K k = kList.remove(0);
		Node<K, W> kNode = null;
		Node<K, W> temp = new Node<K, W>(k);
		if (mNodeList.contains(temp)) {
			kNode = mNodeList.get(mNodeList.indexOf(temp));
		} else {
			if (needNewNode) {
				kNode = new Node<K, W>(k);
				mNodeList.add(kNode);
			} else {
				return null;
			}
		}
		if (kList.size() > 0) {
			return kNode.getSubNode(kList, needNewNode);
		} else {
			return kNode;
		}
	}

	public void append(List<K> kList, W w) {
		getNode(kList, true).setWeight(w);
	}

	public W getNodeWeight(List<K> kList) {
		Node<K, W> result = getNode(kList, false);
		return result == null ? null : result.getWeight();
	}

	public boolean isLeaf(List<K> kList) {
		Node<K, W> result = getNode(kList, false);
		return result != null && result.getWeight() != null;
	}

	public List<Pair<List<K>, W>> dump() {<commit_msg>add contains func<commit_after>package com.alio.structure;

import java.util.ArrayList;
import java.util.List;

public class Tree<K, W> {

	private List<Node<K, W>> mNodeList;

	public static class Pair<K, W> {

		K k;

		W w;

		public Pair(K k, W w) {
			super();
			this.k = k;
			this.w = w;
		}

		public K getK() {
			return k;
		}

		public void setK(K k) {
			this.k = k;
		}

		public W getW() {
			return w;
		}

		public void setW(W w) {
			this.w = w;
		}

	}

	@SuppressWarnings("hiding")
	private class Node<K, W> {
		K k;
		W w;

		private List<Node<K, W>> mSubNodes;

		private Node(K k) {
			super();
			this.k = k;
			mSubNodes = new ArrayList<>();
		}

		private Node(K k, W w) {
			super();
			this.k = k;
			this.w = w;
			mSubNodes = new ArrayList<>();
		}

		public Node<K, W> getSubNode(List<K> kList, boolean needNewNode) {
			K k = kList.remove(0);
			Node<K, W> kNode = null;
			Node<K, W> temp = new Node<K, W>(k);
			if (mSubNodes.contains(temp)) {
				kNode = mSubNodes.get(mSubNodes.indexOf(temp));
			} else {
				if (needNewNode) {
					kNode = new Node<K, W>(k);
					mSubNodes.add(kNode);
				} else {
					return null;
				}
			}
			if (kList.size() > 0) {
				return kNode.getSubNode(kList, needNewNode);
			} else {
				return kNode;
			}
		}

		public List<Pair<List<K>, W>> dump(List<K> superList) {
			List<Pair<List<K>, W>> result = new ArrayList<>();
			if (w != null) {
				result.add(new Pair<>(superList, w));
			} else {
				List<K> superList1 = null;
				for (Node<K, W> node : mSubNodes) {
					superList1 = new ArrayList<K>();
					superList1.addAll(superList);
					superList1.add(node.getKey());
					result.addAll(node.dump(superList1));
				}
			}
			return result;
		}

		public void setWeight(W w) {
			this.w = w;
		}

		public W getWeight() {
			return this.w;
		}

		public K getKey() {
			return this.k;
		}

		@SuppressWarnings("unchecked")
		@Override
		public boolean equals(Object obj) {
			if (this.k == null && obj == null) {
				return true;
			} else if (this.k == null && obj != null || obj == null && this.k != null) {
				return false;
			} else if (obj instanceof Node) {
				return this.k.equals(((Node<K, W>) obj).k);
			} else {
				return false;
			}
		}

		@Override
		public int hashCode() {
			return this.k.hashCode();
		}

	}

	public Tree() {
		super();
		mNodeList = new ArrayList<>();
	}

	private Node<K, W> getNode(List<K> kList, boolean needNewNode) {
		K k = kList.remove(0);
		Node<K, W> kNode = null;
		Node<K, W> temp = new Node<K, W>(k);
		if (mNodeList.contains(temp)) {
			kNode = mNodeList.get(mNodeList.indexOf(temp));
		} else {
			if (needNewNode) {
				kNode = new Node<K, W>(k);
				mNodeList.add(kNode);
			} else {
				return null;
			}
		}
		if (kList.size() > 0) {
			return kNode.getSubNode(kList, needNewNode);
		} else {
			return kNode;
		}
	}

	public void append(List<K> kList, W w) {
		getNode(kList, true).setWeight(w);
	}

	public W getNodeWeight(List<K> kList) {
		Node<K, W> result = getNode(kList, false);
		return result == null ? null : result.getWeight();
	}

	public boolean isLeaf(List<K> kList) {
		Node<K, W> result = getNode(kList, false);
		return result != null && result.getWeight() != null;
	}

	public boolean contains(List<K> kList) {
		Node<K, W> result = getNode(kList, false);
		return result != null;
	}

	public List<Pair<List<K>, W>> dump() {
{'fraction_non_alphanumeric': 0.16470765521398434, 'fraction_numerical': 0.0027124773960217, 'mean_word_length': 2.74548532731377, 'pattern_counts': {'":': 0, '<': 91, '<?xml version=': 0, '>': 95, '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': '2209528', 'n_tokens_mistral': 3082, 'n_tokens_neox': 2592, 'n_words': 646}