Printing All Names Beginning with "K"

Faster Way

The names are indexed by a sortOn slot, so if we provide a beginKey the cursor can go directly to the first name beginning with a "K"'. In addition, rather than using a validTest which requires obtaining the full soup entry, we use an indexValidTest which can operate on keys from the index. All the names from "K" on are still visited, however, and the indexValidTest is applied to each. This example took approximately 3 seconds to execute:

soup := GetUnionSoup("Names");
curs := soup:Query(
   {
      indexPath: 'sortOn, 
      beginKey: "k",
      indexValidTest: 
         func(indexValue) 
         begin
            return BeginsWith(indexValue, "k");
         end
   });
e := curs:Entry();
while e do begin
   Print(e.sortOn);
   e := curs:Next();
end;
"Keohane"
"Kohnlenberger"
"Kollmyer"
"Kuang"

An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996