예제 #1
0
CL_VoidPtr CL_GenericBTree::ItemWithRank (long rank) const
{
    short pos;
    bool found;
    CL_VoidPtr itm;

    CL_GenericBTreeNode* tmp_ptr, *p1;
    tmp_ptr = _nodeSpace->BorrowRoot ();
    if (!tmp_ptr || tmp_ptr->_keyCount <= 0)
        return NULL;
    rank = minl (maxl (rank, 0), tmp_ptr->_subtreeSize-1);
    do {
        if (tmp_ptr->_isLeaf) {
            assert ((0 <= rank && rank <= tmp_ptr->_keyCount-1),
                    ("Internal error: CL_GenericBTree::ItemWithRank:"
                     "bad key count %d rank %ld", tmp_ptr->_keyCount, rank));
            CL_VoidPtr ret = tmp_ptr->_item[rank];
            _nodeSpace->ReturnNode (tmp_ptr);
            return ret;
        }
        // We're in a non-leaf, so find the subtree to descend into
        // (if any)
        short i;
        for (i = 0; i < tmp_ptr->_keyCount; i++) {
            p1 = _nodeSpace->BorrowNode (tmp_ptr->_subtree[i]);
            if (p1->_subtreeSize > rank)
                break;
            rank -= p1->_subtreeSize; // Account for i-th subtree
            _nodeSpace->ReturnNode (p1);
            if (rank == 0) {
                // We've got the item we wanted
                CL_VoidPtr ret = tmp_ptr->_item[i];
                _nodeSpace->ReturnNode (tmp_ptr);
                return ret;
            }
            rank--;               // Account for i-th key in node
        }
        if (i >= tmp_ptr->_keyCount) {
            // Descend into rightmost subtree
            p1 = _nodeSpace->BorrowNode (tmp_ptr->_subtree[i]);
        }
        _nodeSpace->ReturnNode (tmp_ptr);
        tmp_ptr = p1;
    } while (1);
}
예제 #2
0
static int TDFXReadChipLongMMIO(TDFXPtr pTDFX, int chip, int addr) {
    return minl(pTDFX->MMIOBase[chip], addr);
}