* Corrected small things to make Circ-git compile from within MonoDevelop
[circ.git] / Circ.Lib / Common / AutocompletationAlgorithm.cs
blob3512c8155ea6e8aae9fda15c89cb14dc4788294d
2 using System;
3 using System.Collections.Generic;
4 using System.Text;
6 namespace Circ.Lib
8 class StringsTree
10 Dictionary<char, TreeNode> root = new Dictionary<char, TreeNode>();
11 StringBuilder sb = new StringBuilder(25);
13 public StringsTree(string[] nicks)
15 BuildTree(nicks);
18 public string FindApproximately(string partialNick)
20 TreeNode temp;
21 if (!root.TryGetValue(partialNick[0], out temp))
22 return null;
24 // Clean the buffer
25 sb.Remove(0, sb.Length);
26 // Add first character
27 sb.Append(partialNick[0]);
29 for (int i = 1; i < partialNick.Length; i++) {
34 void
36 void BuildTree(string[] nicks)
41 private class TreeNode
43 TreeNode father;
44 Dictionary<char, List<TreeNode>> childNodes = new Dictionary<char, List<TreeNode>>();
45 char value;
47 public TreeNode(TreeNode father, char value)
49 this.father = father;
50 this.value = value;
53 public void AddChild(TreeNode child)
55 if (!childNodes.ContainsKey(child.Value)) {
56 List<TreeNode> temp = new List<TreeNode>();
57 temp.Add(child);
58 this.childNodes.Add(child.Value, temp);
59 } else {
60 this.childNodes[child.Value].Add(child);
64 public char Value {
65 get {
66 return value;
70 public TreeNode Father {
71 get {
72 return father;