本文整理汇总了C++中SparseArray::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseArray::insert方法的具体用法?C++ SparseArray::insert怎么用?C++ SparseArray::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseArray
的用法示例。
在下文中一共展示了SparseArray::insert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
//test insert into sparse array of int, double, string
TEST(Sparse, Insert) {
SparseArray<int>* newInt= new SparseArray<int>(5,5,0);
newInt->insert(0,0,5);
EXPECT_EQ(5, newInt->access(0,0));
delete newInt;
SparseArray<double>* newDouble = new SparseArray<double>(5,6,0.0);
newDouble->insert(2,4,6.5);
EXPECT_EQ(6.5, newDouble->access(2,4));
delete newDouble;
SparseArray<std::string>* newString = new SparseArray<std::string>(7,8,"null");
newString->insert(4,3,"howdy");
EXPECT_EQ("howdy", newString->access(4,3));
delete newString;
}
示例2:
TEST(SparseArrayTest, InsertString) {
SparseArray<string>* tDString = new SparseArray<string>(3, 3, "default");
tDString->insert(1, 2, "Sparse");
EXPECT_EQ("Sparse", tDString->access(1, 2));
delete tDString;
}
示例3:
TEST(sparseTest, getNumCols) {
SparseArray<int>* i = new SparseArray<int>(5, 5, 0);
SparseArray<double>* d = new SparseArray<int>(5, 10, 0);
SparseArray<std::string>* s = new SparseArray<std::string>(5, 19, 0);
i->insert(2, 2, 7);
d->insert(4, 4, 3.145);
s->insert(0, 0, "Hello");
EXPECT_EQ(5, i->getNumCols());
EXPECT_EQ(10, d->getNumCols());
EXPECT_EQ(19, s->getNumCols());
delete i;
delete d;
delete s;
}
示例4: getColumn
SparseArray SparseMatrix::getColumn(unsigned i) const {
SparseArray column;
for (unsigned j=0; j<numRows(); ++j) {
int pos = _row[j].findIndex(i);
if (pos != -1) column.insert(j, _row[j].readValue(pos));
}
return column;
}