D.3 Using Clusters for Mapping and High-speed Translations
Clusters arrays can be used to create high-speed translation tables. Every member of a
cluster can be used as
a lookup key. The findrow()
function is used to do cluster key lookups. All data types
are supported. Duplicate keys are supported as well
Findrow() is highly optimized and can
do over 10 million searches per second. This makes findrow() ideal for
tasks that require fast lookups. Given the cluster name, cluster member to search
in, and data to searched for, findrow() returns the first row where
the key was found or returns a 0 if the key was not found.
duplicate keys, findrow() has an optional third parameter to find the Nth occurrence of a key.
- All members of a cluster, regardless of data type, are searchable as a key
- All keys are changeable
- All keys can contain duplicates
- All key searches take O(1) constant time -- virtually instant lookups
By default, all searches are case-regardless. Set the optional fourth parameter to TRUE if
you want a case-sensitive search.
Because all cluster fields are keys, bi-directional lookups are easy to do. In our example we will translate
from English to German and German to English.
To define a cluster, use the cluster
statement followed by the name of the cluster. In
our example, we are calling our cluster trans
. Our trans cluster has two
. To reference them we use trans->english$
cluster trans: english$, german$
The code below uses the trans
translate from English to German and German to English.