예제 #1
0
        private unsafe long GetRebalancedWeight(Line *data, HashEntry *hashTable, long n)
        {
            var node    = &data[GetHashEntry(hashTable, n)->Idx];
            var weight  = node->Weight;
            var balance = -1L;

            // leaf node case
            if (node->Children[0] == 0)
            {
                return(weight);
            }

            for (var ctr = 0; node->Children[ctr] != 0; ctr++)
            {
                var i = GetRebalancedWeight(data, hashTable, node->Children[ctr]);
                if (i < 0)
                {
                    return(i);
                }

                weight += i;
                if (ctr == 0)
                {
                    balance = i;
                }
                else if (balance != i)
                {
                    if (ctr == 1)
                    {
                        // need to figure out if 0 or 1 is the balance weight
                        var j = node->Children[ctr + 1];
                        // assume if only two children, then can't be unbalanced
                        if (j == 0)
                        {
                            continue;
                        }

                        j = GetRebalancedWeight(data, hashTable, j);
                        if (j == i)
                        {
                            ctr     = 0;
                            i       = balance;
                            balance = j;
                        }
                    }

                    var variance  = balance - i;
                    var newWeight = data[GetHashEntry(hashTable, node->Children[ctr])->Idx].Weight + variance;
                    return(-newWeight);
                }
            }

            return(weight);
        }
예제 #2
0
 public unsafe void Conjugate(Line *input, Line *output, int count)
 {
     Detail.swMM(true, true, &input->P1, P1, P2, &output->P1, count);
 }