tests/utilities/test-set-iterators.cpp
author Aravindakshan Babu <akshan@stanford.edu>
Thu, 08 Jul 2010 23:50:39 -0700
branchdev
changeset 217 64a272a34cb2
parent 106 dfa74f2f2a76
permissions -rw-r--r--
Added extra functionality to Point class( an iterator ) and PersistenceDiagram( dimension property and __len__ func ). persistence-diagram.h: Added a new read-only dimension member and member function to access it. With a new constructor that that takes in an int type to initialize dimension. persistence-diagram.cpp: Added new bp::init constructor. Takes in an integer type to initialize the dimension. Exposed the dimension property. Exposed the size property via a __len__ method. __init__.py: Added an iterator for Point objects. This iterates over the coords and then the data( if present ).

#include <vector>
#include <list>
#include <algorithm>
#include <iostream>

#include <utilities/indirect.h>

#include <boost/lambda/lambda.hpp>
using    boost::lambda::_1;

int main()
{
    std::vector<int>    v;
    v.push_back(1);
    v.push_back(3);
    v.push_back(5);
    v.push_back(7);
    v.push_back(9);
    std::cout << "v: ";
    std::for_each(v.begin(), v.end(), std::cout << _1 << ' ');
    std::cout << std::endl;

    std::list<int>      l;
    l.push_back(2);
    l.push_back(3);
    l.push_back(4);
    l.push_back(5);
    l.push_back(6);
    l.push_back(8);
    std::cout << "l: ";
    std::for_each(l.begin(), l.end(), std::cout << _1 << ' ');
    std::cout << std::endl;
    std::cout << std::endl;

    std::cout << "v \\cap l: ";
    std::for_each(make_intersection_iterator(v.begin(), v.end(), l.begin(), l.end(), std::less<int>()),
                  make_intersection_iterator(v.end(),   v.end(), l.end(),   l.end(), std::less<int>()),
                  std::cout << _1 << ' ');
    std::cout << std::endl;
    
    std::cout << "v - l: ";
    std::for_each(make_difference_iterator(v.begin(),   v.end(), l.begin(), l.end(), std::less<int>()),
                  make_difference_iterator(v.end(),     v.end(), l.end(),   l.end(), std::less<int>()),
                  std::cout << _1 << ' ');
    std::cout << std::endl;
    std::cout << std::endl;
    
    std::cout << "l \\cap v: ";
    std::for_each(make_intersection_iterator(l.begin(), l.end(), v.begin(), v.end(), std::less<int>()),
                  make_intersection_iterator(l.end(),   l.end(), v.end(),   v.end(), std::less<int>()),
                  std::cout << _1 << ' ');
    std::cout << std::endl;
    
    std::cout << "l - v: ";
    std::for_each(make_difference_iterator(l.begin(),   l.end(), v.begin(), v.end(), std::less<int>()),
                  make_difference_iterator(l.end(),     l.end(), v.end(),   v.end(), std::less<int>()),
                  std::cout << _1 << ' ');
    std::cout << std::endl;
}