Two Dimensional MapsThe data type map2 is a two dimensional variant of Maps. It can be used to store objects of an arbitrary type I together with a pair of associated keys of type pointer, item, or int.ExampleThe following program shows how Two Dimensional Maps can be used. It defines amap2 and four points . Then it enters several values into the map2 and
illustrates the functions provided by the data type.
#include <LEDA/core/map2.h> #include <LEDA/geo/point.h> #include <LEDA/core/string.h> using namespace leda; int main() { map2<point,point,string> M2; point p1=point(0,0); point p2=point(1,2); point p3=point(3,4); point p4=point(5,6); //enter something into M2 M2(p1,p2)="alpha"; M2(p3,p4)="beta"; M2(p1,p4)="gamma"; M2(p2,p1)="delta"; //get information from M2 std::cout << "M2(p1,p4)=" << M2(p1,p4) << std::endl; std::cout << "M2(p3,p4)=" << M2(p3,p4) << std::endl; //Check if M2 defined for a pair of points if (M2.defined(p1,p2)) std::cout << "M2.defined(p1,p2) is true.\n"; else std::cout << "M2.defined(p1,p2) is false.\n"; if (M2.defined(p2,p4)) std::cout << "M2.defined(p2,p4) is true.\n"; else std::cout << "M2.defined(p2,p4) is false.\n"; M2.clear(); //Clear M2 return 0; } TipUse Two Dimensional Maps whenever it is appropriate. |
See also:Manual Entries: |