next up previous contents index
Next: Sorted Sequences ( sortseq Up: Dictionaries Previous: Dictionaries ( dictionary )   Contents   Index


Dictionaries with Implementation Parameter ( _dictionary )

Definition

An instance of type _dictionary<K,I,impl> is a dictionary implemented by data type impl. impl must be one of the dictionary implementations listed in section Implementations Dictionaries or a user defined data structure fulfilling the specification given in section User Implementations Dictionaries. Note that depending on the actual implementation impl the key type K must either be linearly ordered or hashed.

#include < LEDA/ _dictionary.h >

Example

Using a dictionary implemented by skiplists to count the number of occurrences of the elements in a sequence of strings.


#include <LEDA/_dictionary.h>
#include <LEDA/impl/skiplist.h>

main()
{
  _dictionary<string,int,skiplist> D;
  string s;
  dic_item it;

  while (cin >> s)
  { it = D.lookup(s);
    if (it==nil) D.insert(s,1);
    else D.change_inf(it,D.inf(it)+1);
  }

  forall_items(it,D) 
    cout << D.key(it) << " : " <<  D.inf(it) << endl;

}



LEDA research project
2000-02-09