Ejemplo n.º 1
0
Record* Hash::findRecord(Key* key){
	int bucketNumber = this->hashTable->getBlock(this->hashKey(key));
	Bucket* bucket = this->readBucket(bucketNumber);

	Record* record = bucket->find(key);
	if(record)
		record = record->clone();

	delete bucket;
	return record;
}
Ejemplo n.º 2
0
void Hash::reHashRecords(Bucket* bucket, int bucketNumber, Bucket* newBucket)
{
	List<Record*>* recordList = bucket->getRecordList();
	ListIterator<Record*> it = recordList->getIterator();
	Record* auxRecord = NULL;
	int bucketDestinationNumber = 0;
	while(it.hasNext()){
		auxRecord = it.next();
		bucketDestinationNumber = this->hashTable->getBlock(this->hashKey(auxRecord->getKey()));
		if(bucketDestinationNumber != bucketNumber){
			newBucket->insertRecord(auxRecord->clone());
			bucket->deleteRecord(auxRecord->getKey());
		}
	}
}