Ejemplo n.º 1
0
Fora::ReturnValue<VectorRecord, VectorLoadRequest>
			VectorRecord::deepcopiedAndContiguous(MemoryPool* inPool, VectorDataManager* inVDM) const
	{
	if (!dataPtr())
		return Fora::slot0(*this);

	lassert(!inPool->isBigVectorHandle());

	VectorHandle* handle = dataPtr();

	if (!allValuesAreLoaded())
		return Fora::slot1(VectorLoadRequest(*this));

	ForaValueArray* array = ForaValueArray::Empty(inPool);

	int64_t curIndex = 0;

	while (curIndex < size())
		{
		TypedFora::Abi::ForaValueArraySlice slice = sliceForOffset(curIndex);

		lassert(slice.mapping().indexIsValid(curIndex));

		lassert_dump(
			slice.array(),
			"We should have guaranteed that this value was loaded by calling 'allValuesAreLoaded'"
			);

		Nullable<int64_t> unmappedIndex =
			slice.firstValueNotLoadedInRange(
				curIndex,
				slice.mapping().highIndex()
				);

		lassert_dump(
			!unmappedIndex,
			"Index " << *unmappedIndex << " is unmapped in "
				<< prettyPrintString(slice) << " of size " << size()
			);

		if (slice.mapping().stride() == 1)
			{
			array->append(
				*slice.array(),
				slice.mapping().offsetForIndex(curIndex),
				slice.mapping().offsetForIndex(slice.mapping().highIndex())
				);
			}
		else
			{
			while (curIndex < slice.mapping().highIndex())
				{
				int64_t indexInTarget = slice.mapping().offsetForIndex(curIndex);
				array->append(*slice.array(), indexInTarget, indexInTarget+1);
				curIndex++;
				}
			}

		curIndex = slice.mapping().highIndex();
		}

	lassert(array->size() == size());

	return Fora::slot0(
		VectorRecord(
			inPool->construct<VectorHandle>(
				Fora::BigVectorId(),
				Fora::PageletTreePtr(),
				array,
				inPool,
				vectorHandleHash()
				)
			)
		);
	}