当前位置: 首页>>代码示例>>C++>>正文


C++ ArrayType::size方法代码示例

本文整理汇总了C++中ArrayType::size方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayType::size方法的具体用法?C++ ArrayType::size怎么用?C++ ArrayType::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArrayType的用法示例。


在下文中一共展示了ArrayType::size方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: serialize_array_impl

    void serialize_array_impl(SF::Archive & ar, ArrayType & a)
    {
        if (ar.isRead())
        {
            unsigned int count = 0;
            ar & count;

            RCF_VERIFY(
                count == a.size(), 
                RCF::Exception(RCF::_RcfError_RcfError_ArraySizeMismatch(a.size(), count)));

            for (std::size_t i=0; i<a.size(); ++i)
            {
                ar & a[i];
            }
        }
        else if (ar.isWrite())
        {
            unsigned int count = a.size();
            ar & count;

            for (std::size_t i=0; i<a.size(); ++i)
            {
                ar & a[i];
            }
        }
    }
开发者ID:Fruneng,项目名称:POI_DB,代码行数:27,代码来源:SerializeArray.hpp

示例2: FindTheMissingNumberXor

auto FindTheMissingNumberXor(const ArrayType &integers) {
    assert(not integers.empty());

    const auto N = integers.size() + 1u;
    auto xor_of_all = integers[0];
    for (ArrayType::size_type i = 1ul; i < integers.size(); ++i) {
        xor_of_all ^= (i ^ integers[i]);
    }

    return xor_of_all ^ N ^ integers.size();
}
开发者ID:yyang-even,项目名称:algorithms,代码行数:11,代码来源:find_the_missing_number.cpp

示例3: RearrangeArrayInPlace

auto RearrangeArrayInPlace(ArrayType elements) {
    for (ArrayType::size_type i = 0; i < elements.size(); ++i) {
        elements[elements[i] % elements.size()] += i * elements.size();
    }

    std::transform(elements.cbegin(), elements.cend(),
    elements.begin(), [&elements](const ArrayType::value_type v) {
        return v / elements.size();
    });

    return elements;
}
开发者ID:yyang-even,项目名称:algorithms,代码行数:12,代码来源:rearrange_array_arrj_becomes_i_if_arri_j.cpp

示例4: CreateWavefunctionEpetraMap

Epetra_Map_Ptr CreateWavefunctionEpetraMap(typename Wavefunction<Rank>::Ptr psi)
{
	typedef blitz::Array<cplx, Rank> ArrayType;
	

	ArrayType data = psi->GetData();
	typename DistributedModel<Rank>::Ptr distr = psi->GetRepresentation()->GetDistributedModel();
	Epetra_Comm_Ptr comm = CreateDistributedModelEpetraComm<Rank>(distr);

	int localSize = data.size();
	int* myElems = new int[localSize*2];

	//Get strides of the global Rank-dimensional array
	blitz::TinyVector<int, Rank> globalShape = psi->GetRepresentation()->GetFullShape();
	blitz::TinyVector<int, Rank> globalStrides;
	globalStrides(Rank-1) = 1;
	for (int rank=Rank-2; rank>=0; rank--)
	{
		globalStrides(rank) = globalStrides(rank+1)	* globalShape(rank+1);
	}

	//Get maps to global indices for each rank
	blitz::TinyVector<blitz::Range, Rank> globalIndices;
	for (int rank=0; rank<Rank; rank++)
	{
		globalIndices(rank) = distr->GetLocalIndexRange(globalShape(rank), rank);
	}
	
	typename blitz::Array<cplx, Rank>::iterator it = data.begin();
	for (int linearCount=0; linearCount<data.size(); linearCount++)
	{
		//Get global position for the current element
		int globalPos = 0;
		for (int rank=0; rank<Rank; rank++)
		{
			int rankPos = it.position()(rank);
			globalPos += globalStrides(rank) * globalIndices(rank)(rankPos);
		}

		//real component
		myElems[2*linearCount] = 2*globalPos;
		//imaginary component
		myElems[2*linearCount+1] = 2*globalPos + 1;
			
		++it;	
	}

	return Epetra_Map_Ptr( new Epetra_Map(-1, localSize*2, myElems, 0, *comm) );
}
开发者ID:AtomAleks,项目名称:PyProp,代码行数:49,代码来源:pyprop_epetra.cpp

示例5: FindTheMissingNumberSum

/** Find the Missing Number
 *
 * @reference   https://www.geeksforgeeks.org/find-the-missing-number/
 *
 * You are given a list of n-1 integers and these integers are in the range of 1 to n.
 * There are no duplicates in list. One of the integers is missing in the list.
 * Write an efficient code to find the missing integer.
 *
 * @complexity  O(n)
 */
auto FindTheMissingNumberSum(const ArrayType &integers) {
    assert(not integers.empty());

    const auto N = integers.size() + 1u;
    const auto sum = N * (N + 1) / 2;
    return std::accumulate(integers.cbegin(), integers.cend(), sum, std::minus<ArrayType::value_type> {});
}
开发者ID:yyang-even,项目名称:algorithms,代码行数:17,代码来源:find_the_missing_number.cpp

示例6: RearrangeArraySimple

/** Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’ | Set 1
 *
 * @reference   https://www.geeksforgeeks.org/rearrange-array-arrj-becomes-arri-j/
 *
 * Given an array of size n where all elements are distinct and in range from 0 to n-1,
 * change contents of arr[] so that arr[i] = j is changed to arr[j] = i.
 */
auto RearrangeArraySimple(const ArrayType &elements) {
    auto output = elements;

    for (ArrayType::size_type i = 0; i < elements.size(); ++i) {
        const auto j = elements[i];
        output[j] = i;
    }

    return output;
}
开发者ID:yyang-even,项目名称:algorithms,代码行数:17,代码来源:rearrange_array_arrj_becomes_i_if_arri_j.cpp

示例7: doWork

void doWork(const std::string &input_file, const std::string &output_file) {
    ArrayType data = readFromFile<ArrayType>(input_file);

    std::cout << "Sorting " << data.size() << " elements..." << std::endl;
    std::clock_t start_time = std::clock();

    ArrayType sorted_data = doSort(data);

    std::clock_t end_time = std::clock();
    const double duration = (end_time - start_time)/double(CLOCKS_PER_SEC);
    std::cout << "Sorting took " << duration << " seconds" << std::endl;

    writeToFile(output_file, sorted_data);
}
开发者ID:georgy-schukin,项目名称:mpiaa,代码行数:14,代码来源:main.cpp

示例8: Vector_const

 inline Vector_const(const ArrayType &inArray,
     typename enable_if<
             boost::is_base_of< const_multi_array_ref<eT, 1>, ArrayType >
         >::type *dummy = NULL)
     : mMemoryHandle(inArray.memoryHandle()),
       mVector(
         const_cast<eT*>(inArray.data()),
         inArray.size(),
         false /* copy_aux_mem */,
         true /* strict */),
       n_rows(mVector.n_rows),
       n_cols(mVector.n_cols),
       n_elem(mVector.n_elem)
     { }
开发者ID:dcking,项目名称:madlib,代码行数:14,代码来源:Vector_const.hpp

示例9: FindAllDuplicatesBitArray

/** Find Duplicates of array using bit array
 *
 * @reference   https://www.geeksforgeeks.org/find-duplicates-of-array-using-bit-array/
 *
 * You have an array of N numbers, where N is at most 32,000. The array may have
 * duplicates entries and you do not know what N is. With only 4 Kilobytes of
 * memory available, how would print all duplicates elements in the array ?
 *
 * @complexity  O(n)
 */
auto FindAllDuplicatesBitArray(const ArrayType &elements) {
    std::vector<bool> counters(elements.size(), false);

    ArrayType output;
    for (const auto elem : elements) {
        if (counters[elem]) {
            output.push_back(elem);
        } else {
            counters[elem] = true;
        }
    }

    return output;
}
开发者ID:yyang-even,项目名称:algorithms,代码行数:24,代码来源:find_all_duplicates.cpp

示例10: CountInversionsMergeSort

auto CountInversionsMergeSort(ArrayType values) {
    return MergeSort(values.begin(), values.size());
}
开发者ID:yyang-even,项目名称:algorithms,代码行数:3,代码来源:count_inversions.cpp


注:本文中的ArrayType::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。