3.0 Data structure tips
[3.1] Using indirection and setFold() with matrix elements
Suppose you have a matrix M of folder names, stored as strings, and you want to set the current folder
in your program. This won't work:
setFold(#M[k,l])
(won't work!)
but this will:
setFold(#(M[k,l]))
(note extra parentheses around #M[k,l])
and so will this:
M[k,l]
→
fname
setfold(#fname)
(credit to Jordan Clifford for extra-parentheses method)
[3.2] Calculate table indices instead of searching
Many functions require searching a table by an index value, then returning the corresponding value, or
the two values that bracket an input value. Suppose we have this table:
0.44
1.1
4
0.33
0.9
3
0.22
0.7
2
0.11
0.5
1
y
x
index
If x = 0.7, the search routine should return 0.22. If x = 0.6, then the search routine should return 0.22,
0.33, or both, depending on the purpose of the program. For example, an interpolation routine would
need 0.22 and 0.33.
In the most general case, the program searches the x-column data to bracket the desired x-value.
Even for short tables and a fast search routine, this is slow. But if the x-data is evenly spaced and the
first x-value is known, then it is faster just to calculate the index, like this:
index
=
int
x
−
x1
dx
+
1
where x1 is the first x-value, x is the search target, and dx is the x-data spacing. For the table above,
x1 = 0.5 and dx = 0.2. int is the 89/92+ int() function. To find the index for x = 0.8, the calculation is
index
=
int
0.8
−
0.5
0.2
+
1
=
2
Note that this equation returns the index pointing to the x-value less than the target value.
If the x-data is in ascending order, dx is positive. If the x-data is in descending order, the formula works
correctly if dx is negative.
3 - 1
Summary of Contents for TI-92+
Page 52: ...Component side of PCB GraphLink I O connector detail 1 41...
Page 53: ...LCD connector detail PCB switch side 1 42...
Page 54: ...Key pad sheet contact side Key pad sheet key side 1 43...
Page 55: ...Key cap detail 1 44...
Page 57: ...Component side of PCB with shield removed A detail view of the intergrated circuits 1 46...
Page 410: ...void extensionroutine2 void Credit to Bhuvanesh Bhatt 10 4...