Re: Decision Tables
- From: Ben Bacarisse <ben.usenet@xxxxxxxxx>
- Date: Mon, 28 Jan 2008 17:20:10 +0000
"Leslie Sanford" <jabberdabber@xxxxxxxxxxxxxxxxx> writes:
Recently I wrote a filter that took a stream of messages as an input, and if<snip>
the messages matched a certain criteria, transformed them into something
else; otherwise, it let the messages pass through unchanged.
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.
.
- Follow-Ups:
- Re: Decision Tables
- From: kwikius
- Re: Decision Tables
- From: Leslie Sanford
- Re: Decision Tables
- References:
- Decision Tables
- From: Leslie Sanford
- Decision Tables
- Prev by Date: Re: Decision Tables
- Next by Date: Re: Crossword project.
- Previous by thread: Re: Decision Tables
- Next by thread: Re: Decision Tables
- Index(es):
Relevant Pages
|