Re: Decision Tables



"Leslie Sanford" <jabberdabber@xxxxxxxxxxxxxxxxx> writes:

Recently I wrote a filter that took a stream of messages as an input, and if
the messages matched a certain criteria, transformed them into something
else; otherwise, it let the messages pass through unchanged.
<snip>

The functions in the decision table would look like this:

bool match0000(receivedMessage, comparisonMessage)
{
return true;
}

bool match0001(receivedMessage, comparisonMessage)
{
return receivedMessage.FirstName == comparisonMessage.FirstName;
}

bool match0010(receivedMessage, comparisonMessage)
{
return receivedMessage.LastName == comparisonMessage.LastName;
}

bool match0011(receivedMessage, comparisonMessage)
{
return match0001(receivedMessage, comparisonMessage) &&
match0010(receivedMessage, comparisonMessage);
}

And so on...

This looks a bit like C, but if your language has closures you can
encode arbitrarily complex expressions a newly created match function.

Another way to go about this (when you don't have closures) is to
encode the actions that match into a stack machine. One simple
encoding is as function pointers (invented language):

void match_first_name(rM, cM) { push(rM.FirstName == cM.FirstName); }
void match_last_name(rM, cM) { push(rM.LastName == cM.LastName); }
void match_country(rM, cM) { push(rM.Country == cM.Country); }

void match_and(rM, cM) { push(pop() & pop()); }
void match_or(rM, cM) { push(pop() | pop()); }
void match_not(rM, cM) { push(!pop()); }

Your complex matches then become short NULL terminated arrays for
these:

complex_match[] = { match_contry, match_not, match_first_name,
match_or, NULL };

Obviously, you can choose other primitives if you want more complex
actions, but the idea is the same.

--
Ben.
.



Relevant Pages

  • Decision Tables
    ... algorithm for determining whether a message matched the filter's criteria ... The thing is is that we may only be interested in matching certain fields. ... if(decisionTable(receivedMessage, comparisonMessage)) ... bool match0000 ...
    (comp.programming)
  • Re: Decision Tables
    ... bool match0000(receivedMessage, comparisonMessage) ... insights. ... It doesn't scale like you said and it seems a lot of work creating the ...
    (comp.programming)