<commit_before>package org.psjava.example.algo;

import org.junit.Assert;
import org.junit.Test;
import org.psjava.algo.graph.bfs.BFS;
import org.psjava.algo.graph.bfs.BFSVisitor;
import org.psjava.ds.Collection;
import org.psjava.ds.graph.MutableDirectedOldGraph;
import org.psjava.ds.graph.NewGraphFromGraph;
import org.psjava.ds.graph.DirectedEdge;
import org.psjava.util.SingleElementCollection;
import org.psjava.util.VisitorStopper;

/**
 * @implementation {@link BFS}
 * @see {@link DepthFirstSearchExample}
 */
public class BreadthFirstSearchExample {

	@Test
	public void example() {
		// Let's prepare a simple graph.

		MutableDirectedOldGraph<String> g = MutableDirectedOldGraph.create();
		g.insertVertex("A");
		g.insertVertex("B");
		g.insertVertex("C");
		g.insertVertex("D");

		g.addEdge("A", "B");
		g.addEdge("B", "C");
		g.addEdge("C", "D");
		g.addEdge("B", "D");

		// Then find a path from "A" to "D" by BFS.

		Collection<String> starts = SingleElementCollection.create("A");
		BFS.traverse(NewGraphFromGraph.createFromDirected(g), starts, new BFSVisitor<String, DirectedEdge<String>>() {
			@Override
			public void onDiscover(String vertex, int depth, VisitorStopper stopper) {
				if (vertex.equals("D")) {
					// There is a path: A->B->D, so depth is 2.
					int pathLength = depth;
					Assert.assertEquals(2, pathLength);
					// when you call the stopper, BFS stops. So no other vertex will be discovered.
					stopper.stop();
				}
			}

			@Override
			public void onWalk(DirectedEdge<String> e) {
				// You can also track the sequence of discovering edges.
			}
		});

	}

}
<commit_msg>to use new graph in BreadthFirstSearchExample<commit_after>package org.psjava.example.algo;

import org.junit.Assert;
import org.junit.Test;
import org.psjava.algo.graph.bfs.BFS;
import org.psjava.algo.graph.bfs.BFSVisitor;
import org.psjava.ds.Collection;
import org.psjava.ds.graph.MutableDirectedUnweightedGraph;
import org.psjava.ds.graph.DirectedEdge;
import org.psjava.util.SingleElementCollection;
import org.psjava.util.VisitorStopper;

/**
 * @implementation {@link BFS}
 * @see {@link DepthFirstSearchExample}
 */
public class BreadthFirstSearchExample {

	@Test
	public void example() {
		// Let's prepare a simple graph.

		MutableDirectedUnweightedGraph<String> g = MutableDirectedUnweightedGraph.create();
		g.insertVertex("A");
		g.insertVertex("B");
		g.insertVertex("C");
		g.insertVertex("D");

		g.addEdge("A", "B");
		g.addEdge("B", "C");
		g.addEdge("C", "D");
		g.addEdge("B", "D");

		// Then find a path from "A" to "D" by BFS.

		Collection<String> starts = SingleElementCollection.create("A");
		BFS.traverse(g, starts, new BFSVisitor<String, DirectedEdge<String>>() {
			@Override
			public void onDiscover(String vertex, int depth, VisitorStopper stopper) {
				if (vertex.equals("D")) {
					// There is a path: A->B->D, so depth is 2.
					int pathLength = depth;
					Assert.assertEquals(2, pathLength);
					// when you call the stopper, BFS stops. So no other vertex will be discovered.
					stopper.stop();
				}
			}

			@Override
			public void onWalk(DirectedEdge<String> e) {
				// You can also track the sequence of discovering edges.
			}
		});

	}

}

{'fraction_non_alphanumeric': 0.13565426170468187, 'fraction_numerical': 0.0012004801920768306, 'mean_word_length': 3.3855263157894737, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '7661001', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1102, 'n_words': 257}