Algorithmic Solutions > LEDA > LEDA Guide > Simple,Basic, and Advanced Data Types > Advanced Data Types > Partially Persistent Dictionaries Example

Partially Persistent Dictionaries Example

The following program shows how pp_dictionary can be used. The assignment copies the pp_dictionary in constant time. If one of the two dictionaries is changed afterwards, the other is frozen at the current state.

#include <LEDA/core/pp_dictionary.h>
#include <LEDA/core/string.h>

using namespace leda;

int main()
{
  pp_dictionary<string, int> PD;
    //objects of type int, keys of type string 
  
  pp_dictionary<string,int> PD_backup1, PD_backup2;
    //used to store intermediate "states" of PD
 
  PD.insert("alpha",1);
  PD.insert("beta",2);
  PD.insert("gamma",3);

  PD_backup1=PD;
     //store PD in PD_backup1

  PD.insert("delta",4); 
     //Now PD_backup1 cannot be changed anymore

  PD.del("beta");

  PD_backup2=PD;
     //store PD in PD_backup2
  
  PD_backup2.insert("psi",10);
     //No PD cannot be changed anymore

  PD_backup2.insert("epsilon",5);
  
  if (PD.lookup("beta")) std::cout << "beta is contained in PD\n";
  else std::cout << "beta is not contained in PD\n";

  if (PD_backup1.lookup("beta")) std::cout << "beta is contained in PD_backup1\n";
  else std::cout << "beta is not contained in PD_backup1\n";

  if (PD_backup2.lookup("beta")) std::cout << "beta is contained in PD_backup2\n";
  else std::cout << "beta is not contained in PD_backup2\n";

  return 0;
}         

See also:

Partially Persistent Dictionary

Persistent Dictionaries

Dictionaries.


Manual Entries:

Manual Page Persistent 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