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

Maps

The data type map can be used to store objects of an arbitrary type I together with an associated key of type pointer, item, or int.

Remark: Maps are implemented by hashing with chaining. You can think of them as a variant of Dictionary Arrays optimized for keys of type pointer, item, or int.

Example

The following program generates a list of segments (type item) and associates a random bit (color) with each segment using a map. Then it outputs each segment and its color.
#include <LEDA/geo/segment.h>
#include <LEDA/core/map.h>
#include <LEDA/core/list.h>

using namespace leda;

int main()
{
  list<segment> seglist;
  
  int i;
  for (i=0;i<10;i++) {
    segment s(0,i,2*i,3*i);
    seglist.append(s);
  }
  
  map<segment,int> color;
  segment s;
  forall(s,seglist) color[s]=rand_int(0,1);
  
  forall(s,seglist) std::cout << s << " " << color[s] << std::endl;
  
  return 0;
}

Strengths

  • fast data type

Disadvantages

  • restricted functionality
  • only for keys of type pointer, item, or int

Tips

If you want to store objects with an associated key of type pointer, item, or int use map, otherwise consider using one of the related data types.

See also:

Data types with key of linearly ordered type:

Dictionary Arrays

Dictionaries

Sorted Sequences

Data types with key of hashed type: Hashing Arrays.

Two-Dimensional Maps

Node Maps

Edge Maps

Face Maps

Segments

Lists


Manual Entries:

Manual Page Maps

User Defined Parameter Types

LEDA Item Concept

Linear Orders

Hashed Types




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