public async Task query(T term, int thershold, Dictionary <T, int> collected, CancellationToken ct) { int distanceAtNode = Distance.calculate(term, this.term); if (distanceAtNode == thershold) { if (!collected.ContainsKey(this.term)) { collected.Add(this.term, distanceAtNode); } return; } if (distanceAtNode < thershold) { if (!collected.ContainsKey(this.term)) { collected.Add(this.term, distanceAtNode); } } for (int score = distanceAtNode - thershold; score <= thershold + distanceAtNode; score++) { BKNode child = children.GetValueOrDefault(score); if (child != null) { ct.ThrowIfCancellationRequested(); await child.query(term, thershold, collected, ct); } } }
public SearchTask(BKNode <T> root, T searchTerm, int searchThreshold) { bkRoot = root; this.searchTerm = searchTerm; this.searchThreshold = searchThreshold; cts = new CancellationTokenSource(); result = new Dictionary <T, int>(); }
public void AddWord(string word) { if (root == null) { root = new BKNode(word); } else { root.AddNode(word); } }
// Adds term to the tree public void add(T term) { if (root != null) { root.add(term); } else { root = new BKNode <T>(term); } }
public void add(T term) { int score = Distance.calculate(term, this.term); BKNode child = null; children.TryGetValue(score, out child); if (child != null) { child.add(term); } else { children.Add(score, new BKNode(term)); } }
// Clears the tree public void clear() { root.children.Clear(); root = null; }
public SearchObject(BKNode <T> root) { bkRoot = root; cts = new CancellationTokenSource(); }