add generic ternary search