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

Dictionary Arrays

The data type d_array can be used to store objects of an arbitrary type I together with an associated key of a linearly ordered type K (int, string, …).

Example

The following program implements a very simple english-german dictionary using a d_array. It enters three words and then outputs the contents of the dictionary.
#include <LEDA/core/d_array.h>
#include <LEDA/core/string.h>

using namespace leda;

int main()
{
  d_array<string,string> D; 
    //objects of type string, keys of type string

  D["hello"]="hallo";D["world"]="Welt";D["book"]="Buch";
		
  string s;
  forall_defined(s,D) std::cout << s << " " << D[s] << std::endl;

  return 0;	
}

Strengths

  • fast data type

Disadvantages

  • restricted interface

Tips

  • To store objects with an associated key of a linearly ordered type, carefully choose between: Dictionary Arrays, Dictionaries, and Sorted Sequences. Dictionary Arrays are fastest, but have a very restricted interface. Sorted Sequences offer lots of functionality, but are slowest. Dictionaries are in between in both categories.
  • If your keys are of type pointer, item, or int use Maps.

See also:

Other data types with key of linearly ordered type:

Dictionaries

Sorted Sequences.

Data type with key of type pointer, item, or int: Maps

Data type with key of hashed type: Hashing Arrays

Strings


Manual Entries:

Manual Page Dictionary Arrays

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