Algorithmic Solutions > LEDA > LEDA Guide > Geometry > Advanced Data Types for 2-Dimensional Geometry > Two-Dimensional Dictionaries


Two-Dimensional Dictionaries

The data type d2_dictionary can be used to store objects of an arbitrary type I together with two associated keys of a linearly ordered type K1 and a linearly ordered type K2, respectively. The elements of a d2_dictionary are of type dic2_item.

Two-dimensional dictionaries are closely related to the data type dictionary.

Additionally to the normal dictionary operations, the data type d2_dictionary supports rectangular range queries on K1xK2.

Example

The following program shows how to use d2_dictionary with keys of type int and information of type string.
#include <LEDA/geo/d2_dictionary.h>
#include <LEDA/core/string.h>

using namespace leda;

int main()
{
  d2_dictionary<int,int,string> D2; 
           
  D2.insert(85,41,"new york");
  D2.insert(119,34,"los angeles");
  D2.insert(71,47,"quebec");
  D2.insert(16,48,"vienna");
  
  std::cout << "Cities in d2_dictionary:\n";
  list<dic2_item> L=D2.all_items();
  dic2_item it;
  forall(it,L) {
    std::cout << "(" << D2.key1(it) << "," << D2.key2(it) 
              << ")\t\t" << D2.inf(it) << std::endl;
  }

  std::cout << "\nCities within (0,100,0,100):\n";
  list<dic2_item> L2=D2.range_search(0,100,0,100);
  forall(it,L2) {
    std::cout << "(" << D2.key1(it) << "," << D2.key2(it) 
              << ")\t\t" << D2.inf(it) << std::endl;
  }

  return 0;
}

See also:

Dictionaries

Two-Dimensional Maps

Associating Information with Geometric Objects

Strings


Geometry

Geometry Algorithms

GeoWin


Manual Entries:

Manual Page Two-Dimensional Dictionaries

User Defined Parameter Types

LEDA Item Concept

Linear Orders




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