Circuit Implementation of Piecewise-Affine Functions Based on a Binary Search Tree