I have a big table which inclues values according to parameters like x and y. How can i find a values fast enough without high cpu load?
OK here is:
1) You select y or z from menu of your program.This will be manual selection. 2) You are getting x values from a sensor to cpu 3) You are matching this x value with y or z according to your first sellection in step 1
For example :
x y z 1 11 23 2 10 22 3 9 26 4 7 20 . . . . . . 192 34 24
1) I selected y so i will use y values for my next matching operations. 2) I got x value (lets say 4) from a sensor automaticaly 3) then i should match x and y for 4. So result will be 7.
The problem is values are not mathematical they are random so i could not write formulas. I need matching form table as fast as i can.
That is a one-dimensional lookup, and it seems like all x values between 1 and 192 are represented. So instant lookup...
struct { unsigned y,z; } my_table[] = { {11,23}, {10,22}, ... }; my_y_result = my_table[x-1].y; my_z_result = my_table[x-1].z;
You may optionally define y = 0 and z = 1 and have a two-dimensional array:
unsigned my_array[][2] = { {11,23}, {10,22}, ... }; my_y_result = my_table[x-1][0]; my_z_result = my_table[x-1][1];