/* * --- UpdatePointer ------ * * update an internal pointer (usually because a node merged) */ void indexNode::updatePointer(void *keyInModNode, bSize_t keylen, void *newSep, bSize_t sepLen) { TOUCH(); //decide which pointer to modify int targetPointer = locateKey(keyInModNode, keylen); if ( (tree->comparisonFunction(keyInModNode, keylen, nth_key(targetPointer), nth_keyLen(targetPointer))) ) targetPointer--; nodeID_t *pointerCopy = new nodeID_t; *pointerCopy = *(nodeID_t *)nth_value(targetPointer); printf("MERGE insert: old sep = <%s, %ld>\n", (char *)nth_key(targetPointer), *(nodeID_t *)nth_value(targetPointer)); if (targetPointer >= 0) { printf("insert: new sep = <%s, %ld>\n", (char *)newSep, *pointerCopy); record *newSepRec = new record(newSep, sepLen, pointerCopy, sizeof(nodeID_t)); remove(nth_key(targetPointer), nth_keyLen(targetPointer)); insert(newSepRec, kNoDuplicates, wrap(&update_cb_insert)); } //else { //do nothing //} return; }
void IntervalBtreeCursor::init() { _multikeyFlag = _namespaceDetails.isMultikey( _indexNo ); _curr = locateKey( _lowerBound, !_lowerBoundInclusive ); skipUnused( &_curr ); relocateEnd(); if ( ok() ) { _nscanned = 1; } }
/* * insert - This function blindly inserts the item which it assumes * consists of a key/pointer pair into the appropriate place * in the node. This will only be called by split() and split() * is required to juggle the pointers */ void indexNode::insert(record *item, int policy, callback<void, int>::ref cb) { void *key; bSize_t keyLen; void *value; bSize_t valLen; bSize_t totalLen; indexElemRep *elem; int i=0, keyLoc; repOK(); TOUCH(); //extract the data from the record value = item->getValue(&valLen); key = item->getKey(&keyLen); if (valLen != sizeof(nodeID_t)) { fatal("bad index record format"); } totalLen = keyLen + sizeof(indexElemRep); if (splitRequired(totalLen)) { split(item, cb); return; } repOK(); compact(); //fill in the record elem = (indexElemRep *)(bottomOfFreeSpace - totalLen); elem->p = *((nodeID_t *)value); //the only thing this can be is a nodeID_t * elem->keyLen = keyLen; memcpy(&(elem->key[0]), key, keyLen); //find the place to insert (items are in ascending order) keyLoc = locateKey(key, keyLen); //insert it for (i = header->numElems; i > keyLoc; i--) header->localPointers[i] = header->localPointers[i-1]; bottomOfFreeSpace -= totalLen; int tmp = (bottomOfFreeSpace - (char *)data->base()); header->localPointers[keyLoc] = tmp; //update the header header->dataSize += totalLen; header->numElems++; repOK(); //success (*cb)(0); return; }
void IntervalBtreeCursor::relocateEnd() { if ( eof() ) { return; } // If the current key is above the upper bound ... int32_t cmp = currKey().woCompare( _upperBound, _ordering, false ); if ( cmp > 0 || ( cmp == 0 && !_upperBoundInclusive ) ) { // ... then iteration is complete. _curr.bucket.Null(); return; } // Otherwise, relocate _end. _end = locateKey( _upperBound, _upperBoundInclusive ); skipUnused( &_end ); }