Algorithmic Solutions > LEDA > LEDA Guide > Simple,Basic, and Advanced Data Types > Advanced Data Types > Two Dimensional Maps

Two Dimensional Maps

The 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.

Example

The following program shows how Two Dimensional Maps can be used. It defines a map2 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;
}

Tip

Use Two Dimensional Maps whenever it is appropriate.

See also:

Maps

Two-Dimensional Dictionaries

Two-Dimensional Node Maps


Manual Entries:

Manual Page Two Dimensional Maps

User Defined Parameter Types

Linear Orders

Hashed Types




Please send any suggestions, comments or questions to leda@algorithmic-solutions.com
© Copyright 2001-2003, Algorithmic Solutions Software GmbH