![]() |
D.5 Using Clusters for Mapping and High-speed Translations |
findrow()
function to perform these lookups.
This system supports all data types and allows for duplicate keys and key value changes.>br>
Findrow()
is a highly optimized function that uses
hashing to perform lookups in O(1) time, enabling over 10 million
searches per second on a modern PC, regardless of the number of
rows. This makes Findrow()
ideal for tasks requiring
fast, efficient lookups. Given the cluster name, the cluster field
to search in, and the data to search for, Findrow()
returns the first row where the key is found or returns 0 if the
key is not found.
Program Explanation:
1. Cluster Definition:
A cluster named trans
is defined to store English words and their corresponding German translations. The cluster has two fields: english$
for English words and german$
for German words.
2. Adding Data:
The program adds entries to the trans
cluster:
'apple'
is paired with the German word 'der Apfel'
.'banana'
is paired with the German word 'die Banane'
.3. User Input Assignment:
The variable word$
is assigned the value of a$
, which is assumed to be a word entered by the user that they want to translate.
4. Searching for English Word:
The program searches the trans
cluster for a row where the english$
field matches word$
(the word entered by the user). The row number is stored in the variable row
.
5. English to German Translation:
If the word is found (row > 0
), the program prints the English word followed by its German translation, using ' >> '
as the separator. The loop then exits since the translation has been found.
6. Searching for German Word:
If the word wasn't found in the English field, the program then searches the trans
cluster for a row where the german$
field matches word$
.
7. German to English Translation:
If the word is found in the German field (row > 0
), the program prints the German word followed by its English translation, again using ' >> '
as the separator. The loop then exits since the translation has been found.
8. No Translation Found:
If the word is not found in either the English or German fields, the program prints a message indicating that there is no translation available for the word entered by the user.
Hide Description
|
|
Enter or modify the code below, and then click on RUN |
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |