TutorialAlgorithms

Introduction
ext/Algorithms provides various generic algorithms for manipulating ranges of elements, that is, elements that are stored in memory contiguously, generally denoted by a pointer to the first element in the range, and a pointer to just past the end of the range. The algorithms are generic in the sense that they can work with ranges of elements of various kinds even UDT objects though, in general, the algorithms have certain minimum requirements of the elements they manipulate.

As a simple example, the following code uses ext.QuickSort to rearrange elements in an array:

and produces the following output:

(1)(2)(3)(4)(5)

As another example, the following code uses `ext.ReplaceIf` to replace numeric characters in a string with the character x:

and produces the following output:

abc xxx def

Obviously not the most efficient way of replacing numeric characters in a string, but strings provide an easy way to demonstrate what an algorithm is doing. The process is similar for working with UDT type elements, as the following code uses ext.Transform to modify a range of Person objects, and ext.ForEach to output them:

Don't worry about the fbext_Instanciate( ..., ((Person)) ) lines. Those are covered on the UsingExtTemplates page. For now it's enough to know that those lines make it possible for ext.Transform and ext.ForEach to work with ranges of Person elements. By default, all algorithms work with built-in numeric (such as Integer, Double, etc.) and String elements.