-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DirectoryTree renamed to DirectoryNode. New code using SortedDictionary as tree node.
- Loading branch information
Showing
5 changed files
with
77 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace HPIZ | ||
{ | ||
public class DirectoryNode | ||
{ | ||
public SortedDictionary<string, DirectoryNode> Children { get; set; } | ||
public DirectoryNode() | ||
{ | ||
Children = new SortedDictionary<string, DirectoryNode>(StringComparer.OrdinalIgnoreCase); | ||
} | ||
|
||
public void AddEntry(string entry) | ||
{ | ||
var sections = entry.Split('\\'); | ||
AddEntryRecursively(sections, 0); | ||
} | ||
|
||
private void AddEntryRecursively(string[] entry, int level) | ||
{ | ||
if (entry.Length > level) | ||
{ | ||
if (Children.ContainsKey(entry[level])) | ||
Children[entry[level]].AddEntryRecursively(entry, level + 1); | ||
else | ||
OnlyAddRecursively(entry, level); | ||
} | ||
} | ||
private void OnlyAddRecursively(string[] entry, int level) | ||
{ | ||
if (entry.Length > level) | ||
{ | ||
Children.Add(entry[level], new DirectoryNode()); | ||
Children[entry[level]].OnlyAddRecursively(entry, level + 1); | ||
} | ||
} | ||
|
||
public int CalculateSize() | ||
{ | ||
int totalSize = 8; | ||
foreach (var item in Children) | ||
{ | ||
totalSize += 9; | ||
totalSize += item.Key.Length + 1; | ||
if (item.Value.Children.Count != 0) | ||
totalSize += item.Value.CalculateSize(); | ||
else | ||
totalSize += 9; | ||
} | ||
return totalSize; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters