本文整理汇总了C++中SparseVector::indices_size方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseVector::indices_size方法的具体用法?C++ SparseVector::indices_size怎么用?C++ SparseVector::indices_size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseVector
的用法示例。
在下文中一共展示了SparseVector::indices_size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SortedCopy
void SortedCopy(const SparseVector& in_vec, SparseVector* out_vec){
// START: Disable after debug!!
// Make sure there are no duplicate indices in input
{
std::set<uint64> prev_indices;
for (int i=0; i < in_vec.indices_size(); ++i){
uint64 cur_index = in_vec.indices(i);
CHECK(!scul::Contains(prev_indices, cur_index)) << "cur_index: " << cur_index;
prev_indices.insert(cur_index);
}
}
// END
CHECK(out_vec);
out_vec->Clear();
scul::Permutation p;
p.InitSortingPermutation(in_vec.indices());
CHECK_EQ(p.size(), in_vec.indices_size());
ResizeRepeatedField(out_vec->mutable_indices(), p.size());
ResizeRepeatedField(out_vec->mutable_values(), p.size());
p.Apply(in_vec.indices(), out_vec->mutable_indices());
p.Apply(in_vec.values(), out_vec->mutable_values());
// START: Disable after debug!!
// Make sure there are no duplicate indicies
{
uint64 prev_index = 0;
for (int i=0; i < out_vec->indices_size(); ++i){
uint64 cur_index = out_vec->indices(i);
if (i){
CHECK_GT(cur_index, prev_index) << "i: " << i << " size: " << out_vec->indices_size();
}
prev_index = cur_index;
}
}
// END
}