// "bool-merge.hac"
//	$Id: bool-merge.hac,v 1.3 2007/02/05 06:40:27 fang Exp $
// conditional routing

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
	This version uses array access to do the channel selection.  
 */
template <pint N>
defproc bool_merge(chan?(int) C; chan?(bool) I[N]; chan!(bool) O) {
int c;
bool x;
chp {
*[ C?(c);
//	[ []i:N: (c == i) -> I[N]?(x) ]
	I[c]?(x);
	O!(x)
]
}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
	Specialization using bool-control input.  
 */
defproc bool_merge_2(chan?(bool) S, I[2]; chan!(bool) O) {
bool c, x;
chp {
*[ S?(c);
	[ c -> I[1]?(x) [] else -> I[0]?(x) ];
	O!(x)
]
}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
	This version uses array access to do the channel selection.  
 */
template <pint N>
defproc bool_merge_select(chan?(int) C; chan?(bool) I[N]; chan!(bool) O) {
int c;
bool x;
chp {
*[ C?(c);
	[ []i:N: (c == i) -> I[N]?(x) ];
	O!(x)
]
}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

