template<class KEY, class VALUE> int Nde::index_has_subtree () { // return the element in this node's parent that has the "this" pointer as its subtree if (!mp_parent) return invalid_index; int first = 0; int last = mp_parent->m_count-1; while (last-first > 1) { int mid = first+(last-first)/2; //Elem& smallest = smallest_key(); if (smallest_key()>=mp_parent->m_vector[mid]) first = mid; else last = mid; } if (mp_parent->m_vector[first].mp_subtree == this) return first; else if (mp_parent->m_vector[last].mp_subtree == this) return last; else throw "error in index_has_subtree"; }
int index_has_subtree (PBTREE btree, int node_idx) { // return the element in this node's parent that has the "this" pointer as its subtree int first; int last; int parent_node_idx = btree->nodes[node_idx].parent_node_idx; if (!BTREE_IS_VALID_NODE_IDX(parent_node_idx)) return BTREE_INVALID_NODE_IDX; first = 0; last = btree->nodes[parent_node_idx].element_count-1; while (last-first > 1) { int mid = first+(last-first)/2; PBTREE_ELEMENT smallest = smallest_key(btree, node_idx); if (smallest->key >= btree->nodes[parent_node_idx].elements[mid].key) first = mid; else last = mid; } if (btree->nodes[parent_node_idx].elements[first].subtree_node_idx == node_idx) return first; else if (btree->nodes[parent_node_idx].elements[last].subtree_node_idx == node_idx) return last; else return BTREE_INVALID_NODE_IDX; }