Пример #1
0
void test18() {
    CS225::SparseVector v;
    for (int i=0;i<10;++i) v.Insert(i+1,i);
    const CS225::SparseVector cv(v);
    int i = cv[3] + cv[4];
    std::cout << "cv[3] + cv[4] = " << i << std::endl;
}
Пример #2
0
int main(int argc, char **argv) {
  CS225::SparseVector v;
  for (int i=0;i<10;++i) v.Insert(i+1,i);
  const CS225::SparseVector cv(v);
  cv[3]=5;
  return 0;
}
Пример #3
0
int main(int argc, char **argv) {
  CS225::SparseVector v;
  for (int i=0;i<10;++i) v.Insert(i+1,i);
  const CS225::SparseVector cv(v);
  CS225::SparseVector v2(cv); // copy from const - OK
  v2 = v + cv;
  v2 = cv + v;
  return 0;
}
Пример #4
0
void test17() {
    CS225::SparseVector v;
    for (int i=0;i<6;++i)  v[i]=i+1;

    const CS225::SparseVector v_copy(v);
    std::cout << "v_copy = " << v_copy << std::endl;

    std::cout << "v_copy[4] = " << v_copy[4] << std::endl;

    const CS225::SparseVector v_1(0*v_copy);
    std::cout << "const CS225::SparseVector v_1(0*v_copy);\n";
    v_1.PrintRaw();
}
Пример #5
0
void test13() {
    CS225::SparseVector v;
    for (int i=0;i<10;++i) v[i]=i;

    std::cout << "v = " << v << std::endl;
    v.PrintRaw(); std::cout << std::endl;

    v[1] = v[5] = v[2];
    std::cout << "v = " << v << std::endl;
    v.PrintRaw(); std::cout << std::endl;

    v[1] += v[5] += v[2];
    std::cout << "v = " << v << std::endl;
    v.PrintRaw(); std::cout << std::endl;
}
Пример #6
0
void test12() {
    CS225::SparseVector v;
    for (int i=0;i<10;++i) v.Insert(i+1,i);

    std::cout << "v = " << v << std::endl;
    v.PrintRaw(); std::cout << std::endl;

    v[1] += v[5];
    std::cout << "v = " << v << std::endl;
    v.PrintRaw(); std::cout << std::endl;

    v[2] -= v[2];
    std::cout << "v = " << v << std::endl;
    v.PrintRaw(); std::cout << std::endl;
}
Пример #7
0
void test14() { // test for existance of nodes with 0 in them
    CS225::SparseVector v;
    for (int i=0;i<16;++i) v[i] = i%2;

    v.PrintRaw();

    CS225::SparseVector v1,v2;
    for (int i=0;i<20;++i) { v1[i] = i%2; v2[i] = -v1[i]; }
    CS225::SparseVector v_sum=v1+v2;
    v_sum.PrintRaw();

    CS225::SparseVector v3;
    for (int i=0;i<20;++i)  v3[i]=i+1;
    for (int i=0;i<20;i+=2) v3[i] -= v3[i];
    v3.PrintRaw();
    std::cout << "v3 = " << v3 << std::endl;
}
Пример #8
0
void test10 () {
    CS225::SparseVector v;
    v[1]=1;
    v[2]=2;
    v[13]=13;
    CS225::SparseVector & vr=v;
    vr[1]=0;
    vr[2]=0;
    vr[6]=6;
    vr[7]=7;
    vr[15]=15;
    v=vr;
    std::cout << "Should be equal\n";
    std::cout << "v  = ";
    v.PrintRaw();
    std::cout << std::endl;
    std::cout << "vr = ";
    vr.PrintRaw();
    std::cout << std::endl;
}
Пример #9
0
void test11() {
    CS225::SparseVector v;
    for (int i=0;i<10;++i) v.Insert(i+1,i);
    std::cout << "v = " << v << std::endl;

    std::cout << "Second element is v[2]=" << v[2] << std::endl;

    v[2]=5;
    std::cout << "v = " << v << std::endl;
    v.PrintRaw(); std::cout << std::endl;

    int temp=v[5];
    std::cout << "v[5]=" << temp << std::endl;
    v.PrintRaw(); std::cout << std::endl;

    v[6] += -5; v[5] -= 3;
    std::cout << "v = " << v << std::endl;
    v.PrintRaw(); std::cout << std::endl;

    v[2] = v[8];
    std::cout << "v = " << v << std::endl;
    v.PrintRaw(); std::cout << std::endl;
}