示例#1
0
/**
 * Returns a pointer to the Bucket that may contain the given BucketItem.
 */
BucketListItem* BucketList::findBucket(BucketItem* bucketItemToBeSearched) {
	assert(this->getHead() != NULL);
	BucketListItem *cur = (BucketListItem*) this->getHead();
	Bucket *checkBucket = cur->getElement();

	/**
	 * Checks which is the Bucket that may contain the requested Bucket.
	 */
	while (checkBucket->getLastItemID() < bucketItemToBeSearched->getNode()->getId()) {
		if (cur->getNext() == NULL)
			break;
		cur = (BucketListItem*) cur->getNext();
		checkBucket = cur->getElement();

		if (cur->getElement()->isEmpty()) // just insert it there (it's the newly added bucket)
			break;
	}
	return cur;
}
示例#2
0
/**
 * Finds the Bucket containing a BucketItem with the given id, if any.
 * Returns a pointer to the BucketItem or NULL.
 */
BucketItem* BucketList::lookup(int id) {
	if (this->isEmpty())
		return NULL;

	BucketListItem *cur = (BucketListItem*) this->getHead();
	Bucket *checkBucket = cur->getElement();
	Bucket *lookupBucket;

	// Find the only bucket that is possible to find the given id.
	while (checkBucket->getLastItemID() < id) {
		cur = (BucketListItem*) cur->getNext();
		if (cur == NULL)
			return NULL;
		assert(cur != NULL);
		checkBucket = cur->getElement();

		if (cur->getElement()->isEmpty())
			return NULL;
	}

	lookupBucket = cur->getElement();
	return lookupBucket->lookupBucketItem(id);
}