i tried to read your thoughts and came up with a solution that memoizes function calls.
i hope that is what you wanted.
when asking for a functions output with a new combination of input values then we obviously need to call that function and store the result. if later on a known combination of input values reoccurs we can use the stored result.
note that i didn’t include any code to empty the ditctionary. so this dictionary will grow until - you know - someone stands up and shouts “memory leak!”…
in this version i just replaced the Tuple<double, double, bool> which occured over and over in the code with a type alias (MyKey). that way it gets more readable:
using MyKey = Tuple<double, double, bool>;
[PluginInfo(Name = "Memoize", Category = "Value", Version = "Double_Double_Bool_Double",
Help = "Memoize a Results of a Function", Tags = "",
Bugs = "To make this work with different functions we either need to empty the dictionary when a new function is connected or make the function part of the key.")]
public class Double_Double_Bool_DoubleValueMemoizeNode : IPluginEvaluate
// we accept any function that has the signature
// double -> double -> bool -> double
ISpread<Func<double, double, bool, double>> FFunc;
Dictionary<MyKey, double> Results = new Dictionary<MyKey, double>();
public void Evaluate(int SpreadMax)
FOutput.SliceCount = SpreadMax;
for (int i = 0; i < SpreadMax; i++)
// generate a key that is made of
// current x, current y, current ad input value
MyKey key = new MyKey(FX[i](i), FY[i](i), FAd[i](i));
// the result of the function will be stored in this variable
// lets have a look if we already have a result of the function for
// those three input values.
// if we have a result we dont need to call the function
// if have no result we need to call the function and store the result in the dictionary
if (!Results.TryGetValue(key, out result))
result = FFunc[i](FX[i](i](FX[i), FY[i](i), FAd[i](i));
Results[key](key) = result;
FOutput[i](i) = result;
hi , i got some progress thx but still many doubts , how could i apply a timer to each dictionary key so the value of dictionary is the time counting itself , i saw this Action Dictionary but it may not be for that
hi tonfilm , in general learning more c# and specially dictionary staff i love it so very glad for previous examples of gregsn and elias ,
in this particular , i,m trying to accomplish two task one is trying to make some animations basic plugs i made similar to this drag&slide file attached but dictionary ID based .
So instead if inputting slice based , inputting like id(key) and value based .
i made this draft plug as i thought it could behave the dictionary version also attached .
you input keys and values of the id you want to modify then once the id is not present in the input the friction part takes place (this will replace the Add pin) , then a getid pin which gets values and id of existing keys something like the custom in box2d .
in other hand but related because i think one task helps the other , i wanted to do a id alive time plug dictionary based this is why i wanted to associate a timer to each key been the timer the value of dictionary .
i have tried a few approaches but not good , not sure if it will be best to make all into new class and if so how .
take into account i am quite new to c# so although sometimes i get things quickly other times i feel quite blind about simple things , so any obvious thing you write or show might be a treasure for me hehe ;D
hope you understand the explanation i can make more examples if needed . thanks
i got the AliveTime Dictionary working not sure if it is too elegant so very welcome to received corrections or more efficient ways .
About the Drag animation i still do not know how to convert it to dictionary based , i thought that making a function of the friction part and put it in the dictionary as result will do it or probably a class of it but do not know how to get lastvalue into a function in the a class in the case this is the way.
so if you guys can guide me a bit on the drag to dictionary based would be great ;D .