Z
Zenobia
I have a problem. I need to look up several values stored in
arrays. Each value is stored as a pair. The first (number)
represents the probability of this item occurring. For instance,
in the example below there are 11 items.
conFinal =
{2:'m',4:'n',6:'ng',8:'r',10:'l',12:'kh',14:'k',16:'s',18:'hl',19:'tl',20:'sh'}
Letter 'n' (2nd item) has a probability of 2 chances in 20 (1 in
10] but 'tl' has only a 1 in 20 chance. The chance is
determined by the maximum number in the array (20) and the
distance from the previous value pair. [for instance 'n' is 2
units distant from the previous value pair - ... 2:'m',4:'n' ...
What is the best structure to use for this. An ordinary array or
an associative array?
Assuming that I DON'T use an associative array (as per above) -
should I use a 2-D or 1-D ordinary array? eg a 1-D like this:
conFinal = ['2:m','4:n','6:ng', etc - using something like : or
| as a separator with which the array can be split() with to
separate the two items (number from letter) This is what I am
currently doing and I know the MUST be a better way.
PS: I would like a method that made my array definition
statements easy to write as there is LOT of data.
Are there any good web references on using associative arrays
(including the alternative syntax (is the syntax using {} and :
above. Is that declaration correct?).
I need to do this lookup often for lots of different groups of
data. So it's not just a one-of.
arrays. Each value is stored as a pair. The first (number)
represents the probability of this item occurring. For instance,
in the example below there are 11 items.
conFinal =
{2:'m',4:'n',6:'ng',8:'r',10:'l',12:'kh',14:'k',16:'s',18:'hl',19:'tl',20:'sh'}
Letter 'n' (2nd item) has a probability of 2 chances in 20 (1 in
10] but 'tl' has only a 1 in 20 chance. The chance is
determined by the maximum number in the array (20) and the
distance from the previous value pair. [for instance 'n' is 2
units distant from the previous value pair - ... 2:'m',4:'n' ...
What is the best structure to use for this. An ordinary array or
an associative array?
Assuming that I DON'T use an associative array (as per above) -
should I use a 2-D or 1-D ordinary array? eg a 1-D like this:
conFinal = ['2:m','4:n','6:ng', etc - using something like : or
| as a separator with which the array can be split() with to
separate the two items (number from letter) This is what I am
currently doing and I know the MUST be a better way.
PS: I would like a method that made my array definition
statements easy to write as there is LOT of data.
Are there any good web references on using associative arrays
(including the alternative syntax (is the syntax using {} and :
above. Is that declaration correct?).
I need to do this lookup often for lots of different groups of
data. So it's not just a one-of.