I think the ternary operator in Fig. 1 should be: h2 = (p1 == i) ? x : h2
I think the ternary operator in Fig. 1 should be:
h2 = (p1 == i) ? x : h2