I have the following problem, the code speaks for itself:
In[1]:= f[1][{1, 2}] = 112
Out[1]= 112
In[2]:= f[1][{3, 4}] = 114
Out[2]= 114
In[3]:= f[2][{1, 6}] = 216
Out[3]= 216
In[4]:= f[2][{2, 7}] = 227
Out[4]= 227
In[5]:= DownValues[f]
Out[5]= {}
In[6]:= SubValues[f]
Out[6]= {HoldPattern[f[1][{1, 2}]] :> 112,
HoldPattern[f[1][{3, 4}]] :> 114, HoldPattern[f[2][{1, 6}]] :> 216,
HoldPattern[f[2][{2, 7}]] :> 227}
In[7]:= SubValues[f[1]]
During evaluation of In[7]:= SubValues::sym: Argument f[1] at position 1 is expected to be a symbol. >>
Out[7]= SubValues[f[1]]
EDIT: the values above are not hard coded. They are constructed incrementally at run time. They are constructed using following algorithm:
f[_Integer][{_Integer..}] :=0
...
someplace later in the code, e.g.,
index = get index;
c = get random configuration (i.e. a pair of integers) = {n1, n2};
f[index][c] = f[index][c] + 1;
which tags that configuration c has occured once more in the simulation at time instance index
Please note that what happens in the last line is that the left hand side is not evaluated, the right hand side is, first the value for f[index][c] is looked up, if it is not found, then the defult rule is used which gives 0 + 1, if found the old value is incremented by one and stored. All this should be constant time. If one uses arrays, then it will be quadratic complexity (since whole array needs to be copied when one element is added).
The problem is that that, later on, I would like SubValues[f1] to give a list of definitions associated with f1 that are pattern free but the syntax of SubValues forces me to retrieve all of them. Of course, this has later impact on the speed since one has to extract f1s of interest (e.g. in this example f1[{1, 2}] = 112, and f1[{3, 4}] = 114) from possibly a very long list.
Ultimatelly the problem is to harvest f1 data so that the following structure is returned:
{list1, list2}
where
list1 = {{1,2}, {3,4}}
list2 = {112, 134}
I know that one can use Cases[SubValues[f], suitablePattern] and work on the result to get the desired outcome, but I would like to do this more directly and in the most efficient way (since the procedure is repeated many times at runtime).
Regards Zoran
EDIT: Seems that the problem was not well formulated. The better version of the the same problem can be found here:
so please "abandon the ship" and apologies for not being clear from scratch.