SortedDictionarySample()
{
// Create a new disk dictionary.
TSortedDiskDictionary* myDictionary = new TSortedDiskDictionary("mynewdict");
// NOTE:
// TOrderableCollectibleLong is an imaginary class that inherits
// from MOrderableCollectible.
TOrderableCollectibleLong key1(11);
TCollectibleLong value1(1001);
TOrderableCollectibleLong key2(5);
TCollectibleLong value2(999);
TOrderableCollectibleLong key3(75);
TCollectibleLong value3(102456);
// Add some entries to the disk dictionary
mySortedDictionary->Add(key1, value1);
mySortedDictionary->Add(key2, value2);
mySortedDictionary->Add(key3, value3);
// Delete the instance in memory
delete mySortedDictionary;
// ...Some time later....
mySortedDictionary = new TSortedDiskDictionary("mynewdict");
// Checking to see if various keys are in the dictionary.
Boolean found = mySortedDictionary->Member(TOrderableCollectibleLong(11));
qprintf("11 was found as a key in the sorted dictionary = %d\n", found);
found = mySortedDictionary->Member(TOrderableCollectibleLong(1001));
qprintf("1001 was found as a key in the sorted dictionary = %d\n", found);
found = mySortedDictionary->Member(TOrderableCollectibleLong(5));
qprintf("5 was found as a key in the sorted dictionary = %d\n", found);
found = mySortedDictionary->Member(TCollectibleLong(69));
qprintf("69 was found as a key in the sorted dictionary = %d\n", found);
// Retrieving a value given a key
TOrderableCollectibleLong* someLong = (TOrderableCollectibleLong*)
mySortedDictionary->Retrieve(TOrderableCollectibleLong(11));
qprintf("Value associated with 11 is: %d\n", someLong->GetValue());
delete someLong;
someLong = (TOrderableCollectibleLong*)
mySortedDictionary->Retrieve(TOrderableCollectibleLong(75));
qprintf("Value associated with 75 is: %d\n", someLong->GetValue());
mySortedDictionary->SetDestroyFileOnDelete(TRUE);
delete someLong;
delete mySortedDictionary;
}