Skip to content

Commit

Permalink
Count root nodes in frequency command
Browse files Browse the repository at this point in the history
  • Loading branch information
swiftyfinch committed Apr 7, 2024
1 parent f2c8f8a commit 75ffdc4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Sources/XTree/Core/Common/Services/FrequencyManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ final class FrequencyManager {

func print(inputPath: String) async throws {
let nodesMap = try await inputReader.read(inputPath: inputPath)
let frequencies: [String: Int] = nodesMap.values.reduce(into: [:]) { parents, node in
var frequencies: [String: Int] = nodesMap.values.reduce(into: [:]) { parents, node in
node.children.forEach { name in
parents[name, default: 0] += 1
}
}
nodesMap.keys.forEach { name in
frequencies[name, default: 0] += 1
}
guard let maxFrequency = frequencies.map(\.value).max() else { return }
let width = Int(log10f(Float(maxFrequency)).rounded(.up))
let list = frequencies
Expand Down

0 comments on commit 75ffdc4

Please sign in to comment.