<commit_before>package com.cafeform.algorithm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * Another implementation of bredth first search.
 * Uses color and predecesser HashMap to check the status of each node
 *  color : Back=Found, Gray=Found, but not child search, White=Not found
 *  predeccessor : parent node
 * 
 * @author kaizawa
 */
class BreadthFirstSearch2 extends SearchAlgorithm {
    LinkedBlockingDeque<Node> foundNodeQueue = new LinkedBlockingDeque<>();
    HashMap<Node, Color> colorMap = new HashMap<>();
    HashMap<Node, Node> predeccessorMap = new HashMap(); 
    
    enum Color {BLACK, WHITE, GRAY};

    public BreadthFirstSearch2(List<Node> nodeList, Node startNode, Node goalNode) {
        super(nodeList, startNode, goalNode);
    }
    
    @Override
    public SearchResult doSearch() {
        predeccessorMap.put(startNode, null);
        foundNodeQueue.add(startNode);
            
        while(false == foundNodeQueue.isEmpty()){
            Node currentNode = foundNodeQueue.poll();

            if (currentNode == goalNode) {
                break;
            } else {
                for (Node child : (Set<Node>) currentNode.getChildrenMap().keySet()) {
                    //Check if it has already been found
                    if(colorMap.containsKey(child)){
                        // This node has ever been found.
                        continue;
                    }

                    // Put child node to the gray queue.
                    foundNodeQueue.add(child);
                    // Set currentNode as parent of child node
                    predeccessorMap.put(child, currentNode);
                    // Set color of child node to GRAY
                    colorMap.put(child, Color.GRAY);
                }
            }
        } 

        ArrayList<Node> shortestPath = new ArrayList<>();
        
        for(Node node = goalNode; null != node; node = predeccessorMap.get(node)){
            shortestPath.add(0, node);
        }
        
        // Return path which found first        
        return new SearchResult(shortestPath, "BreadthFirstSearch2");
    }
}<commit_msg>Mod: calculate total time until search<commit_after>package com.cafeform.algorithm;

import java.util.*;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * Another implementation of bredth first search.
 * Uses color and predecesser HashMap to check the status of each node
 *  color : Back=Found, Gray=Found, but not child search, White=Not found
 *  predeccessor : parent node
 * 
 * @author kaizawa
 */
class BreadthFirstSearch2 extends SearchAlgorithm {
    LinkedBlockingDeque<Node> foundNodeQueue = new LinkedBlockingDeque<>();
    HashSet<Node> foundNodeSet = new HashSet<>();
    HashMap<Node, Node> predeccessorMap = new HashMap(); 
    
    public BreadthFirstSearch2(List<Node> nodeList, Node startNode, Node goalNode) {
        super(nodeList, startNode, goalNode);
    }
    
    @Override
    public SearchResult doSearch() {
        predeccessorMap.put(startNode, null);
        foundNodeQueue.add(startNode);
            
        while(false == foundNodeQueue.isEmpty()){
            Node currentNode = foundNodeQueue.poll();

            if (currentNode == goalNode) {
                break;
            } else {
                for (Node child : (Set<Node>) currentNode.getChildrenMap().keySet()) {
                    time.incrementAndGet();
                    //Check if it has already been found
                    if(foundNodeSet.contains(child)){
                        // This node has ever been found.
                        continue;
                    }

                    // Put child node to the gray queue.
                    foundNodeQueue.add(child);
                    // Set currentNode as parent of child node
                    predeccessorMap.put(child, currentNode);
                    // Set color of child node to GRAY
                    foundNodeSet.add(child);
                }
            }
        } 

        // Return path which found first        
        return new SearchResult(getShortstPathFromGloal(), "BreadthFirstSearch2", time.get());
    }
    
    public List<Node> getShortstPathFromGloal(){
        ArrayList<Node> shortestPath = new ArrayList<>();
        
        for(Node node = goalNode; null != node; node = predeccessorMap.get(node)){
            shortestPath.add(0, node);
        }        
        return shortestPath;
    }    
}
{'fraction_non_alphanumeric': 0.09140607916028864, 'fraction_numerical': 0.0017493986442160508, 'mean_word_length': 1.926423544465771, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, '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': '2975140', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1165, 'n_words': 323}