예제 #1
0
int addEHTFile(EHTFILE * file, char * key, unsigned position) {
	int entrySize = file->keyLength + sizeof(unsigned);
	int bucketSize = sizeof(file->bucket->buffer) / entrySize;

	if ( readEHTFile(file, key) != 0 )
	    return 1;

	if ( file->bucket->length < bucketSize ) {
		IndexOverlay * indexEntry = (IndexOverlay *)(file->bucket->buffer + file->bucket->length * entrySize);
		indexEntry->link = position;
		strncpy(indexEntry->key, key, file->keyLength);
		file->bucket->length++;
		writeDirect(file->bucket, file->bucketFile, file->bucketNumber);
	} else
		while ( ! splitBucket(file, key, position) )
		    doubleHashTable(file);
}
예제 #2
0
void HashMap::split(TransactionContext& txn) {
	if (hashMapImage_->split_ == hashMapImage_->front_) {
		hashMapImage_->split_ = 0;
		hashMapImage_->front_ = hashMapImage_->front_ << 1;
		hashMapImage_->toSplit_ = false;
	}

	uint64_t bucketAddr0 = hashMapImage_->split_;
	uint64_t bucketAddr1 = hashMapImage_->rear_;
	hashMapImage_->split_++;
	hashMapImage_->rear_++;

	if (hashMapImage_->rear_ > hashArray_.size()) {
		hashArray_.twiceHashArray(txn);

		if (hashMapImage_->rear_ > hashArray_.size()) {
			GS_THROW_SYSTEM_ERROR(GS_ERROR_DS_HM_MAX_ARRY_SIZE_OVER, "");
		}
	}

	Bucket splitBucket(
		txn, *getObjectManager(), maxArraySize_, maxCollisionArraySize_);
	hashArray_.get(txn, bucketAddr0, splitBucket);
	Bucket::Cursor cursor(txn, *getObjectManager());
	splitBucket.set(txn, cursor);
	if (cursor.size_ == 0) {
		;  
	}
	else {
		util::XArray<OId> remainOIdList(txn.getDefaultAllocator());
		Bucket newBucket1(
			txn, *getObjectManager(), maxArraySize_, maxCollisionArraySize_);
		hashArray_.get(txn, bucketAddr1, newBucket1);
		size_t bucket0Size = 0;
		size_t bucket1Size = 0;

		bool isCurrent = splitBucket.next(txn, cursor);
		while (isCurrent) {
			OId oId = splitBucket.getCurrentOId(cursor);
			uint32_t addr = hashBucketAddrFromObject<T>(txn, oId);
			if (addr == bucketAddr0) {
				bucket0Size++;
				remainOIdList.push_back(oId);
			}
			else {
				bucket1Size++;
				newBucket1.append(txn, oId);
			}
			isCurrent = splitBucket.next(txn, cursor);
		}
		cursor.array_.reset();

		if (bucket1Size > 0) {
			splitBucket.clear(txn);
			for (size_t i = 0; i < remainOIdList.size(); i++) {
				splitBucket.append(txn, remainOIdList[i]);
			}
		}
		else if (bucket0Size > 1) {
			remainOIdList.clear();
		}
	}

	return;
}