Пример #1
0
bool OrdListClass<ItemType>::rFind( /* In */ KeyType key )	// The key to search for
{
	// If the current position in the tree is not NULL
	if( currPos != NULL )
	{
		// If the key being searched for is less than the key of the node at the current position in the
		//  tree
		if( key < currPos->data.key )
		{
			prevPos = currPos;
			currPos = currPos->left;

			// Recursively search for the key
			return rFind( key );

		} // End if
		// Else if the key being searched for is greater than the key of the node at the current
		//  position in the tree
		else if( key > currPos->data.key )
		{
			prevPos = currPos;
			currPos = currPos->right;

			// Recursively search for the target
			return rFind( key );

		} // End else if

		return true;

	} // End if

	return false;

} // End rFind( KeyType key )
Пример #2
0
static boolean bptFileFindMaybeMulti(struct bptFile *bpt, void *key, int keySize, int valSize,
    boolean multi, void *singleVal, struct slRef **multiVal)
/* Do either a single or multiple find depending in multi parameter.  Only one of singleVal
 * or multiVal should be non-NULL, depending on the same parameter. */
{
/* Check key size vs. file key size, and act appropriately.  If need be copy key to a local
 * buffer and zero-extend it. */
if (keySize > bpt->keySize)
    return FALSE;
char keyBuf[keySize];
if (keySize != bpt->keySize)
    {
    memcpy(keyBuf, key, keySize);
    memset(keyBuf+keySize, 0, bpt->keySize - keySize);
    key = keyBuf;
    }

/* Make sure the valSize matches what's in file. */
if (valSize != bpt->valSize)
    errAbort("Value size mismatch between bptFileFind (valSize=%d) and %s (valSize=%d)",
    	valSize, bpt->fileName, bpt->valSize);

if (multi)
    {
    rFindMulti(bpt, bpt->rootOffset, key, multiVal);
    return *multiVal != NULL;
    }
else
    return rFind(bpt, bpt->rootOffset, key, singleVal);
}
Пример #3
0
bool OrdListClass<ItemType>::Find( /* In */ KeyType target )	// The target being searched for
{
	currPos = root;
	prevPos = NULL;

	// Recursively search for the target
	return rFind( target );

} // End Find( KeyType target )
Пример #4
0
bool BstClass<ItemType>::rFind(/* in */KeyType key,				//key to be searched for 
							   /* in */node<ItemType>* & trav)	//location to test for key		
{
	//at end of tree
	if(trav == nullptr)
		return false;

	//given whether the key is greater than or less than current node
	//recurse left or right
	else if(trav -> data.key < key)
		return rFind(key, trav -> right);

	else if(trav -> data.key > key)
		return rFind(key, trav -> left);

	else //==
		return true;
	
}//end rFind
Пример #5
0
static boolean rFind(struct bptFile *bpt, bits64 blockStart, void *key, void *val)
/* Find value corresponding to key.  If found copy value to memory pointed to by val and return 
 * true. Otherwise return false. */
{
/* Seek to start of block. */
udcSeek(bpt->udc, blockStart);

/* Read block header. */
UBYTE isLeaf;
UBYTE reserved;
bits16 i, childCount;
udcMustReadOne(bpt->udc, isLeaf);
udcMustReadOne(bpt->udc, reserved);
boolean isSwapped = bpt->isSwapped;
childCount = udcReadBits16(bpt->udc, isSwapped);

UBYTE keyBuf[bpt->keySize];   /* Place to put a key, buffered on stack. */

if (isLeaf)
    {
    for (i=0; i<childCount; ++i)
        {
	udcMustRead(bpt->udc, keyBuf, bpt->keySize);
	udcMustRead(bpt->udc, val, bpt->valSize);
	if (memcmp(key, keyBuf, bpt->keySize) == 0)
	    return TRUE;
	}
    return FALSE;
    }
else
    {
    /* Read and discard first key. */
    udcMustRead(bpt->udc, keyBuf, bpt->keySize);

    /* Scan info for first file offset. */
    bits64 fileOffset = udcReadBits64(bpt->udc, isSwapped);

    /* Loop through remainder. */
    for (i=1; i<childCount; ++i)
	{
	udcMustRead(bpt->udc, keyBuf, bpt->keySize);
	if (memcmp(key, keyBuf, bpt->keySize) < 0)
	    break;
	fileOffset = udcReadBits64(bpt->udc, isSwapped);
	}
    return rFind(bpt, fileOffset, key, val);
    }
}
Пример #6
0
bool BstClass<ItemType>::Find(/* in */KeyType key)			//key to be searched for
{
	return rFind(key, root);
}//end Find