I have a Hashtable that consist in pair<condition to check, result of check>. This represents a hashtable of conditions.
I want to have a list of instruction that use these conditions. The instructions is therefore composed of a set of conditions, and I want to evaluates instructions to true if all the conditions that belong to the instructions are evaluated to true.
The list of conditions that composed an instruction is build with
i.ID being the unique key (in this case an integer).
Conditions are evaluated by a separate thread and printing out the elements that exist into the HashTable of Conditions shows correct results sometimes conditions are true when they should be and go back to false when conditions are not verified.
The problem is that the hashtable of instructions contains values (i.e. results of tested conditions) that are always False… This seems therefore that
Hello Jasdev and thanks for your reply to this tricky post. In fact I did the following:
I added the pairs<instruction_ID, Ar_list_of_conditions> to the HashTable of Instructions as you suggested. Therefore the hash table of instructions contains the list of conditions instead of the list of results of these conditions. Then I I look for the current value of conditions in Hashtable of conditions.
This works but seems to me totally unefficient due to the fact that the HashTable of instructions should handle ref to results of conditions and not the conditions, checking conditions in HashTable of conditions involves a big overhead… Any other idea?
returns a Value type not Reference type, now there is such a thing as boxing in .net, in which value types can be used like reference types, but it has its overheads.
I would suggest wrapping the Boolean value inside a class with a property and adding that to your Hashtableofconditions
Before your comment, code was updating values in HtC with the following assignement
HtC[de.key]=true;
with de being a dictionnary entry of HtC, this was really slow. I follow your advice and encapsulate the boolean value in a class. Results are really better now.