<commit_before>package com.nhn.hippo.web.calltree.span;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.profiler.common.bo.SpanBo;
import com.profiler.common.bo.SubSpanBo;

/**
 * 
 * @author netspider
 * 
 */
public class SpanAligner2 {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	private final Map<Long, SpanBo> spanMap;
	private Long rootSpanId;

	public SpanAligner2(List<SpanBo> spans) {
		spanMap = new HashMap<Long, SpanBo>(spans.size());

		long rootSpanStartTime = Long.MAX_VALUE;

		for (SpanBo span : spans) {
			if (spanMap.containsKey(Long.valueOf(span.getSpanId()))) {
				throw new IllegalStateException("duplicated spanId. id:" + span.getSpanId());
			}

			if (span.getStartTime() < rootSpanStartTime) {
				rootSpanId = (span.getParentSpanId() == -1) ? -1L : span.getSpanId();
				rootSpanStartTime = span.getStartTime();
			}

			this.spanMap.put((span.getParentSpanId() == -1) ? -1L : span.getSpanId(), span);
		}
	}

	public List<SpanAlign> sort() {
		List<SpanAlign> list = new ArrayList<SpanAlign>();
		SpanBo root = spanMap.get(rootSpanId);

		if (root == null) {
			throw new IllegalStateException("root span not found. rootSpanId=" + rootSpanId + ", map=" + spanMap.keySet());
		}

		populate(root, 0, list);<commit_msg>[유치수] [NOBTS] root span 찾는 방법 변경.<commit_after>package com.nhn.hippo.web.calltree.span;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.profiler.common.bo.SpanBo;
import com.profiler.common.bo.SubSpanBo;

/**
 * 
 * @author netspider
 * 
 */
public class SpanAligner2 {

	private final Map<Long, SpanBo> spanMap;
	private Long rootSpanId = null;

	public SpanAligner2(List<SpanBo> spans) {
		spanMap = new HashMap<Long, SpanBo>(spans.size());

		long rootSpanStartTime = Long.MAX_VALUE;

		for (SpanBo span : spans) {
			if (spanMap.containsKey(Long.valueOf(span.getSpanId()))) {
				throw new IllegalStateException("duplicated spanId. id:" + span.getSpanId());
			}

			if (span.getParentSpanId() == -1L) {
				rootSpanId = -1L;
				spanMap.put(-1L, span);
				continue;
			} else if (rootSpanId != -1 && span.getStartTime() < rootSpanStartTime) {
				rootSpanId = (span.getParentSpanId() == -1) ? -1L : span.getSpanId();
				rootSpanStartTime = span.getStartTime();
			}
			spanMap.put(span.getSpanId(), span);
		}
	}

	public List<SpanAlign> sort() {
		List<SpanAlign> list = new ArrayList<SpanAlign>();
		SpanBo root = spanMap.get(rootSpanId);

		if (root == null) {
			throw new IllegalStateException("root span not found. rootSpanId=" + rootSpanId + ", map=" + spanMap.keySet());
		}

		populate(root, 0, list);
{'fraction_non_alphanumeric': 0.14778856526429343, 'fraction_numerical': 0.006472491909385114, 'mean_word_length': 4.151851851851852, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '5106580', 'n_tokens_mistral': 1069, 'n_tokens_neox': 994, 'n_words': 203}