| 99 | // } |
| 100 | |
| 101 | int cWeightedIndex::FindPosition(double position, int root_id) |
| 102 | { |
| 103 | //if (position >= subtree_weight[root_id]) { |
| 104 | // cout << "BDB: position " << position << "subtree_weight[" << root_id << "] = " << subtree_weight[root_id] << endl; |
| 105 | //} |
| 106 | assert(position < subtree_weight[root_id]); |
| 107 | |
| 108 | // First, see if we should just return this node. |
| 109 | if (position < item_weight[root_id]) { |
| 110 | return root_id; |
| 111 | } |
| 112 | |
| 113 | // If not, then see if we should search in the left subtree... |
| 114 | position -= item_weight[root_id]; |
| 115 | const int left_id = GetLeftChild(root_id); |
| 116 | assert (left_id < size); |
| 117 | if (position < subtree_weight[left_id]) { |
| 118 | return FindPosition(position, left_id); |
| 119 | } |
| 120 | |
| 121 | // Otherwise we must look in the right subtree... |
| 122 | position -= subtree_weight[left_id]; |
| 123 | const int right_id = GetRightChild(root_id); |
| 124 | assert (right_id < size); |
| 125 | assert (position < subtree_weight[right_id]); |
| 126 | return FindPosition(position, right_id); |
| 127 | } |
| 128 |
no outgoing calls
no test coverage detected