示例#1
0
            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);
                    }
                }
            }
示例#2
0
 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>();
 }
示例#3
0
 public void AddWord(string word)
 {
     if (root == null)
     {
         root = new BKNode(word);
     }
     else
     {
         root.AddNode(word);
     }
 }
示例#4
0
 // Adds term to the tree
 public void add(T term)
 {
     if (root != null)
     {
         root.add(term);
     }
     else
     {
         root = new BKNode <T>(term);
     }
 }
示例#5
0
            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));
                }
            }
示例#6
0
 // Clears the tree
 public void clear()
 {
     root.children.Clear();
     root = null;
 }
示例#7
0
 public SearchObject(BKNode <T> root)
 {
     bkRoot = root;
     cts    = new CancellationTokenSource();
 }