<commit_before>//
//  Graph.swift
//  HeapKit Tests
//
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Foundation

struct Connection: Equatable, Hashable {
	let nodeA: Int
	let nodeB: Int
	
	var hashValue: Int {
		return 65536 * nodeA + nodeB
	}
}

func ==(lhs: Connection, rhs: Connection) -> Bool {
	return lhs.nodeA == rhs.nodeA && lhs.nodeB == rhs.nodeB
}

class Graph {
	private let nodes: Dictionary<Int, [Int]>
	private let weights: Dictionary<Connection, Int>
	
	init(nodes: Dictionary<Int, [Int]>, weights: Dictionary<Connection, Int>) {
		self.nodes = nodes
		self.weights = weights
	}
	
	func findShortestPaths(fromIndex sourceIndex: Int) -> Dictionary<Int, Int> {
		var visited = Dictionary<Int, Bool>()
		
		var distances = Dictionary<Int, Int>()
		distances[sourceIndex] = 0
		
		let heap = MinHeap<Int, Int>()
		heap.insert(sourceIndex, weight: 0)
		
		while !heap.isEmpty {
			let index = heap.removeMinimum()!
			visited[index] = true
			
			if let neighbors = nodes[index] {
				for neighborIndex in neighbors {
					if visited[neighborIndex] == nil {
						let weight = weights[Connection(nodeA: index, nodeB: neighborIndex)]!
						let newDistance = distances[index]! + weight
						
						if let currentDistance = distances[neighborIndex] {
							if newDistance < currentDistance {
								distances[neighborIndex] = newDistance
								heap.update(neighborIndex, weight: newDistance)
							}
						}
						else {
							distances[neighborIndex] = newDistance
							heap.insert(neighborIndex, weight: newDistance)
						}
					}
				}
			}
		}
		
		return distances
	}
}<commit_msg>Use new API<commit_after>//
//  Graph.swift
//  HeapKit Tests
//
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import Foundation

struct Connection: Equatable, Hashable {
	let nodeA: Int
	let nodeB: Int
	
	var hashValue: Int {
		return 65536 * nodeA + nodeB
	}
}

func ==(lhs: Connection, rhs: Connection) -> Bool {
	return lhs.nodeA == rhs.nodeA && lhs.nodeB == rhs.nodeB
}

class Graph {
	private let nodes: Dictionary<Int, [Int]>
	private let weights: Dictionary<Connection, Int>
	
	init(nodes: Dictionary<Int, [Int]>, weights: Dictionary<Connection, Int>) {
		self.nodes = nodes
		self.weights = weights
	}
	
	func findShortestPaths(fromIndex sourceIndex: Int) -> Dictionary<Int, Int> {
		var visited = Dictionary<Int, Bool>()
		
		var distances = Dictionary<Int, Int>()
		distances[sourceIndex] = 0
		
		let heap = MinHeap<Int, Int>()
		heap.insert(sourceIndex, weight: 0)
		
		while !heap.isEmpty {
			let index = heap.removeTop()!
			visited[index] = true
			
			if let neighbors = nodes[index] {
				for neighborIndex in neighbors {
					if visited[neighborIndex] == nil {
						let weight = weights[Connection(nodeA: index, nodeB: neighborIndex)]!
						let newDistance = distances[index]! + weight
						
						if let currentDistance = distances[neighborIndex] {
							if newDistance < currentDistance {
								distances[neighborIndex] = newDistance
								heap.update(neighborIndex, weight: newDistance)
							}
						}
						else {
							distances[neighborIndex] = newDistance
							heap.insert(neighborIndex, weight: newDistance)
						}
					}
				}
			}
		}
		
		return distances
	}
}
{'fraction_non_alphanumeric': 0.11495673671199011, 'fraction_numerical': 0.006798516687268232, 'mean_word_length': 3.081967213114754, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, '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': '2064857', 'n_tokens_mistral': 1274, 'n_tokens_neox': 989, 'n_words': 270}