Esempio n. 1
0
        public DistanceTree(Candidate[] candidates)
        {
            cands        = candidates;
            DTNode.cands = candidates;
            List <int> children = new List <int>();

            for (int i = 1; i < candidates.Length; i++)
            {
                children.Add(i);
            }
            root = new DTNode(0, children, 0);
        }
Esempio n. 2
0
 public DTNode(int n, List <int> children, int depth)
 {
     if (children.Count < 5)
     {
         this.leaf  = true;
         this.items = new List <int>();
         items.AddRange(children);
         items.Add(n);
     }
     else
     {
         this.node      = n;
         this.leaf      = false;
         this.threshold = findMedian(node, children);
         List <int> c = new List <int>();
         List <int> f = new List <int>();
         foreach (int i in children)
         {
             if (cands[node].SqrtDistanceTo(cands[i]) >= threshold)
             {
                 f.Add(i);
             }
             else
             {
                 c.Add(i);
             }
         }
         if (c.Count != 0)
         {
             int cn = c[c.Count - 1];
             c.RemoveAt(c.Count - 1);
             this.close = new DTNode(cn, c, depth + 1);
         }
         int fn = f[f.Count - 1];
         f.RemoveAt(f.Count - 1);
         this.far = new DTNode(fn, f, depth + 1);
     }
 }