TSF provides two types for the manipulation of set of values ; the vectors and the hash tables. A vector is an sequence of values referenced by an integer index. The lower index is 1.
The following expressions can be used to manipulate hash tables.
The following are commons to vectors and hash tables.
Example 52:Print the content of a hash table.
SCRIPT DumpHashTable(H) // Version with the keys keys := HASHKEYS(H) FOR i := 1,LENGTH(keys) DO k := keys[i] PRINT TOSTRING(k)+" => "+TOSTRING(H{k}) ENDFOR ENDSCRIPT SCRIPT ShortDumpHashTable(H) // Version without the keys val := HASHVALUES(H) FOR i := 1,LENGTH(val) DO PRINT val[i] ENDFOR ENDSCRIPT
Example 53:A simple use of vectors and hash tables. Associate a string
(in english) to its numerical value.
SCRIPT main() // Create a vector of number (strings) v1 := VECTOR("one","two","three","four") // Create the equivalent vector of number (integers) v2 := NEWVECTOR(LENGTH(v1),FALSE) FOR i:=1,LENGTH(v2) DO v2[i] := i ENDFOR // Associate v1 and v2 in a hash table h := NEWHASH FOR i:=1,LENGTH(v1) DO h{v1[i]} := v2[i] ENDFOR // Print the value associated to the string "two" PRINT "The value of 'two' is " PRINT h{"two"} ENDSCRIPT
In the current version of TSF, there are some syntaxical restrictions in the usage of vectors and hash tables. A element can not be used as a reference in a function call or in a script call. For example, it is not possible to write the following statement: