The
Dynamic dictionaries are useful in applications with requirements for:
Ad hoc queries or collection-based sorts without the overhead of maintaining multiple persistent dictionaries.
Intensive collation or collection-based sorting. The sorting provided by a dynamic dictionary is sometimes referred to as an insertion sort, in which each entry is inserted in the correct place in the structure as opposed to moving the entries around to obtain the required order.
As with any collection, the size of a dynamic dictionary is limited by the maximum entries for a collection (2^32) or the available disk space provided for the transient database.
Dynamic dictionaries do not offer a facility to sort objects not entirely based on a comparison of embedded attribute values; for example, the ability for you to provide your own sort compare routine is not supported.
In the following example, a dynamic dictionary performs an object sort based on member attributes. The publications property is a collection of Publications. This example shows the use of the reimplemented
vars dynaDict : DynaDictionary; pub : Publication; iter : Iterator; begin create dynaDict transient; // set the membership of our dynamic dictionary dynaDict.setMembership(Publication); // specify the ytdSales, royalty, and descending pubDate dictionary keys dynaDict.addMemberKey("ytdSales", false, false); dynaDict.addMemberKey("royalty", false, false); // specify descending key so that most recent titles appear first dynaDict.addMemberKey("pubdate", true, false); // complete key definition dynaDict.endKeys(false); // copy publication instances into the dynamic dictionary publications.copy(dynaDict); // display all publications with more than 1000 // sales (ytd) in sorted order iter := dynaDict.createIterator; // start the iteration where ytdSales >= 1000 // since the dynadict has 3 keys we must pass // keys to the startKeyGeq method dynaDict.startKeyGeq(1000, null, null, iter); while iter.next(pub) do write pub.name & " " & pub.ytdSales.String & pub.royalty.String & " " & pub.pubdate.String; endwhile; epilog // ensure we delete transients delete iter; delete dynaDict; end;
For details about the methods defined in the DynaDictionary class, see "