implement compare_function