From cfa3a22a6588feb7f45a17713250acc34a679a44 Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Fri, 22 Mar 2024 11:04:56 -0500 Subject: [PATCH] Remove duplicated functions. --- bindings/python/cconfigspace/binding.py | 4 +- bindings/python/cconfigspace/context.py | 9 +- bindings/ruby/lib/cconfigspace/binding.rb | 6 +- bindings/ruby/lib/cconfigspace/context.rb | 7 +- connectors/kokkos/ccs-kokkos-connector.cpp | 15 +- include/cconfigspace/binding.h | 13 +- include/cconfigspace/configuration.h | 106 ----------- include/cconfigspace/configuration_space.h | 211 --------------------- include/cconfigspace/context.h | 103 +++++----- include/cconfigspace/evaluation.h | 107 ----------- include/cconfigspace/features.h | 104 ---------- include/cconfigspace/features_evaluation.h | 111 ----------- include/cconfigspace/features_space.h | 211 --------------------- include/cconfigspace/objective_space.h | 211 --------------------- include/cconfigspace/tree_evaluation.h | 107 ----------- samples/test_python.c | 4 +- samples/test_ruby.c | 4 +- src/binding.c | 12 +- src/binding_internal.h | 27 +-- src/configuration.c | 108 ++--------- src/configuration_internal.h | 8 +- src/configuration_space.c | 120 +----------- src/context.c | 3 +- src/context_internal.h | 17 +- src/evaluation.c | 114 +++-------- src/evaluation_internal.h | 10 +- src/features.c | 83 +------- src/features_evaluation.c | 134 ++++--------- src/features_evaluation_internal.h | 12 +- src/features_internal.h | 8 +- src/features_space.c | 115 ----------- src/features_tuner_random.c | 25 ++- src/objective_space.c | 115 ----------- src/tree_evaluation.c | 111 +++-------- src/tree_evaluation_internal.h | 13 +- tests/test_condition.c | 16 +- tests/test_configuration_space.c | 33 ++-- tests/test_distribution_space.c | 33 ++-- tests/test_features_space.c | 64 ++++--- tests/test_forbidden.c | 16 +- tests/test_random_features_tuner.c | 11 +- tests/test_random_tree_tuner.c | 3 +- tests/test_random_tuner.c | 7 +- tests/test_user_defined_features_tuner.c | 12 +- tests/test_user_defined_tuner.c | 4 +- 45 files changed, 389 insertions(+), 2178 deletions(-) diff --git a/bindings/python/cconfigspace/binding.py b/bindings/python/cconfigspace/binding.py index 422b36a7..c2a09ea2 100644 --- a/bindings/python/cconfigspace/binding.py +++ b/bindings/python/cconfigspace/binding.py @@ -5,7 +5,7 @@ ccs_binding_get_context = _ccs_get_function("ccs_binding_get_context", [ccs_binding, ct.POINTER(ccs_context)]) ccs_binding_get_value = _ccs_get_function("ccs_binding_get_value", [ccs_binding, ct.c_size_t, ct.POINTER(Datum)]) ccs_binding_get_values = _ccs_get_function("ccs_binding_get_values", [ccs_binding, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ct.c_size_t)]) -ccs_binding_get_value_by_name = _ccs_get_function("ccs_binding_get_value_by_name", [ccs_binding, ct.c_char_p, ct.POINTER(Datum)]) +ccs_binding_get_value_by_name = _ccs_get_function("ccs_binding_get_value_by_name", [ccs_binding, ct.c_char_p, ct.POINTER(ccs_bool), ct.POINTER(Datum)]) ccs_binding_get_value_by_parameter = _ccs_get_function("ccs_binding_get_value_by_parameter", [ccs_binding, ccs_parameter, ct.POINTER(ccs_bool), ct.POINTER(Datum)]) ccs_binding_hash = _ccs_get_function("ccs_binding_hash", [ccs_binding, ct.POINTER(ccs_hash)]) ccs_binding_cmp = _ccs_get_function("ccs_binding_cmp", [ccs_binding, ccs_binding, ct.POINTER(ct.c_int)]) @@ -37,7 +37,7 @@ def value(self, parameter): if isinstance(parameter, Parameter): res = ccs_binding_get_value_by_parameter(self.handle, parameter.handle, None, ct.byref(v)) elif isinstance(parameter, str): - res = ccs_binding_get_value_by_name(self.handle, str.encode(parameter), ct.byref(v)) + res = ccs_binding_get_value_by_name(self.handle, str.encode(parameter), None, ct.byref(v)) else: res = ccs_binding_get_value(self.handle, parameter, ct.byref(v)) Error.check(res) diff --git a/bindings/python/cconfigspace/context.py b/bindings/python/cconfigspace/context.py index aa8fb3af..af58767e 100644 --- a/bindings/python/cconfigspace/context.py +++ b/bindings/python/cconfigspace/context.py @@ -6,7 +6,7 @@ ccs_context_get_num_parameters = _ccs_get_function("ccs_context_get_num_parameters", [ccs_context, ct.POINTER(ct.c_size_t)]) ccs_context_get_parameter = _ccs_get_function("ccs_context_get_parameter", [ccs_context, ct.c_size_t, ct.POINTER(ccs_parameter)]) ccs_context_get_parameter_by_name = _ccs_get_function("ccs_context_get_parameter_by_name", [ccs_context, ct.c_char_p, ct.POINTER(ccs_parameter)]) -ccs_context_get_parameter_index_by_name = _ccs_get_function("ccs_context_get_parameter_index_by_name", [ccs_context, ct.c_char_p, ct.POINTER(ct.c_size_t)]) +ccs_context_get_parameter_index_by_name = _ccs_get_function("ccs_context_get_parameter_index_by_name", [ccs_context, ct.c_char_p, ct.POINTER(ccs_bool), ct.POINTER(ct.c_size_t)]) ccs_context_get_parameter_index = _ccs_get_function("ccs_context_get_parameter_index", [ccs_context, ccs_parameter, ct.POINTER(ccs_bool), ct.POINTER(ct.c_size_t)]) ccs_context_get_parameter_indexes = _ccs_get_function("ccs_context_get_parameter_indexes", [ccs_context, ct.c_size_t, ct.POINTER(ccs_parameter), ct.POINTER(ccs_bool), ct.POINTER(ct.c_size_t)]) ccs_context_get_parameters = _ccs_get_function("ccs_context_get_parameters", [ccs_context, ct.c_size_t, ct.POINTER(ccs_parameter), ct.POINTER(ct.c_size_t)]) @@ -34,7 +34,10 @@ def parameter_by_name(self, name): v = ccs_parameter() res = ccs_context_get_parameter_by_name(self.handle, str.encode(name), ct.byref(v)) Error.check(res) - return Parameter.from_handle(v) + if v.value is None: + return None + else: + return Parameter.from_handle(v) def parameter_index(self, parameter): v = ct.c_size_t() @@ -44,7 +47,7 @@ def parameter_index(self, parameter): def parameter_index_by_name(self, name): v = ct.c_size_t() - res = ccs_context_get_parameter_index_by_name(self.handle, str.encode(name), ct.byref(v)) + res = ccs_context_get_parameter_index_by_name(self.handle, str.encode(name), None, ct.byref(v)) Error.check(res) return v.value diff --git a/bindings/ruby/lib/cconfigspace/binding.rb b/bindings/ruby/lib/cconfigspace/binding.rb index 903fd436..8094b86b 100644 --- a/bindings/ruby/lib/cconfigspace/binding.rb +++ b/bindings/ruby/lib/cconfigspace/binding.rb @@ -2,7 +2,7 @@ module CCS attach_function :ccs_binding_get_context, [:ccs_binding_t, :pointer], :ccs_result_t attach_function :ccs_binding_get_value, [:ccs_binding_t, :size_t, :pointer], :ccs_result_t attach_function :ccs_binding_get_values, [:ccs_binding_t, :size_t, :pointer, :pointer], :ccs_result_t - attach_function :ccs_binding_get_value_by_name, [:ccs_binding_t, :string, :pointer], :ccs_result_t + attach_function :ccs_binding_get_value_by_name, [:ccs_binding_t, :string, :pointer, :pointer], :ccs_result_t attach_function :ccs_binding_get_value_by_parameter, [:ccs_binding_t, :ccs_parameter_t, :pointer, :pointer], :ccs_result_t attach_function :ccs_binding_hash, [:ccs_binding_t, :pointer], :ccs_result_t attach_function :ccs_binding_cmp, [:ccs_binding_t, :ccs_binding_t, :pointer], :ccs_result_t @@ -16,10 +16,10 @@ def value(parameter) ptr = MemoryPointer::new(:ccs_datum_t) case parameter when String - CCS.error_check CCS.ccs_binding_get_value_by_name(@handle, parameter, ptr) + CCS.error_check CCS.ccs_binding_get_value_by_name(@handle, parameter, nil, ptr) when Symbol name = parameter.inspect - CCS.error_check CCS.ccs_binding_get_value_by_name(@handle, name, ptr) + CCS.error_check CCS.ccs_binding_get_value_by_name(@handle, name, nil, ptr) when Parameter CCS.error_check CCS.ccs_binding_get_value_by_parameter(@handle, parameter.handle, nil, ptr) when Integer diff --git a/bindings/ruby/lib/cconfigspace/context.rb b/bindings/ruby/lib/cconfigspace/context.rb index e78b9c67..59e2feb7 100644 --- a/bindings/ruby/lib/cconfigspace/context.rb +++ b/bindings/ruby/lib/cconfigspace/context.rb @@ -3,7 +3,7 @@ module CCS attach_function :ccs_context_get_num_parameters, [:ccs_context_t, :pointer], :ccs_result_t attach_function :ccs_context_get_parameter, [:ccs_context_t, :size_t, :pointer], :ccs_result_t attach_function :ccs_context_get_parameter_by_name, [:ccs_context_t, :string, :pointer], :ccs_result_t - attach_function :ccs_context_get_parameter_index_by_name, [:ccs_context_t, :string, :pointer], :ccs_result_t + attach_function :ccs_context_get_parameter_index_by_name, [:ccs_context_t, :string, :pointer, :pointer], :ccs_result_t attach_function :ccs_context_get_parameter_index, [:ccs_context_t, :ccs_parameter_t, :pointer, :pointer], :ccs_result_t attach_function :ccs_context_get_parameter_indexes, [:ccs_context_t, :size_t, :pointer, :pointer, :pointer], :ccs_result_t attach_function :ccs_context_get_parameters, [:ccs_context_t, :size_t, :pointer, :pointer], :ccs_result_t @@ -30,13 +30,14 @@ def parameter_by_name(name) name = name.inspect if name.kind_of?(Symbol) ptr = MemoryPointer::new(:ccs_parameter_t) CCS.error_check CCS.ccs_context_get_parameter_by_name(@handle, name, ptr) - Parameter.from_handle(ptr.read_ccs_parameter_t) + param = ptr.read_ccs_parameter_t + param.null? ? nil : Parameter.from_handle(param) end def parameter_index_by_name(name) name = name.inspect if name.kind_of?(Symbol) ptr = MemoryPointer::new(:size_t) - CCS.error_check CCS.ccs_context_get_parameter_index_by_name(@handle, name, ptr) + CCS.error_check CCS.ccs_context_get_parameter_index_by_name(@handle, name, nil, ptr) ptr.read_size_t end diff --git a/connectors/kokkos/ccs-kokkos-connector.cpp b/connectors/kokkos/ccs-kokkos-connector.cpp index e56f4be8..f7f1f42c 100644 --- a/connectors/kokkos/ccs-kokkos-connector.cpp +++ b/connectors/kokkos/ccs-kokkos-connector.cpp @@ -584,9 +584,9 @@ kokkosp_request_values( ccs_datum_t *values = new ccs_datum_t[numContextVariables]; for (size_t i = 0; i < numContextVariables; i++) { size_t indx; - CCS_CHECK(ccs_features_space_get_parameter_index( - features_space, features[contextValues[i].type_id], - NULL, &indx)); + CCS_CHECK(ccs_context_get_parameter_index( + (ccs_context_t)features_space, + features[contextValues[i].type_id], NULL, &indx)); extract_value(contextValues + i, values + indx); } CCS_CHECK(ccs_create_features( @@ -604,12 +604,13 @@ kokkosp_request_values( tuner, &configuration_space)); { ccs_datum_t *values = new ccs_datum_t[numTuningVariables]; - CCS_CHECK(ccs_configuration_get_values( - configuration, numTuningVariables, values, NULL)); + CCS_CHECK(ccs_binding_get_values( + (ccs_binding_t)configuration, numTuningVariables, values, + NULL)); for (size_t i = 0; i < numTuningVariables; i++) { size_t indx; - CCS_CHECK(ccs_configuration_space_get_parameter_index( - configuration_space, + CCS_CHECK(ccs_context_get_parameter_index( + (ccs_context_t)configuration_space, parameters[tuningValues[i].type_id], NULL, &indx)); set_value(tuningValues + i, values + indx); } diff --git a/include/cconfigspace/binding.h b/include/cconfigspace/binding.h index 2d6752df..e6631027 100644 --- a/include/cconfigspace/binding.h +++ b/include/cconfigspace/binding.h @@ -78,13 +78,16 @@ ccs_binding_get_values( * Get the value of the parameter with the given name. * @param[in] binding * @param[in] name the name of the parameter whose value to retrieve + * @param[out] found_ret a pointer to the an optional variable that will + * hold wether a parameter named \p name was found in + * \p binding * @param[out] value_ret a pointer to the variable that will hold the value * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p binding is not a valid CCS * object * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the \p binding context + * @return #CCS_RESULT_ERROR_INVALID_NAME if \p found_ret is NULL no parameter + * with such \p name exist in the \p binding context * @remarks * This function is thread-safe */ @@ -92,6 +95,7 @@ extern ccs_result_t ccs_binding_get_value_by_name( ccs_binding_t binding, const char *name, + ccs_bool_t *found_ret, ccs_datum_t *value_ret); /** @@ -125,7 +129,7 @@ ccs_binding_get_value_by_parameter( * value. * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p binding is not a valid CCS - * object + * binding * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p hash_ret is NULL * @remarks * This function is thread-safe @@ -144,7 +148,8 @@ ccs_binding_hash(ccs_binding_t binding, ccs_hash_t *hash_ret); * than, equal, or greater then the second binding * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p binding or \p other_binding - * are not valid CCS objects + * are not valid CCS bindings; or if \p binding and \p other_binding are + * bindings of different types * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p cmp_ret is NULL * @remarks * This function is thread-safe diff --git a/include/cconfigspace/configuration.h b/include/cconfigspace/configuration.h index 7aaebe6f..87dc5d3e 100644 --- a/include/cconfigspace/configuration.h +++ b/include/cconfigspace/configuration.h @@ -57,74 +57,6 @@ ccs_configuration_get_configuration_space( ccs_configuration_t configuration, ccs_configuration_space_t *configuration_space_ret); -/** - * Get the value of the parameter at the given index. - * @param[in] configuration - * @param[in] index index of the parameter in the associated configuration - * space - * @param[out] value_ret a pointer to the variable that will hold the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration is not a valid - * CCS configuration - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the configuration space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_get_value( - ccs_configuration_t configuration, - size_t index, - ccs_datum_t *value_ret); - -/** - * Get all the values in the configuration. - * @param[in] configuration - * @param[in] num_values the size of the \p values array - * @param[out] values an array of size \p num_values to hold the returned - * values, or NULL. If the array is too big, extra values - * are set to #CCS_DATA_TYPE_NONE - * @param[out] num_values_ret a pointer to a variable that will contain the - * number of values that are or would be returned. - * Can be NULL - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration is not a valid - * CCS configuration - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p values is NULL and \p - * num_values is greater than 0; or if \p values is NULL and \p num_values_ret - * is NULL; or if \p num_values is less than the number of values that would be - * returned - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_get_values( - ccs_configuration_t configuration, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret); - -/** - * Get the value of the parameter with the given name. - * @param[in] configuration - * @param[in] name the name of the parameter whose value to retrieve - * @param[out] value_ret a pointer to the variable that will hold the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration is not a valid - * CCS configuration - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the \p configuration space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_get_value_by_name( - ccs_configuration_t configuration, - const char *name, - ccs_datum_t *value_ret); - /** * Check that the configuration is a valid configuration for the configuration * space. @@ -149,44 +81,6 @@ ccs_configuration_check( ccs_configuration_t configuration, ccs_bool_t *is_valid_ret); -/** - * Compute a hash value for the configuration by hashing together the - * configuration space reference, the number of values, and the values - * themselves. - * @param[in] configuration - * @param[out] hash_ret the address of the variable that will contain the hash - * value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration is not a valid - * CCS configuration - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p hash_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_hash(ccs_configuration_t configuration, ccs_hash_t *hash_ret); - -/** - * Define a strict ordering of configuration instances. Configuration space, - * number of values and values are compared. - * @param[in] configuration the first configuration - * @param[in] other_configuration the second configuration - * @param[out] cmp_ret the pointer to the variable that will contain the result - * of the comparison. Will contain -1, 0, or 1 depending on - * if the first configuration is found to be respectively - * lesser than, equal, or greater then the second - * configuration - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration or \p - * other_configuration are not a valid CCS object - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_cmp( - ccs_configuration_t configuration, - ccs_configuration_t other_configuration, - int *cmp_ret); #ifdef __cplusplus } #endif diff --git a/include/cconfigspace/configuration_space.h b/include/cconfigspace/configuration_space.h index a77d1a56..66cdb750 100644 --- a/include/cconfigspace/configuration_space.h +++ b/include/cconfigspace/configuration_space.h @@ -59,23 +59,6 @@ ccs_create_configuration_space( ccs_expression_t *forbidden_clauses, ccs_configuration_space_t *configuration_space_ret); -/** - * Get the name of a configuration space. - * @param[in] configuration_space - * @param[out] name_ret a pointer to a `char *` variable which will contain a - * pointer to the configuration space name. - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a - * valid CCS configuration space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_space_get_name( - ccs_configuration_space_t configuration_space, - const char **name_ret); - /** * Set (replace) the internal rng of the configuration space. * @param[in,out] configuration_space @@ -107,200 +90,6 @@ ccs_configuration_space_get_rng( ccs_configuration_space_t configuration_space, ccs_rng_t *rng_ret); -/** - * Get the number of parameters in a configuration space. - * @param[in] configuration_space - * @param[out] num_parameters_ret a pointer to the variable that will contain - * the number of parameters in the configuration - * space - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a - * valid CCS configuration space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p num_parameters_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_space_get_num_parameters( - ccs_configuration_space_t configuration_space, - size_t *num_parameters_ret); - -/** - * Get a parameter in a configuration space given its index. - * @param[in] configuration_space - * @param[in] index the index of the parameter to retrieve - * @param[out] parameter_ret a pointer to the variable that will contain - * the parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a - * valid CCS configuration space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p parameter_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the configuration space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_space_get_parameter( - ccs_configuration_space_t configuration_space, - size_t index, - ccs_parameter_t *parameter_ret); - -/** - * Get a parameter in a configuration space given its name. - * @param[in] configuration_space - * @param[in] name the name of the parameter to retrieve - * @param[out] parameter_ret a pointer to the variable that will contain - * the parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a - * valid CCS configuration space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name or \p parameter_ret are - * NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the \p configuration space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_space_get_parameter_by_name( - ccs_configuration_space_t configuration_space, - const char *name, - ccs_parameter_t *parameter_ret); - -/** - * Get the index of a parameter in the configuration space given its name. - * @param[in] configuration_space - * @param[in] name the name of the parameter to retrieve the index of - * @param[out] index_ret a pointer to the variable that will contain the index - * of parameter in the \p configuration_space - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a - * valid CCS configuration space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name or \p index_ret are NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the configuration space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_space_get_parameter_index_by_name( - ccs_configuration_space_t configuration_space, - const char *name, - size_t *index_ret); - -/** - * Get the index of a parameter in the configuration space. - * @param[in] configuration_space - * @param[in] parameter - * @param[out] found_ret a pointer to the an optional variable that will - * hold wether the parameter was found in the \p - * configuration_space - * @param[out] index_ret a pointer to the variable which will contain the index - * of the parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a - * valid CCS configuration space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p index_ret is NULL - * @return #CCS_RESULT_ERROR_INVALID_PARAMETER if \p found_ret is NULL - * and \p configuration_space does not contain \p parameter - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_space_get_parameter_index( - ccs_configuration_space_t configuration_space, - ccs_parameter_t parameter, - ccs_bool_t *found_ret, - size_t *index_ret); - -/** - * Get the indices of a set of parameters in a configuration space. - * @param[in] configuration_space - * @param[in] num_parameters the number of parameters to query the index for - * @param[in] parameters an array of \p num_parameters parameters to query the - * index for - * @param[out] found an optional array of \p num_parameters variables that - * will hold wether the parameter was found in \p - * configuration_space - * @param[out] indexes an array of \p num_parameters indices that will contain - * the values of the parameter indices - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a - * valid CCS configuration space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p parameters is NULL and \p - * num_parameters is greater than 0; or if \p indexes is NULL and \p - * num_parameters is greater than 0 - * @return #CCS_RESULT_ERROR_INVALID_PARAMETER if \p found is NULL and at - * least one of the parameters is not contained in \p configuration_space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_space_get_parameter_indexes( - ccs_configuration_space_t configuration_space, - size_t num_parameters, - ccs_parameter_t *parameters, - ccs_bool_t *found, - size_t *indexes); - -/** - * Get the parameters in the given configuration space. - * @param[in] configuration_space - * @param[in] num_parameters is the number of parameters that can be added to - * \p parameters. If \p parameters is not NULL \p - * num_parameters must be greater than 0 - * @param[out] parameters an array of \p num_parameters that will contain the - * returned parameters or NULL. If the array is too big, - * extra values are set to NULL - * @param[out] num_parameters_ret a pointer to a variable that will contain the - * number of parameters that are or would be - * returned. Can be NULL - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a - * valid CCS configuration space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p parameters is NULL and \p - * num_parameters is greater than 0; or if \p parameters is NULL and - * num_parameters_ret is NULL; or if \p num_parameters is less than the number - * of parameters that would be returned - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_space_get_parameters( - ccs_configuration_space_t configuration_space, - size_t num_parameters, - ccs_parameter_t *parameters, - size_t *num_parameters_ret); - -/** - * Validate that a given value at the given index is valid in a configuration - * space, and return a sanitized value. - * @param[in] configuration_space - * @param[in] index the index of the value in the configuration_space - * @param[in] value the datum to validate - * @param[out] value_ret a pointer that will contain the validated value. If \p - * value is a string \p value_ret will contain a non - * transient string. - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a - * valid CCS configuration space - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if index is greater than the number - * of parameters in \p configuration_space - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory while - * memoizing a string - * @return #CCS_RESULT_ERROR_INVALID_VALUE if the value did not validate or if - * value_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_configuration_space_validate_value( - ccs_configuration_space_t configuration_space, - size_t index, - ccs_datum_t value, - ccs_datum_t *value_ret); - /** * Get the active condition of a parameter in a configuration space given * it's index. diff --git a/include/cconfigspace/context.h b/include/cconfigspace/context.h index ecd84b53..1a09937d 100644 --- a/include/cconfigspace/context.h +++ b/include/cconfigspace/context.h @@ -30,31 +30,6 @@ extern "C" { extern ccs_result_t ccs_context_get_name(ccs_context_t context, const char **name_ret); -/** - * Get the index of an parameter in the context. - * @param[in] context - * @param[in] parameter - * @param[out] found_ret a pointer to the an optional variable that will - * hold wether the parameter was found in the \p - * context - * @param[out] index_ret a pointer to the variable which will contain the index - * of the parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p context is not a valid CCS - * object; - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p index_ret is NULL - * @return #CCS_RESULT_ERROR_INVALID_PARAMETER if \p found_ret is NULL and - * \p context does not contain \p parameter - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_context_get_parameter_index( - ccs_context_t context, - ccs_parameter_t parameter, - ccs_bool_t *found_ret, - size_t *index_ret); - /** * Get the number of parameters in the given context. * @param[in] context @@ -93,19 +68,47 @@ ccs_context_get_parameter( size_t index, ccs_parameter_t *parameter_ret); +/** + * Get the parameters in the given context. + * @param[in] context + * @param[in] num_parameters is the number of parameters that can be added to + * \p parameters. If \p parameters is not NULL \p + * num_parameters must be greater than 0 + * @param[in] parameters an array of \p num_parameters that will contain the + * returned parameters or NULL. If the array is too big, + * extra values are set to NULL + * @param[out] num_parameters_ret a pointer to a variable that will contain the + * number of parameters that are or would be + * returned. Can be NULL + * @return #CCS_RESULT_SUCCESS on success + * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p context is not a valid CCS + * object + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p parameters is NULL and \p + * num_parameters is greater than 0; or if \p parameters is NULL and \p + * num_parameters_ret is NULL; or if \p num_parameters is less than the number + * of parameters that would be returned + * @remarks + * This function is thread-safe + */ +extern ccs_result_t +ccs_context_get_parameters( + ccs_context_t context, + size_t num_parameters, + ccs_parameter_t *parameters, + size_t *num_parameters_ret); + /** * Get an parameter in a context given its name. * @param[in] context * @param[in] name the name of the parameter to retrieve * @param[out] parameter_ret a pointer to the variable that will contain the - * parameter + * parameter, or NULL if the parameter is not found + * in the context * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p context is not a valid CCS * object * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name or \p parameter_ret are * NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the \p context * @remarks * This function is thread-safe */ @@ -119,14 +122,17 @@ ccs_context_get_parameter_by_name( * Get the index of an parameter in the context given its name. * @param[in] context * @param[in] name the name of the parameter to retrieve the index of + * @param[out] found_ret a pointer to the an optional variable that will + * hold wether a parameter named \p name was found in + * \p context * @param[out] index_ret a pointer to the variable that will contain the index * of parameter in the \p context * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p context is not a valid CCS * object * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name or \p index_ret are NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the context + * @return #CCS_RESULT_ERROR_INVALID_NAME if \p found_ret is NULL and no + * parameter with such \p name exist in the context * @remarks * This function is thread-safe */ @@ -134,36 +140,33 @@ extern ccs_result_t ccs_context_get_parameter_index_by_name( ccs_context_t context, const char *name, + ccs_bool_t *found_ret, size_t *index_ret); /** - * Get the parameters in the given context. + * Get the index of an parameter in the context. * @param[in] context - * @param[in] num_parameters is the number of parameters that can be added to - * \p parameters. If \p parameters is not NULL \p - * num_parameters must be greater than 0 - * @param[in] parameters an array of \p num_parameters that will contain the - * returned parameters or NULL. If the array is too big, - * extra values are set to NULL - * @param[out] num_parameters_ret a pointer to a variable that will contain the - * number of parameters that are or would be - * returned. Can be NULL + * @param[in] parameter + * @param[out] found_ret a pointer to the an optional variable that will + * hold wether the parameter was found in the \p + * context + * @param[out] index_ret a pointer to the variable which will contain the index + * of the parameter * @return #CCS_RESULT_SUCCESS on success * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p context is not a valid CCS - * object - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p parameters is NULL and \p - * num_parameters is greater than 0; or if \p parameters is NULL and \p - * num_parameters_ret is NULL; or if \p num_parameters is less than the number - * of parameters that would be returned + * object; + * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p index_ret is NULL + * @return #CCS_RESULT_ERROR_INVALID_PARAMETER if \p found_ret is NULL and + * \p context does not contain \p parameter * @remarks * This function is thread-safe */ extern ccs_result_t -ccs_context_get_parameters( - ccs_context_t context, - size_t num_parameters, - ccs_parameter_t *parameters, - size_t *num_parameters_ret); +ccs_context_get_parameter_index( + ccs_context_t context, + ccs_parameter_t parameter, + ccs_bool_t *found_ret, + size_t *index_ret); /** * Get the indices of a set of parameters in a context. diff --git a/include/cconfigspace/evaluation.h b/include/cconfigspace/evaluation.h index b9addc0b..1380168a 100644 --- a/include/cconfigspace/evaluation.h +++ b/include/cconfigspace/evaluation.h @@ -120,74 +120,6 @@ ccs_evaluation_get_result( ccs_evaluation_t evaluation, ccs_evaluation_result_t *result_ret); -/** - * Get the value of the parameter at the given index. - * @param[in] evaluation - * @param[in] index index of the parameter in the associated objective - * space - * @param[out] value_ret a pointer to the variable that will hold the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p binding is not a valid CCS - * evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_get_value( - ccs_evaluation_t evaluation, - size_t index, - ccs_datum_t *value_ret); - -/** - * Get all the values in an evaluation. - * @param[in] evaluation - * @param[in] num_values the size of the \p values array - * @param[out] values an array of size \p num_values to hold the returned values - * or NULL. If the array is too big, extra values are set to - * #CCS_DATA_TYPE_NONE - * @param[out] num_values_ret a pointer to a variable that will contain the - * number of values that are or would be returned. - * Can be NULL - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p values is NULL and \p - * num_values is greater than 0; or if \p values is NULL and num_values_ret is - * NULL; or if num_values is less than the number of values that would be - * returned - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_get_values( - ccs_evaluation_t evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret); - -/** - * Get the value of the parameter with the given name. - * @param[in] evaluation - * @param[in] name the name of the parameter whose value to retrieve - * @param[out] value_ret a pointer to the variable that will hold the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the \p objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_get_value_by_name( - ccs_evaluation_t evaluation, - const char *name, - ccs_datum_t *value_ret); - /** * Check that an evaluation values are valid in the objective space. * @param[in] evaluation @@ -258,45 +190,6 @@ ccs_evaluation_get_objective_values( ccs_datum_t *values, size_t *num_values_ret); -/** - * Compute a hash value for the evaluation by hashing together the objective - * space reference, the configuration, the number of values, the values - * themselves, and the associated result. - * @param[in] evaluation - * @param[out] hash_ret the address of the variable that will contain the hash - * value. - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p hash_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_hash(ccs_evaluation_t evaluation, ccs_hash_t *hash_ret); - -/** - * Define a strict ordering of evaluation instances. Objective space, - * configuration, number of values, values, and result codes are compared. - * @param[in] evaluation the first evaluation - * @param[in] other_evaluation the second evaluation - * @param[out] cmp_ret a pointer to the variable that will contain the result - * of the comparison. Will contain -1, 0, or 1 depending on - * if the first evaluation is found to be respectively - * lesser than, equal, or greater then the second evaluation - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation or \p - * other_evaluation are not valid CCS evaluations - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p cmp_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_evaluation_cmp( - ccs_evaluation_t evaluation, - ccs_evaluation_t other_evaluation, - int *cmp_ret); - /** * Compare two successful evaluations objectives. * @param[in] evaluation the first evaluation diff --git a/include/cconfigspace/features.h b/include/cconfigspace/features.h index a46182fc..6c01dcd7 100644 --- a/include/cconfigspace/features.h +++ b/include/cconfigspace/features.h @@ -55,73 +55,6 @@ ccs_features_get_features_space( ccs_features_t features, ccs_features_space_t *features_space_ret); -/** - * Get the value of the parameter at the given index. - * @param[in] features - * @param[in] index index of the parameter in the associated features space - * @param[out] value_ret a pointer to the variable that will hold the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features is not a valid CCS - * features - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the features space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_get_value( - ccs_features_t features, - size_t index, - ccs_datum_t *value_ret); - -/** - * Get all the values in the features. - * @param[in] features - * @param[in] num_values the size of the \p values array - * @param[out] values an array of size \p num_values to hold the returned - * values, or NULL. If the array is too big, extra values - * are set to #CCS_DATA_TYPE_NONE - * @param[out] num_values_ret a pointer to a variable that will contain the - * number of values that are or would be returned. - * Can be NULL - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features is not a valid CCS - * features - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p values is NULL and \p - * num_values is greater than 0; or if \p values is NULL and num_values_ret is - * NULL; or if \p num_values is less than the number of values that would be - * returned - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_get_values( - ccs_features_t features, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret); - -/** - * Get the value of the parameter with the given name. - * @param[in] features - * @param[in] name the name of the parameter whose value to retrieve - * @param[out] value_ret a pointer to the variable that will hold the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features is not a valid CCS - * features - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the \p features space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_get_value_by_name( - ccs_features_t features, - const char *name, - ccs_datum_t *value_ret); - /** * Check that the features is a valid features for the features space. * @param[in] features @@ -141,43 +74,6 @@ ccs_features_get_value_by_name( extern ccs_result_t ccs_features_check(ccs_features_t features, ccs_bool_t *is_valid_ret); -/** - * Compute a hash value for the features by hashing together the features space - * reference, the number of values, and the values themselves. - * @param[in] features - * @param[out] hash_ret the address of the variable that will contain the hash - * value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features is not a valid CCS - * features - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p hash_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_hash(ccs_features_t features, ccs_hash_t *hash_ret); - -/** - * Define a strict ordering of features instances. Configuration space, number - * of values and values are compared. - * @param[in] features the first features - * @param[in] other_features the second features - * @param[out] cmp_ret the pointer to the variable that will contain the result - * of the comparison. Will contain -1, 0, or 1 depending on - * if the first features is found to be respectively lesser - * than, equal, or greater then the second features - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features or \p other_features - * are not a valid CCS object - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_cmp( - ccs_features_t features, - ccs_features_t other_features, - int *cmp_ret); - #ifdef __cplusplus } #endif diff --git a/include/cconfigspace/features_evaluation.h b/include/cconfigspace/features_evaluation.h index 654422db..5f4805ca 100644 --- a/include/cconfigspace/features_evaluation.h +++ b/include/cconfigspace/features_evaluation.h @@ -118,74 +118,6 @@ ccs_features_evaluation_get_result( ccs_features_evaluation_t features_evaluation, ccs_evaluation_result_t *result_ret); -/** - * Get the value of the parameter at the given index. - * @param[in] features_evaluation - * @param[in] index index of the parameter in the associated objective - * space - * @param[out] value_ret a pointer to the variable that will hold the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p binding is not a valid CCS - * features evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_get_value( - ccs_features_evaluation_t features_evaluation, - size_t index, - ccs_datum_t *value_ret); - -/** - * Get all the values in a features evaluation. - * @param[in] features_evaluation - * @param[in] num_values the size of the \p values array - * @param[out] values an array of size \p num_values to hold the returned values - * or NULL. If the array is too big, extra values are set to - * #CCS_DATA_TYPE_NONE - * @param[out] num_values_ret a pointer to a variable that will contain the - * number of values that are or would be returned. - * Can be NULL - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_evaluation is not a - * valid CCS features evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p values is NULL and \p - * num_values is greater than 0; or if \p values is NULL and num_values_ret is - * NULL; or if num_values is less than the number of values that would be - * returned - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_get_values( - ccs_features_evaluation_t features_evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret); - -/** - * Get the value of the parameter with the given name. - * @param[in] features_evaluation - * @param[in] name the name of the parameter whose value to retrieve - * @param[out] value_ret a pointer to the variable that will hold the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_evaluation is not a - * valid CCS features evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the \p objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_get_value_by_name( - ccs_features_evaluation_t features_evaluation, - const char *name, - ccs_datum_t *value_ret); - /** * Get the value of an objective for a valid features evaluation in the context * of its objective space. @@ -237,49 +169,6 @@ ccs_features_evaluation_get_objective_values( ccs_datum_t *values, size_t *num_values_ret); -/** - * Compute a hash value for a features evaluation by hashing together the - * objective space reference, the configuration, the features, the number of - * values, the values themselves, and the associated result. - * @param[in] features_evaluation - * @param[out] hash_ret the address of the variable that will contain the hash - * value. - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_evaluation is not a - * valid CCS features evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p hash_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_hash( - ccs_features_evaluation_t features_evaluation, - ccs_hash_t *hash_ret); - -/** - * Define a strict ordering of features evaluation instances. Objective space, - * configuration, features, number of values, values, and result codes are - * compared. - * @param[in] features_evaluation the first features evaluation - * @param[in] other_features_evaluation the second features evaluation - * @param[out] cmp_ret a pointer to the variable that will contain the result - * of the comparison. Will contain -1, 0, or 1 depending on - * if the first features evaluation is found to be - * respectively lesser than, equal, or greater then the - * second features evaluation - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_evaluation or \p - * other_features_evaluation are not valid CCS features evaluations - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p cmp_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_evaluation_cmp( - ccs_features_evaluation_t features_evaluation, - ccs_features_evaluation_t other_features_evaluation, - int *cmp_ret); - /** * Compare two successful features evaluations objectives. * @param[in] features_evaluation the first features evaluation diff --git a/include/cconfigspace/features_space.h b/include/cconfigspace/features_space.h index e7fdca2e..8921fcfc 100644 --- a/include/cconfigspace/features_space.h +++ b/include/cconfigspace/features_space.h @@ -36,217 +36,6 @@ ccs_create_features_space( ccs_parameter_t *parameters, ccs_features_space_t *features_space_ret); -/** - * Get the name of a features space. - * @param[in] features_space - * @param[out] name_ret a pointer to a `char *` variable which will contain a - * pointer to the features space name. - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features space is not a valid - * CCS features space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_space_get_name( - ccs_features_space_t features_space, - const char **name_ret); - -/** - * Get the number of parameters in a features space. - * @param[in] features_space - * @param[out] num_parameters_ret a pointer to the variable that will contain - * the number of parameters in the features - * space - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_space is not a valid - * CCS features space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p num_parameters_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_space_get_num_parameters( - ccs_features_space_t features_space, - size_t *num_parameters_ret); - -/** - * Get an parameter in a features space given its index. - * @param[in] features_space - * @param[in] index the index of the parameter to retrieve - * @param[out] parameter_ret a pointer to the variable that will contain the - * parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_space is not a valid - * CCS features space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p parameter_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the features space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_space_get_parameter( - ccs_features_space_t features_space, - size_t index, - ccs_parameter_t *parameter_ret); - -/** - * Get an parameter in a features space given its name. - * @param[in] features_space - * @param[in] name the name of the parameter to retrieve - * @param[out] parameter_ret a pointer to the variable that will contain the - * parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_space is not a valid - * CCS features space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name or \p parameter_ret are - * NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the \p features space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_space_get_parameter_by_name( - ccs_features_space_t features_space, - const char *name, - ccs_parameter_t *parameter_ret); - -/** - * Get the index of an parameter in the features space given its name. - * @param[in] features_space - * @param[in] name the name of the parameter to retrieve the index of - * @param[out] index_ret a pointer to the variable that will contain the index - * of parameter in the \p features_space - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_space is not a valid - * CCS features space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name or \p index_ret are NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the features space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_space_get_parameter_index_by_name( - ccs_features_space_t features_space, - const char *name, - size_t *index_ret); - -/** - * Get the index of an parameter in the features space. - * @param[in] features_space - * @param[in] parameter - * @param[out] found_ret a pointer to the an optional variable that will - * hold wether the parameter was found in the \p - * features_space - * @param[out] index_ret a pointer to the variable which will contain the index - * of the parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_space is not a valid - * CCS features space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p index_ret is NULL - * @return #CCS_RESULT_ERROR_INVALID_PARAMETER if \p found_ret is NULL - * and \p features_space does not contain \p parameter - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_space_get_parameter_index( - ccs_features_space_t features_space, - ccs_parameter_t parameter, - ccs_bool_t *found_ret, - size_t *index_ret); - -/** - * Get the indices of a set of parameters in a features space. - * @param[in] features_space - * @param[in] num_parameters the number of parameters to query the index for - * @param[in] parameters an array of \p num_parameters parameters to query the - * index for - * @param[out] found an optional array of \p num_parameters variables that - * will hold wether the parameter was found in \p - * features_space - * @param[out] indexes an array of \p num_parameters indices that will - * contain the values of the parameter indices - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_space is not a valid - * CCS features space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p parameters is NULL and \p - * num_parameters is greater than 0; or if \p indexes is NULL and \p - * num_parameters is greater than 0 - * @return #CCS_RESULT_ERROR_INVALID_PARAMETER if \p found is NULL and at - * least one of the parameters is not contained in \p features_space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_space_get_parameter_indexes( - ccs_features_space_t features_space, - size_t num_parameters, - ccs_parameter_t *parameters, - ccs_bool_t *found, - size_t *indexes); - -/** - * Get the parameters in the given features space. - * @param[in] features_space - * @param[in] num_parameters is the number of parameters that can be added to - * \p parameters. If \p parameters is not NULL \p - * num_parameters must be greater than 0 - * @param[in] parameters an array of \p num_parameters that will contain the - * returned parameters or NULL. If the array is too big, - * extra values are set to NULL - * @param[out] num_parameters_ret a pointer to a variable that will contain the - * number of parameters that are or would be - * returned. Can be NULL - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_space is not a valid - * CCS features space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p parameters is NULL and \p - * num_parameters is greater than 0; or if \p parameters is NULL and - * num_parameters_ret is NULL; or if \p num_parameters is less than the number - * of parameters that would be returned - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_space_get_parameters( - ccs_features_space_t features_space, - size_t num_parameters, - ccs_parameter_t *parameters, - size_t *num_parameters_ret); - -/** - * Validate that a given value at the given index is valid in a features - * space, and return a sanitized value. - * @param[in] features_space - * @param[in] index the index of the value in the features_space - * @param[in] value the datum to validate - * @param[out] value_ret a pointer that will contain the validated value. If \p - * value is a string \p value_ret will contain a non - * transient string. - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p features_space is not a valid - * CCS features space - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if index is greater than the number - * of parameters in \p features_space - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory while - * memoizing a string - * @return #CCS_RESULT_ERROR_INVALID_VALUE if the value did not validate or if - * value_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_features_space_validate_value( - ccs_features_space_t features_space, - size_t index, - ccs_datum_t value, - ccs_datum_t *value_ret); - /** * Check that a features is a valid in a features space. * @param[in] features_space diff --git a/include/cconfigspace/objective_space.h b/include/cconfigspace/objective_space.h index 94d61417..1c12ffe4 100644 --- a/include/cconfigspace/objective_space.h +++ b/include/cconfigspace/objective_space.h @@ -69,189 +69,6 @@ ccs_create_objective_space( ccs_objective_type_t *types, ccs_objective_space_t *objective_space_ret); -/** - * Get the name of a objective space. - * @param[in] objective_space - * @param[out] name_ret a pointer to a `char *` variable which will contain a - * pointer to the objective space name. - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective space is not a valid - * CCS objective space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_objective_space_get_name( - ccs_objective_space_t objective_space, - const char **name_ret); - -/** - * Get the number of parameters in a objective space. - * @param[in] objective_space - * @param[out] num_parameters_ret a pointer to the variable that will contain - * the number of parameters in the objective - * space - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not a valid - * CCS objective space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p num_parameters_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_objective_space_get_num_parameters( - ccs_objective_space_t objective_space, - size_t *num_parameters_ret); - -/** - * Get an parameter in a objective space given its index. - * @param[in] objective_space - * @param[in] index the index of the parameter to retrieve - * @param[out] parameter_ret a pointer to the variable that will contain the - * parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not a valid - * CCS objective space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p parameter_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_objective_space_get_parameter( - ccs_objective_space_t objective_space, - size_t index, - ccs_parameter_t *parameter_ret); - -/** - * Get an parameter in a objective space given its name. - * @param[in] objective_space - * @param[in] name the name of the parameter to retrieve - * @param[out] parameter_ret a pointer to the variable that will contain the - * parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not a valid - * CCS objective space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name or \p parameter_ret are - * NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the \p objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_objective_space_get_parameter_by_name( - ccs_objective_space_t objective_space, - const char *name, - ccs_parameter_t *parameter_ret); - -/** - * Get the index of an parameter in the objective space given its name. - * @param[in] objective_space - * @param[in] name the name of the parameter to retrieve the index of - * @param[out] index_ret a pointer to the variable that will contain the index - * of parameter in the \p objective_space - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not a valid - * CCS objective space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p name or \p index_ret are NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_objective_space_get_parameter_index_by_name( - ccs_objective_space_t objective_space, - const char *name, - size_t *index_ret); - -/** - * Get the index of an parameter in the objective space. - * @param[in] objective_space - * @param[in] parameter - * @param[out] found_ret a pointer to the an optional variable that will - * hold wether the parameter was found in the \p - * objective_space - * @param[out] index_ret a pointer to the variable which will contain the index - * of the parameter - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not a valid - * CCS objective space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p index_ret is NULL - * @return #CCS_RESULT_ERROR_INVALID_PARAMETER if \p found_ret is NULL and - * \p objective_space does not contain \p parameter - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_objective_space_get_parameter_index( - ccs_objective_space_t objective_space, - ccs_parameter_t parameter, - ccs_bool_t *found_ret, - size_t *index_ret); - -/** - * Get the indices of a set of parameters in a objective space. - * @param[in] objective_space - * @param[in] num_parameters the number of parameters to query the index for - * @param[in] parameters an array of \p num_parameters parameters to query the - * index for - * @param[out] found an optional array of \p num_parameters variables that - * will hold wether the parameter was found in \p - * objective_space - * @param[out] indexes an array of \p num_parameters indices that will contain - * the values of the parameter indices - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not a valid - * CCS objective space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p parameters is NULL and \p - * num_parameters is greater than 0; or if \p indexes is NULL and \p - * num_parameters is greater than 0 - * @return #CCS_RESULT_ERROR_INVALID_PARAMETER if \p found is NULL and at - * least one of the parameters is not contained in \p objective_space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_objective_space_get_parameter_indexes( - ccs_objective_space_t objective_space, - size_t num_parameters, - ccs_parameter_t *parameters, - ccs_bool_t *found, - size_t *indexes); - -/** - * Get the parameters in the given objective space. - * @param[in] objective_space - * @param[in] num_parameters is the number of parameters that can be added to - * \p parameters. If \p parameters is not NULL \p - * num_parameters must be greater than 0 - * @param[in] parameters an array of \p num_parameters that will contain the - * returned parameters or NULL. If the array is too big, - * extra values are set to NULL - * @param[out] num_parameters_ret a pointer to a variable that will contain the - * number of parameters that are or would be - * returned. Can be NULL @return - * #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not a valid - * CCS objective space - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p parameters is NULL and \p - * num_parameters is greater than 0; or if \p parameters is NULL and - * num_parameters_ret is NULL; or if \p num_parameters is less than the number - * of parameters that would be returned - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_objective_space_get_parameters( - ccs_objective_space_t objective_space, - size_t num_parameters, - ccs_parameter_t *parameters, - size_t *num_parameters_ret); - /** * Check that a evaluation is a valid in a objective space. * @param[in] objective_space @@ -279,34 +96,6 @@ ccs_objective_space_check_evaluation( ccs_evaluation_t evaluation, ccs_bool_t *is_valid_ret); -/** - * Validate that a given value at the given index is valid in a objective - * space, and return a sanitized value. - * @param[in] objective_space - * @param[in] index the index of the value in the objective_space - * @param[in] value the datum to validate - * @param[out] value_ret a pointer that will contain the validated value. If \p - * value is a string \p value_ret will contain a non - * transient string. - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p objective_space is not a valid - * CCS objective space - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if index is greater than the number - * of parameters in \p objective_space - * @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory while - * memoizing a string - * @return #CCS_RESULT_ERROR_INVALID_VALUE if the value did not validate or if - * value_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_objective_space_validate_value( - ccs_objective_space_t objective_space, - size_t index, - ccs_datum_t value, - ccs_datum_t *value_ret); - /** * Get the objective of rank index in a objective space. * @param[in] objective_space diff --git a/include/cconfigspace/tree_evaluation.h b/include/cconfigspace/tree_evaluation.h index 17342ad0..4f8df716 100644 --- a/include/cconfigspace/tree_evaluation.h +++ b/include/cconfigspace/tree_evaluation.h @@ -98,74 +98,6 @@ ccs_tree_evaluation_get_result( ccs_tree_evaluation_t evaluation, ccs_evaluation_result_t *result_ret); -/** - * Get the value of the parameter at the given index. - * @param[in] evaluation - * @param[in] index index of the parameter in the associated objective - * space - * @param[out] value_ret a pointer to the variable that will hold the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p binding is not a valid CCS - * tree evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count - * of parameters in the objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_get_value( - ccs_tree_evaluation_t evaluation, - size_t index, - ccs_datum_t *value_ret); - -/** - * Get all the values in a tree evaluation. - * @param[in] evaluation - * @param[in] num_values the size of the \p values array - * @param[out] values an array of size \p num_values to hold the returned values - * or NULL. If the array is too big, extra values are set to - * #CCS_DATA_TYPE_NONE - * @param[out] num_values_ret a pointer to a variable that will contain the - * number of values that are or would be returned. - * Can be NULL - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * tree evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p values is NULL and \p - * num_values is greater than 0; or if \p values is NULL and num_values_ret is - * NULL; or if num_values is less than the number of values that would be - * returned - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_get_values( - ccs_tree_evaluation_t evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret); - -/** - * Get the value of the parameter with the given name. - * @param[in] evaluation - * @param[in] name the name of the parameter whose value to retrieve - * @param[out] value_ret a pointer to the variable that will hold the value - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * tree evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL - * @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name - * exist in the \p objective space - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_get_value_by_name( - ccs_tree_evaluation_t evaluation, - const char *name, - ccs_datum_t *value_ret); - /** * Check that an evaluation values are valid in the objective space. * @param[in] evaluation @@ -238,45 +170,6 @@ ccs_tree_evaluation_get_objective_values( ccs_datum_t *values, size_t *num_values_ret); -/** - * Compute a hash value for the tree evaluation by hashing together the - * objective space reference, the configuration, the number of values, the - * values themselves, and the associated result. - * @param[in] evaluation - * @param[out] hash_ret the address of the variable that will contain the hash - * value. - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation is not a valid CCS - * tree evaluation - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p hash_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_hash(ccs_tree_evaluation_t evaluation, ccs_hash_t *hash_ret); - -/** - * Define a strict ordering of tree evaluation instances. Objective space, - * configuration, number of values, values, and result codes are compared. - * @param[in] evaluation the first evaluation - * @param[in] other_evaluation the second evaluation - * @param[out] cmp_ret a pointer to the variable that will contain the result - * of the comparison. Will contain -1, 0, or 1 depending on - * if the first evaluation is found to be respectively - * lesser than, equal, or greater then the second evaluation - * @return #CCS_RESULT_SUCCESS on success - * @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p evaluation or \p - * other_evaluation are not valid CCS tree evaluations - * @return #CCS_RESULT_ERROR_INVALID_VALUE if \p cmp_ret is NULL - * @remarks - * This function is thread-safe - */ -extern ccs_result_t -ccs_tree_evaluation_cmp( - ccs_tree_evaluation_t evaluation, - ccs_tree_evaluation_t other_evaluation, - int *cmp_ret); - /** * Compare two successful tree evaluations objectives. * @param[in] evaluation the first evaluation diff --git a/samples/test_python.c b/samples/test_python.c index 239be7a5..a82cdfcf 100644 --- a/samples/test_python.c +++ b/samples/test_python.c @@ -68,8 +68,8 @@ test_tuner(ccs_tuner_t tuner, ccs_objective_space_t ospace) ccs_evaluation_t evaluation; err = ccs_tuner_ask(tuner, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_get_values( - configuration, 2, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configuration, 2, values, NULL); assert(err == CCS_RESULT_SUCCESS); res = ccs_float( (values[0].value.f - 1) * (values[0].value.f - 1) + diff --git a/samples/test_ruby.c b/samples/test_ruby.c index c2ce4c69..dbb03ce1 100644 --- a/samples/test_ruby.c +++ b/samples/test_ruby.c @@ -77,8 +77,8 @@ test_tuner(ccs_tuner_t tuner, ccs_objective_space_t ospace) ccs_evaluation_t evaluation; err = ccs_tuner_ask(tuner, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_get_values( - configuration, 2, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configuration, 2, values, NULL); assert(err == CCS_RESULT_SUCCESS); res = ccs_float( (values[0].value.f - 1) * (values[0].value.f - 1) + diff --git a/src/binding.c b/src/binding.c index 8dac011e..229ca72c 100644 --- a/src/binding.c +++ b/src/binding.c @@ -43,10 +43,12 @@ ccs_result_t ccs_binding_get_value_by_name( ccs_binding_t binding, const char *name, + ccs_bool_t *found_ret, ccs_datum_t *value_ret) { CCS_CHECK_BINDING(binding); - CCS_VALIDATE(_ccs_binding_get_value_by_name(binding, name, value_ret)); + CCS_VALIDATE(_ccs_binding_get_value_by_name( + binding, name, found_ret, value_ret)); return CCS_RESULT_SUCCESS; } @@ -67,8 +69,9 @@ ccs_result_t ccs_binding_hash(ccs_binding_t binding, ccs_hash_t *hash_ret) { CCS_CHECK_BINDING(binding); + CCS_CHECK_PTR(hash_ret); _ccs_binding_ops_t *ops = ccs_binding_get_ops(binding); - CCS_VALIDATE(ops->hash(binding->data, hash_ret)); + CCS_VALIDATE(ops->hash(binding, hash_ret)); return CCS_RESULT_SUCCESS; } @@ -77,12 +80,15 @@ ccs_binding_cmp(ccs_binding_t binding, ccs_binding_t other_binding, int *cmp_ret { CCS_CHECK_BINDING(binding); CCS_CHECK_BINDING(other_binding); + CCS_REFUTE( + binding->obj.type != other_binding->obj.type, + CCS_RESULT_ERROR_INVALID_OBJECT); CCS_CHECK_PTR(cmp_ret); if (binding == other_binding) { *cmp_ret = 0; return CCS_RESULT_SUCCESS; } _ccs_binding_ops_t *ops = ccs_binding_get_ops(binding); - CCS_VALIDATE(ops->cmp(binding->data, other_binding, cmp_ret)); + CCS_VALIDATE(ops->cmp(binding, other_binding, cmp_ret)); return CCS_RESULT_SUCCESS; } diff --git a/src/binding_internal.h b/src/binding_internal.h index 128f153b..e42aef24 100644 --- a/src/binding_internal.h +++ b/src/binding_internal.h @@ -7,12 +7,10 @@ typedef struct _ccs_binding_data_s _ccs_binding_data_t; struct _ccs_binding_ops_s { _ccs_object_ops_t obj_ops; - ccs_result_t (*hash)(_ccs_binding_data_t *data, ccs_hash_t *hash_ret); + ccs_result_t (*hash)(ccs_binding_t binding, ccs_hash_t *hash_ret); - ccs_result_t (*cmp)( - _ccs_binding_data_t *data, - ccs_binding_t other, - int *cmp_ret); + ccs_result_t ( + *cmp)(ccs_binding_t binding, ccs_binding_t other, int *cmp_ret); }; typedef struct _ccs_binding_ops_s _ccs_binding_ops_t; @@ -77,12 +75,15 @@ static inline ccs_result_t _ccs_binding_get_value_by_name( ccs_binding_t binding, const char *name, + ccs_bool_t *found_ret, ccs_datum_t *value_ret) { CCS_CHECK_PTR(name); size_t index; CCS_VALIDATE(ccs_context_get_parameter_index_by_name( - binding->data->context, name, &index)); + binding->data->context, name, found_ret, &index)); + if (found_ret && !*found_ret) + return CCS_RESULT_SUCCESS; CCS_VALIDATE(_ccs_binding_get_value(binding, index, value_ret)); return CCS_RESULT_SUCCESS; } @@ -104,10 +105,10 @@ _ccs_binding_get_value_by_parameter( } static inline ccs_result_t -_ccs_binding_hash(_ccs_binding_data_t *data, ccs_hash_t *hash_ret) +_ccs_binding_hash(ccs_binding_t binding, ccs_hash_t *hash_ret) { - CCS_CHECK_PTR(hash_ret); - ccs_hash_t h, ht; + _ccs_binding_data_t *data = binding->data; + ccs_hash_t h, ht; HASH_JEN(&(data->context), sizeof(data->context), h); HASH_JEN(&(data->num_values), sizeof(data->num_values), ht); h = _hash_combine(h, ht); @@ -121,11 +122,11 @@ _ccs_binding_hash(_ccs_binding_data_t *data, ccs_hash_t *hash_ret) static inline ccs_result_t _ccs_binding_cmp( - _ccs_binding_data_t *data, - ccs_binding_t other_binding, - int *cmp_ret) + ccs_binding_t binding, + ccs_binding_t other_binding, + int *cmp_ret) { - CCS_CHECK_PTR(cmp_ret); + _ccs_binding_data_t *data = binding->data; _ccs_binding_data_t *other_data = other_binding->data; if (data == other_data) { *cmp_ret = 0; diff --git a/src/configuration.c b/src/configuration.c index 26ee464c..745be5be 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -1,13 +1,8 @@ #include "cconfigspace_internal.h" #include "configuration_internal.h" +#include "configuration_space_internal.h" #include -static inline _ccs_configuration_ops_t * -ccs_configuration_get_ops(ccs_configuration_t configuration) -{ - return (_ccs_configuration_ops_t *)configuration->obj.ops; -} - static ccs_result_t _ccs_configuration_del(ccs_object_t object) { @@ -62,19 +57,19 @@ _ccs_configuration_serialize( } static ccs_result_t -_ccs_configuration_hash(_ccs_configuration_data_t *data, ccs_hash_t *hash_ret) +_ccs_configuration_hash(ccs_configuration_t configuration, ccs_hash_t *hash_ret) { - return _ccs_binding_hash((_ccs_binding_data_t *)data, hash_ret); + return _ccs_binding_hash((ccs_binding_t)configuration, hash_ret); } static ccs_result_t _ccs_configuration_cmp( - _ccs_configuration_data_t *data, - ccs_configuration_t other, - int *cmp_ret) + ccs_configuration_t configuration, + ccs_configuration_t other, + int *cmp_ret) { return _ccs_binding_cmp( - (_ccs_binding_data_t *)data, (ccs_binding_t)other, cmp_ret); + (ccs_binding_t)configuration, (ccs_binding_t)other, cmp_ret); } static _ccs_configuration_ops_t _configuration_ops = { @@ -91,16 +86,11 @@ _ccs_create_configuration( ccs_configuration_t *configuration_ret) { ccs_result_t err; - size_t num_parameters; - CCS_VALIDATE(ccs_configuration_space_get_num_parameters( - configuration_space, &num_parameters)); - CCS_REFUTE( - values && num_parameters != num_values, - CCS_RESULT_ERROR_INVALID_VALUE); - uintptr_t mem = (uintptr_t)calloc( - 1, sizeof(struct _ccs_configuration_s) + - sizeof(struct _ccs_configuration_data_s) + - num_parameters * sizeof(ccs_datum_t)); + size_t num_parameters = configuration_space->data->num_parameters; + uintptr_t mem = (uintptr_t)calloc( + 1, sizeof(struct _ccs_configuration_s) + + sizeof(struct _ccs_configuration_data_s) + + num_parameters * sizeof(ccs_datum_t)); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); CCS_VALIDATE_ERR_GOTO( err, ccs_retain_object(configuration_space), errmem); @@ -123,9 +113,10 @@ _ccs_create_configuration( if (values[i].flags & CCS_DATUM_FLAG_TRANSIENT) CCS_VALIDATE_ERR_GOTO( err, - ccs_configuration_space_validate_value( - configuration_space, i, - values[i], + ccs_context_validate_value( + (ccs_context_t) + configuration_space, + i, values[i], config->data->values + i), errinit); } @@ -148,9 +139,7 @@ ccs_create_configuration( CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); CCS_CHECK_PTR(configuration_ret); CCS_CHECK_ARY(num_values, values); - size_t num_parameters; - CCS_VALIDATE(ccs_configuration_space_get_num_parameters( - configuration_space, &num_parameters)); + size_t num_parameters = configuration_space->data->num_parameters; CCS_REFUTE( num_parameters != num_values, CCS_RESULT_ERROR_INVALID_VALUE); CCS_VALIDATE(_ccs_create_configuration( @@ -170,44 +159,6 @@ ccs_configuration_get_configuration_space( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_configuration_get_value( - ccs_configuration_t configuration, - size_t index, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_CONFIGURATION); - CCS_VALIDATE(_ccs_binding_get_value( - (ccs_binding_t)configuration, index, value_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_configuration_get_values( - ccs_configuration_t configuration, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret) -{ - CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_CONFIGURATION); - CCS_VALIDATE(_ccs_binding_get_values( - (ccs_binding_t)configuration, num_values, values, - num_values_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_configuration_get_value_by_name( - ccs_configuration_t configuration, - const char *name, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_CONFIGURATION); - CCS_VALIDATE(_ccs_binding_get_value_by_name( - (ccs_binding_t)configuration, name, value_ret)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_configuration_check( ccs_configuration_t configuration, @@ -219,28 +170,3 @@ ccs_configuration_check( is_valid_ret)); return CCS_RESULT_SUCCESS; } - -ccs_result_t -ccs_configuration_hash(ccs_configuration_t configuration, ccs_hash_t *hash_ret) -{ - CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_CONFIGURATION); - _ccs_configuration_ops_t *ops = - ccs_configuration_get_ops(configuration); - CCS_VALIDATE(ops->hash(configuration->data, hash_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_configuration_cmp( - ccs_configuration_t configuration, - ccs_configuration_t other_configuration, - int *cmp_ret) -{ - CCS_CHECK_OBJ(configuration, CCS_OBJECT_TYPE_CONFIGURATION); - CCS_CHECK_OBJ(other_configuration, CCS_OBJECT_TYPE_CONFIGURATION); - _ccs_configuration_ops_t *ops = - ccs_configuration_get_ops(configuration); - CCS_VALIDATE( - ops->cmp(configuration->data, other_configuration, cmp_ret)); - return CCS_RESULT_SUCCESS; -} diff --git a/src/configuration_internal.h b/src/configuration_internal.h index 641e0833..4f209b5b 100644 --- a/src/configuration_internal.h +++ b/src/configuration_internal.h @@ -9,12 +9,12 @@ struct _ccs_configuration_ops_s { _ccs_object_ops_t obj_ops; ccs_result_t ( - *hash)(_ccs_configuration_data_t *data, ccs_hash_t *hash_ret); + *hash)(ccs_configuration_t configuration, ccs_hash_t *hash_ret); ccs_result_t (*cmp)( - _ccs_configuration_data_t *data, - ccs_configuration_t other, - int *cmp_ret); + ccs_configuration_t configuration, + ccs_configuration_t other, + int *cmp_ret); }; typedef struct _ccs_configuration_ops_s _ccs_configuration_ops_t; diff --git a/src/configuration_space.c b/src/configuration_space.c index e82c57f4..a9a69a4e 100644 --- a/src/configuration_space.c +++ b/src/configuration_space.c @@ -447,9 +447,9 @@ _recompute_graph(ccs_configuration_space_t configuration_space) errmem); CCS_VALIDATE_ERR_GOTO( err, - ccs_configuration_space_get_parameter_indexes( - configuration_space, count, parents, NULL, - parents_index), + ccs_context_get_parameter_indexes( + (ccs_context_t)configuration_space, count, + parents, NULL, parents_index), errmem); for (size_t i = 0; i < count; i++) { utarray_push_back(pparents[index], parents_index + i); @@ -621,17 +621,6 @@ ccs_create_configuration_space( #undef utarray_oom #define utarray_oom() exit(-1) -ccs_result_t -ccs_configuration_space_get_name( - ccs_configuration_space_t configuration_space, - const char **name_ret) -{ - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); - CCS_VALIDATE(_ccs_context_get_name( - (ccs_context_t)configuration_space, name_ret)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_configuration_space_set_rng( ccs_configuration_space_t configuration_space, @@ -661,109 +650,6 @@ ccs_configuration_space_get_rng( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_configuration_space_get_num_parameters( - ccs_configuration_space_t configuration_space, - size_t *num_parameters_ret) -{ - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); - CCS_VALIDATE(_ccs_context_get_num_parameters( - (ccs_context_t)configuration_space, num_parameters_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_configuration_space_get_parameter( - ccs_configuration_space_t configuration_space, - size_t index, - ccs_parameter_t *parameter_ret) -{ - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); - CCS_VALIDATE(_ccs_context_get_parameter( - (ccs_context_t)configuration_space, index, parameter_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_configuration_space_get_parameter_by_name( - ccs_configuration_space_t configuration_space, - const char *name, - ccs_parameter_t *parameter_ret) -{ - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); - CCS_VALIDATE(_ccs_context_get_parameter_by_name( - (ccs_context_t)configuration_space, name, parameter_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_configuration_space_get_parameter_index_by_name( - ccs_configuration_space_t configuration_space, - const char *name, - size_t *index_ret) -{ - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); - CCS_VALIDATE(_ccs_context_get_parameter_index_by_name( - (ccs_context_t)configuration_space, name, index_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_configuration_space_get_parameter_index( - ccs_configuration_space_t configuration_space, - ccs_parameter_t parameter, - ccs_bool_t *found_ret, - size_t *index_ret) -{ - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); - CCS_VALIDATE(_ccs_context_get_parameter_index( - (ccs_context_t)(configuration_space), parameter, found_ret, - index_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_configuration_space_get_parameter_indexes( - ccs_configuration_space_t configuration_space, - size_t num_parameters, - ccs_parameter_t *parameters, - ccs_bool_t *found, - size_t *indexes) -{ - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); - CCS_VALIDATE(_ccs_context_get_parameter_indexes( - (ccs_context_t)configuration_space, num_parameters, parameters, - found, indexes)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_configuration_space_get_parameters( - ccs_configuration_space_t configuration_space, - size_t num_parameters, - ccs_parameter_t *parameters, - size_t *num_parameters_ret) -{ - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); - CCS_VALIDATE(_ccs_context_get_parameters( - (ccs_context_t)configuration_space, num_parameters, parameters, - num_parameters_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_configuration_space_validate_value( - ccs_configuration_space_t configuration_space, - size_t index, - ccs_datum_t value, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(configuration_space, CCS_OBJECT_TYPE_CONFIGURATION_SPACE); - CCS_VALIDATE(_ccs_context_validate_value( - (ccs_context_t)configuration_space, index, value, value_ret)); - return CCS_RESULT_SUCCESS; -} - static ccs_result_t _set_actives( ccs_configuration_space_t configuration_space, diff --git a/src/context.c b/src/context.c index af03acaf..dbb8d29a 100644 --- a/src/context.c +++ b/src/context.c @@ -50,11 +50,12 @@ ccs_result_t ccs_context_get_parameter_index_by_name( ccs_context_t context, const char *name, + ccs_bool_t *found_ret, size_t *index_ret) { CCS_CHECK_CONTEXT(context); CCS_VALIDATE(_ccs_context_get_parameter_index_by_name( - context, name, index_ret)); + context, name, found_ret, index_ret)); return CCS_RESULT_SUCCESS; } diff --git a/src/context_internal.h b/src/context_internal.h index fd6eea85..a426ece9 100644 --- a/src/context_internal.h +++ b/src/context_internal.h @@ -100,8 +100,7 @@ _ccs_context_get_parameter_by_name( size_t sz_name; sz_name = strlen(name); HASH_FIND(hh_name, context->data->name_hash, name, sz_name, wrapper); - CCS_REFUTE(!wrapper, CCS_RESULT_ERROR_INVALID_NAME); - *parameter_ret = wrapper->parameter; + *parameter_ret = wrapper ? wrapper->parameter : NULL; return CCS_RESULT_SUCCESS; } @@ -109,6 +108,7 @@ static inline ccs_result_t _ccs_context_get_parameter_index_by_name( ccs_context_t context, const char *name, + ccs_bool_t *found_ret, size_t *index_ret) { CCS_CHECK_PTR(name); @@ -117,8 +117,17 @@ _ccs_context_get_parameter_index_by_name( size_t sz_name; sz_name = strlen(name); HASH_FIND(hh_name, context->data->name_hash, name, sz_name, wrapper); - CCS_REFUTE(!wrapper, CCS_RESULT_ERROR_INVALID_NAME); - *index_ret = wrapper->index; + if (!found_ret) { + CCS_REFUTE(!wrapper, CCS_RESULT_ERROR_INVALID_NAME); + *index_ret = wrapper->index; + } else { + if (wrapper) { + *found_ret = CCS_TRUE; + *index_ret = wrapper->index; + } else { + *found_ret = CCS_FALSE; + } + } return CCS_RESULT_SUCCESS; } diff --git a/src/evaluation.c b/src/evaluation.c index ca4b625f..6258c3d5 100644 --- a/src/evaluation.c +++ b/src/evaluation.c @@ -1,14 +1,9 @@ #include "cconfigspace_internal.h" #include "evaluation_internal.h" #include "configuration_internal.h" +#include "objective_space_internal.h" #include -static inline _ccs_evaluation_ops_t * -ccs_evaluation_get_ops(ccs_evaluation_t evaluation) -{ - return (_ccs_evaluation_ops_t *)evaluation->obj.ops; -} - static ccs_result_t _ccs_evaluation_del(ccs_object_t object) { @@ -124,11 +119,12 @@ _ccs_evaluation_serialize( } static ccs_result_t -_ccs_evaluation_hash(_ccs_evaluation_data_t *data, ccs_hash_t *hash_ret) +_ccs_evaluation_hash(ccs_evaluation_t evaluation, ccs_hash_t *hash_ret) { - ccs_hash_t h, ht; - CCS_VALIDATE(_ccs_binding_hash((_ccs_binding_data_t *)data, &h)); - CCS_VALIDATE(ccs_configuration_hash(data->configuration, &ht)); + _ccs_evaluation_data_t *data = evaluation->data; + ccs_hash_t h, ht; + CCS_VALIDATE(_ccs_binding_hash((ccs_binding_t)evaluation, &h)); + CCS_VALIDATE(ccs_binding_hash((ccs_binding_t)data->configuration, &ht)); h = _hash_combine(h, ht); HASH_JEN(&(data->result), sizeof(data->result), ht); h = _hash_combine(h, ht); @@ -138,22 +134,24 @@ _ccs_evaluation_hash(_ccs_evaluation_data_t *data, ccs_hash_t *hash_ret) static ccs_result_t _ccs_evaluation_cmp( - _ccs_evaluation_data_t *data, - ccs_evaluation_t other, - int *cmp_ret) + ccs_evaluation_t evaluation, + ccs_evaluation_t other, + int *cmp_ret) { CCS_VALIDATE(_ccs_binding_cmp( - (_ccs_binding_data_t *)data, (ccs_binding_t)other, cmp_ret)); + (ccs_binding_t)evaluation, (ccs_binding_t)other, cmp_ret)); if (*cmp_ret) return CCS_RESULT_SUCCESS; + _ccs_evaluation_data_t *data = evaluation->data; _ccs_evaluation_data_t *other_data = other->data; *cmp_ret = data->result < other_data->result ? -1 : data->result > other_data->result ? 1 : 0; if (*cmp_ret) return CCS_RESULT_SUCCESS; - CCS_VALIDATE(ccs_configuration_cmp( - data->configuration, other_data->configuration, cmp_ret)); + CCS_VALIDATE(ccs_binding_cmp( + (ccs_binding_t)data->configuration, + (ccs_binding_t)other_data->configuration, cmp_ret)); return CCS_RESULT_SUCCESS; } @@ -177,14 +175,14 @@ ccs_create_evaluation( CCS_CHECK_PTR(evaluation_ret); CCS_CHECK_ARY(num_values, values); ccs_result_t err; - size_t num; - CCS_VALIDATE( - ccs_objective_space_get_num_parameters(objective_space, &num)); - CCS_REFUTE(values && num != num_values, CCS_RESULT_ERROR_INVALID_VALUE); + size_t num_parameters = objective_space->data->num_parameters; + CCS_REFUTE( + values && num_parameters != num_values, + CCS_RESULT_ERROR_INVALID_VALUE); uintptr_t mem = (uintptr_t)calloc( 1, sizeof(struct _ccs_evaluation_s) + sizeof(struct _ccs_evaluation_data_s) + - num * sizeof(ccs_datum_t)); + num_parameters * sizeof(ccs_datum_t)); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(objective_space), errmem); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(configuration), erros); @@ -195,7 +193,7 @@ ccs_create_evaluation( (_ccs_object_ops_t *)&_evaluation_ops); eval->data = (struct _ccs_evaluation_data_s *)(mem + sizeof(struct _ccs_evaluation_s)); - eval->data->num_values = num; + eval->data->num_values = num_parameters; eval->data->objective_space = objective_space; eval->data->configuration = configuration; eval->data->result = result; @@ -203,13 +201,15 @@ ccs_create_evaluation( (ccs_datum_t *)(mem + sizeof(struct _ccs_evaluation_s) + sizeof(struct _ccs_evaluation_data_s)); if (values) { - memcpy(eval->data->values, values, num * sizeof(ccs_datum_t)); + memcpy(eval->data->values, values, + num_parameters * sizeof(ccs_datum_t)); for (size_t i = 0; i < num_values; i++) if (values[i].flags & CCS_DATUM_FLAG_TRANSIENT) CCS_VALIDATE_ERR_GOTO( err, - ccs_objective_space_validate_value( - objective_space, i, values[i], + ccs_context_validate_value( + (ccs_context_t)objective_space, + i, values[i], eval->data->values + i), errc); } @@ -259,43 +259,6 @@ ccs_evaluation_get_result( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_evaluation_get_value( - ccs_evaluation_t evaluation, - size_t index, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); - CCS_VALIDATE(_ccs_binding_get_value( - (ccs_binding_t)evaluation, index, value_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_evaluation_get_values( - ccs_evaluation_t evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); - CCS_VALIDATE(_ccs_binding_get_values( - (ccs_binding_t)evaluation, num_values, values, num_values_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_evaluation_get_value_by_name( - ccs_evaluation_t evaluation, - const char *name, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); - CCS_VALIDATE(_ccs_binding_get_value_by_name( - (ccs_binding_t)evaluation, name, value_ret)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_evaluation_check(ccs_evaluation_t evaluation, ccs_bool_t *is_valid_ret) { @@ -356,33 +319,6 @@ ccs_evaluation_get_objective_values( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_evaluation_hash(ccs_evaluation_t evaluation, ccs_hash_t *hash_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); - _ccs_evaluation_ops_t *ops = ccs_evaluation_get_ops(evaluation); - CCS_VALIDATE(ops->hash(evaluation->data, hash_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_evaluation_cmp( - ccs_evaluation_t evaluation, - ccs_evaluation_t other_evaluation, - int *cmp_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_EVALUATION); - CCS_CHECK_OBJ(other_evaluation, CCS_OBJECT_TYPE_EVALUATION); - CCS_CHECK_PTR(cmp_ret); - if (evaluation == other_evaluation) { - *cmp_ret = 0; - return CCS_RESULT_SUCCESS; - } - _ccs_evaluation_ops_t *ops = ccs_evaluation_get_ops(evaluation); - CCS_VALIDATE(ops->cmp(evaluation->data, other_evaluation, cmp_ret)); - return CCS_RESULT_SUCCESS; -} - static inline int _numeric_compare(const ccs_datum_t *a, const ccs_datum_t *b) { diff --git a/src/evaluation_internal.h b/src/evaluation_internal.h index 78782879..8072a204 100644 --- a/src/evaluation_internal.h +++ b/src/evaluation_internal.h @@ -8,12 +8,12 @@ typedef struct _ccs_evaluation_data_s _ccs_evaluation_data_t; struct _ccs_evaluation_ops_s { _ccs_object_ops_t obj_ops; - ccs_result_t (*hash)(_ccs_evaluation_data_t *data, ccs_hash_t *hash_ret); + ccs_result_t (*hash)(ccs_evaluation_t evaluation, ccs_hash_t *hash_ret); ccs_result_t (*cmp)( - _ccs_evaluation_data_t *data, - ccs_evaluation_t other, - int *cmp_ret); + ccs_evaluation_t evaluation, + ccs_evaluation_t other, + int *cmp_ret); }; typedef struct _ccs_evaluation_ops_s _ccs_evaluation_ops_t; @@ -26,8 +26,8 @@ struct _ccs_evaluation_data_s { ccs_objective_space_t objective_space; size_t num_values; ccs_datum_t *values; - ccs_configuration_t configuration; ccs_evaluation_result_t result; + ccs_configuration_t configuration; }; #endif //_EVALUATION_INTERNAL_H diff --git a/src/features.c b/src/features.c index 71502084..58579477 100644 --- a/src/features.c +++ b/src/features.c @@ -1,14 +1,9 @@ #include "cconfigspace_internal.h" #include "features_internal.h" +#include "features_space_internal.h" #include "datum_hash.h" #include -static inline _ccs_features_ops_t * -ccs_features_get_ops(ccs_features_t features) -{ - return (_ccs_features_ops_t *)features->obj.ops; -} - static ccs_result_t _ccs_features_del(ccs_object_t object) { @@ -63,17 +58,17 @@ _ccs_features_serialize( } static ccs_result_t -_ccs_features_hash(_ccs_features_data_t *data, ccs_hash_t *hash_ret) +_ccs_features_hash(ccs_features_t features, ccs_hash_t *hash_ret) { - CCS_VALIDATE(_ccs_binding_hash((_ccs_binding_data_t *)data, hash_ret)); + CCS_VALIDATE(_ccs_binding_hash((ccs_binding_t)features, hash_ret)); return CCS_RESULT_SUCCESS; } static ccs_result_t -_ccs_features_cmp(_ccs_features_data_t *data, ccs_features_t other, int *cmp_ret) +_ccs_features_cmp(ccs_features_t features, ccs_features_t other, int *cmp_ret) { CCS_VALIDATE(_ccs_binding_cmp( - (_ccs_binding_data_t *)data, (ccs_binding_t)other, cmp_ret)); + (ccs_binding_t)features, (ccs_binding_t)other, cmp_ret)); return CCS_RESULT_SUCCESS; } @@ -94,9 +89,7 @@ ccs_create_features( CCS_CHECK_PTR(features_ret); CCS_CHECK_ARY(num_values, values); ccs_result_t err; - size_t num_parameters; - CCS_VALIDATE(ccs_features_space_get_num_parameters( - features_space, &num_parameters)); + size_t num_parameters = features_space->data->num_parameters; CCS_REFUTE( values && num_parameters != num_values, CCS_RESULT_ERROR_INVALID_VALUE); @@ -125,8 +118,9 @@ ccs_create_features( if (values[i].flags & CCS_DATUM_FLAG_TRANSIENT) CCS_VALIDATE_ERR_GOTO( err, - ccs_features_space_validate_value( - features_space, i, values[i], + ccs_context_validate_value( + (ccs_context_t)features_space, + i, values[i], feat->data->values + i), errfs); } @@ -151,43 +145,6 @@ ccs_features_get_features_space( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_features_get_value( - ccs_features_t features, - size_t index, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); - CCS_VALIDATE(_ccs_binding_get_value( - (ccs_binding_t)features, index, value_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_get_values( - ccs_features_t features, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret) -{ - CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); - CCS_VALIDATE(_ccs_binding_get_values( - (ccs_binding_t)features, num_values, values, num_values_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_get_value_by_name( - ccs_features_t features, - const char *name, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); - CCS_VALIDATE(_ccs_binding_get_value_by_name( - (ccs_binding_t)features, name, value_ret)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_features_check(ccs_features_t features, ccs_bool_t *is_valid_ret) { @@ -196,25 +153,3 @@ ccs_features_check(ccs_features_t features, ccs_bool_t *is_valid_ret) features->data->features_space, features, is_valid_ret)); return CCS_RESULT_SUCCESS; } - -ccs_result_t -ccs_features_hash(ccs_features_t features, ccs_hash_t *hash_ret) -{ - CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); - _ccs_features_ops_t *ops = ccs_features_get_ops(features); - CCS_VALIDATE(ops->hash(features->data, hash_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_cmp( - ccs_features_t features, - ccs_features_t other_features, - int *cmp_ret) -{ - CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); - CCS_CHECK_OBJ(other_features, CCS_OBJECT_TYPE_FEATURES); - _ccs_features_ops_t *ops = ccs_features_get_ops(features); - CCS_VALIDATE(ops->cmp(features->data, other_features, cmp_ret)); - return CCS_RESULT_SUCCESS; -} diff --git a/src/features_evaluation.c b/src/features_evaluation.c index 66413b10..6a8cb9c0 100644 --- a/src/features_evaluation.c +++ b/src/features_evaluation.c @@ -2,14 +2,9 @@ #include "features_evaluation_internal.h" #include "configuration_internal.h" #include "features_internal.h" +#include "objective_space_internal.h" #include -static inline _ccs_features_evaluation_ops_t * -ccs_features_evaluation_get_ops(ccs_features_evaluation_t evaluation) -{ - return (_ccs_features_evaluation_ops_t *)evaluation->obj.ops; -} - static ccs_result_t _ccs_features_evaluation_del(ccs_object_t object) { @@ -135,14 +130,15 @@ _ccs_features_evaluation_serialize( static ccs_result_t _ccs_features_evaluation_hash( - _ccs_features_evaluation_data_t *data, - ccs_hash_t *hash_ret) + ccs_features_evaluation_t features_evaluation, + ccs_hash_t *hash_ret) { - ccs_hash_t h, ht; - CCS_VALIDATE(_ccs_binding_hash((_ccs_binding_data_t *)data, &h)); - CCS_VALIDATE(ccs_configuration_hash(data->configuration, &ht)); + _ccs_features_evaluation_data_t *data = features_evaluation->data; + ccs_hash_t h, ht; + CCS_VALIDATE(_ccs_binding_hash((ccs_binding_t)features_evaluation, &h)); + CCS_VALIDATE(ccs_binding_hash((ccs_binding_t)data->configuration, &ht)); h = _hash_combine(h, ht); - CCS_VALIDATE(ccs_features_hash(data->features, &ht)); + CCS_VALIDATE(ccs_binding_hash((ccs_binding_t)data->features, &ht)); h = _hash_combine(h, ht); HASH_JEN(&(data->result), sizeof(data->result), ht); h = _hash_combine(h, ht); @@ -152,26 +148,30 @@ _ccs_features_evaluation_hash( static ccs_result_t _ccs_features_evaluation_cmp( - _ccs_features_evaluation_data_t *data, - ccs_features_evaluation_t other, - int *cmp_ret) + ccs_features_evaluation_t features_evaluation, + ccs_features_evaluation_t other, + int *cmp_ret) { CCS_VALIDATE(_ccs_binding_cmp( - (_ccs_binding_data_t *)data, (ccs_binding_t)other, cmp_ret)); + (ccs_binding_t)features_evaluation, (ccs_binding_t)other, + cmp_ret)); if (*cmp_ret) return CCS_RESULT_SUCCESS; + _ccs_features_evaluation_data_t *data = features_evaluation->data; _ccs_features_evaluation_data_t *other_data = other->data; *cmp_ret = data->result < other_data->result ? -1 : data->result > other_data->result ? 1 : 0; if (*cmp_ret) return CCS_RESULT_SUCCESS; - CCS_VALIDATE(ccs_configuration_cmp( - data->configuration, other_data->configuration, cmp_ret)); + CCS_VALIDATE(ccs_binding_cmp( + (ccs_binding_t)data->configuration, + (ccs_binding_t)other_data->configuration, cmp_ret)); if (*cmp_ret) return CCS_RESULT_SUCCESS; - CCS_VALIDATE(ccs_features_cmp( - data->features, other_data->features, cmp_ret)); + CCS_VALIDATE(ccs_binding_cmp( + (ccs_binding_t)data->features, + (ccs_binding_t)other_data->features, cmp_ret)); return CCS_RESULT_SUCCESS; } @@ -197,14 +197,14 @@ ccs_create_features_evaluation( CCS_CHECK_OBJ(features, CCS_OBJECT_TYPE_FEATURES); CCS_CHECK_PTR(evaluation_ret); CCS_CHECK_ARY(num_values, values); - size_t num; - CCS_VALIDATE( - ccs_objective_space_get_num_parameters(objective_space, &num)); - CCS_REFUTE(values && num != num_values, CCS_RESULT_ERROR_INVALID_VALUE); + size_t num_parameters = objective_space->data->num_parameters; + CCS_REFUTE( + values && num_parameters != num_values, + CCS_RESULT_ERROR_INVALID_VALUE); uintptr_t mem = (uintptr_t)calloc( 1, sizeof(struct _ccs_features_evaluation_s) + sizeof(struct _ccs_features_evaluation_data_s) + - num * sizeof(ccs_datum_t)); + num_parameters * sizeof(ccs_datum_t)); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); ccs_result_t err; CCS_VALIDATE_ERR_GOTO( @@ -220,7 +220,7 @@ ccs_create_features_evaluation( eval->data = (struct _ccs_features_evaluation_data_s *)(mem + sizeof(struct _ccs_features_evaluation_s)); - eval->data->num_values = num; + eval->data->num_values = num_parameters; eval->data->objective_space = objective_space; eval->data->configuration = configuration; eval->data->features = features; @@ -229,13 +229,15 @@ ccs_create_features_evaluation( (ccs_datum_t *)(mem + sizeof(struct _ccs_features_evaluation_s) + sizeof(struct _ccs_features_evaluation_data_s)); if (values) { - memcpy(eval->data->values, values, num * sizeof(ccs_datum_t)); + memcpy(eval->data->values, values, + num_parameters * sizeof(ccs_datum_t)); for (size_t i = 0; i < num_values; i++) { if (values[i].flags & CCS_DATUM_FLAG_TRANSIENT) { CCS_VALIDATE_ERR_GOTO( err, - ccs_objective_space_validate_value( - objective_space, i, values[i], + ccs_context_validate_value( + (ccs_context_t)objective_space, + i, values[i], eval->data->values + i), errfeat); } @@ -300,43 +302,6 @@ ccs_features_evaluation_get_result( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_features_evaluation_get_value( - ccs_features_evaluation_t evaluation, - size_t index, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_VALIDATE(_ccs_binding_get_value( - (ccs_binding_t)evaluation, index, value_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_evaluation_get_values( - ccs_features_evaluation_t evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_VALIDATE(_ccs_binding_get_values( - (ccs_binding_t)evaluation, num_values, values, num_values_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_evaluation_get_value_by_name( - ccs_features_evaluation_t evaluation, - const char *name, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_VALIDATE(_ccs_binding_get_value_by_name( - (ccs_binding_t)evaluation, name, value_ret)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_features_evaluation_check( ccs_features_evaluation_t evaluation, @@ -414,37 +379,6 @@ _numeric_compare(const ccs_datum_t *a, const ccs_datum_t *b) } } -ccs_result_t -ccs_features_evaluation_hash( - ccs_features_evaluation_t evaluation, - ccs_hash_t *hash_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - _ccs_features_evaluation_ops_t *ops = - ccs_features_evaluation_get_ops(evaluation); - CCS_VALIDATE(ops->hash(evaluation->data, hash_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_evaluation_cmp( - ccs_features_evaluation_t evaluation, - ccs_features_evaluation_t other_evaluation, - int *cmp_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_CHECK_OBJ(other_evaluation, CCS_OBJECT_TYPE_FEATURES_EVALUATION); - CCS_CHECK_PTR(cmp_ret); - if (evaluation == other_evaluation) { - *cmp_ret = 0; - return CCS_RESULT_SUCCESS; - } - _ccs_features_evaluation_ops_t *ops = - ccs_features_evaluation_get_ops(evaluation); - CCS_VALIDATE(ops->cmp(evaluation->data, other_evaluation, cmp_ret)); - return CCS_RESULT_SUCCESS; -} - // Could be using memoization here. ccs_result_t ccs_features_evaluation_compare( @@ -470,9 +404,9 @@ ccs_features_evaluation_compare( int eql; CCS_VALIDATE(ccs_objective_space_get_objectives( evaluation->data->objective_space, 0, NULL, NULL, &count)); - CCS_VALIDATE(ccs_features_cmp( - evaluation->data->features, other_evaluation->data->features, - &eql)); + CCS_VALIDATE(ccs_binding_cmp( + (ccs_binding_t)evaluation->data->features, + (ccs_binding_t)other_evaluation->data->features, &eql)); if (0 != eql) { *result_ret = CCS_COMPARISON_NOT_COMPARABLE; return CCS_RESULT_SUCCESS; diff --git a/src/features_evaluation_internal.h b/src/features_evaluation_internal.h index f90f2873..4a9106c1 100644 --- a/src/features_evaluation_internal.h +++ b/src/features_evaluation_internal.h @@ -9,13 +9,13 @@ struct _ccs_features_evaluation_ops_s { _ccs_object_ops_t obj_ops; ccs_result_t (*hash)( - _ccs_features_evaluation_data_t *data, - ccs_hash_t *hash_ret); + ccs_features_evaluation_t features_evaluation, + ccs_hash_t *hash_ret); ccs_result_t (*cmp)( - _ccs_features_evaluation_data_t *data, - ccs_features_evaluation_t other, - int *cmp_ret); + ccs_features_evaluation_t features_evaluation, + ccs_features_evaluation_t other, + int *cmp_ret); }; typedef struct _ccs_features_evaluation_ops_s _ccs_features_evaluation_ops_t; @@ -28,8 +28,8 @@ struct _ccs_features_evaluation_data_s { ccs_objective_space_t objective_space; size_t num_values; ccs_datum_t *values; - ccs_configuration_t configuration; ccs_evaluation_result_t result; + ccs_configuration_t configuration; ccs_features_t features; }; diff --git a/src/features_internal.h b/src/features_internal.h index 8b5dbf99..1ea73122 100644 --- a/src/features_internal.h +++ b/src/features_internal.h @@ -8,12 +8,12 @@ typedef struct _ccs_features_data_s _ccs_features_data_t; struct _ccs_features_ops_s { _ccs_object_ops_t obj_ops; - ccs_result_t (*hash)(_ccs_features_data_t *data, ccs_hash_t *hash_ret); + ccs_result_t (*hash)(ccs_features_t features, ccs_hash_t *hash_ret); ccs_result_t (*cmp)( - _ccs_features_data_t *data, - ccs_features_t other, - int *cmp_ret); + ccs_features_t features, + ccs_features_t other, + int *cmp_ret); }; typedef struct _ccs_features_ops_s _ccs_features_ops_t; diff --git a/src/features_space.c b/src/features_space.c index 65372de0..0eb695cd 100644 --- a/src/features_space.c +++ b/src/features_space.c @@ -132,121 +132,6 @@ ccs_create_features_space( return err; } -ccs_result_t -ccs_features_space_get_name( - ccs_features_space_t features_space, - const char **name_ret) -{ - CCS_CHECK_OBJ(features_space, CCS_OBJECT_TYPE_FEATURES_SPACE); - CCS_VALIDATE( - _ccs_context_get_name((ccs_context_t)features_space, name_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_space_get_num_parameters( - ccs_features_space_t features_space, - size_t *num_parameters_ret) -{ - CCS_CHECK_OBJ(features_space, CCS_OBJECT_TYPE_FEATURES_SPACE); - CCS_VALIDATE(_ccs_context_get_num_parameters( - (ccs_context_t)features_space, num_parameters_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_space_get_parameter( - ccs_features_space_t features_space, - size_t index, - ccs_parameter_t *parameter_ret) -{ - CCS_CHECK_OBJ(features_space, CCS_OBJECT_TYPE_FEATURES_SPACE); - CCS_VALIDATE(_ccs_context_get_parameter( - (ccs_context_t)features_space, index, parameter_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_space_get_parameter_by_name( - ccs_features_space_t features_space, - const char *name, - ccs_parameter_t *parameter_ret) -{ - CCS_CHECK_OBJ(features_space, CCS_OBJECT_TYPE_FEATURES_SPACE); - CCS_VALIDATE(_ccs_context_get_parameter_by_name( - (ccs_context_t)features_space, name, parameter_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_space_get_parameter_index_by_name( - ccs_features_space_t features_space, - const char *name, - size_t *index_ret) -{ - CCS_CHECK_OBJ(features_space, CCS_OBJECT_TYPE_FEATURES_SPACE); - CCS_VALIDATE(_ccs_context_get_parameter_index_by_name( - (ccs_context_t)features_space, name, index_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_space_get_parameter_index( - ccs_features_space_t features_space, - ccs_parameter_t parameter, - ccs_bool_t *found_ret, - size_t *index_ret) -{ - CCS_CHECK_OBJ(features_space, CCS_OBJECT_TYPE_FEATURES_SPACE); - CCS_CHECK_OBJ(parameter, CCS_OBJECT_TYPE_PARAMETER); - CCS_VALIDATE(_ccs_context_get_parameter_index( - (ccs_context_t)(features_space), parameter, found_ret, - index_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_space_get_parameter_indexes( - ccs_features_space_t features_space, - size_t num_parameters, - ccs_parameter_t *parameters, - ccs_bool_t *found, - size_t *indexes) -{ - CCS_CHECK_OBJ(features_space, CCS_OBJECT_TYPE_FEATURES_SPACE); - CCS_VALIDATE(_ccs_context_get_parameter_indexes( - (ccs_context_t)features_space, num_parameters, parameters, - found, indexes)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_space_get_parameters( - ccs_features_space_t features_space, - size_t num_parameters, - ccs_parameter_t *parameters, - size_t *num_parameters_ret) -{ - CCS_CHECK_OBJ(features_space, CCS_OBJECT_TYPE_FEATURES_SPACE); - CCS_VALIDATE(_ccs_context_get_parameters( - (ccs_context_t)features_space, num_parameters, parameters, - num_parameters_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_features_space_validate_value( - ccs_features_space_t features_space, - size_t index, - ccs_datum_t value, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(features_space, CCS_OBJECT_TYPE_FEATURES_SPACE); - CCS_VALIDATE(_ccs_context_validate_value( - (ccs_context_t)features_space, index, value, value_ret)); - return CCS_RESULT_SUCCESS; -} - static inline ccs_result_t _check_features( ccs_features_space_t features_space, diff --git a/src/features_tuner_random.c b/src/features_tuner_random.c index 20db9c4b..544dc862 100644 --- a/src/features_tuner_random.c +++ b/src/features_tuner_random.c @@ -287,7 +287,9 @@ _ccs_features_tuner_random_get_optima( d->optima, eval))) { CCS_VALIDATE(ccs_features_evaluation_get_features( *eval, &feat)); - CCS_VALIDATE(ccs_features_cmp(features, feat, &cmp)); + CCS_VALIDATE(ccs_binding_cmp( + (ccs_binding_t)features, (ccs_binding_t)feat, + &cmp)); if (cmp == 0) num_optima += 1; } @@ -301,8 +303,9 @@ _ccs_features_tuner_random_get_optima( CCS_VALIDATE( ccs_features_evaluation_get_features( *eval, &feat)); - CCS_VALIDATE( - ccs_features_cmp(features, feat, &cmp)); + CCS_VALIDATE(ccs_binding_cmp( + (ccs_binding_t)features, + (ccs_binding_t)feat, &cmp)); if (cmp == 0) evaluations[index++] = *eval; } @@ -349,7 +352,9 @@ _ccs_features_tuner_random_get_history( d->history, eval))) { CCS_VALIDATE(ccs_features_evaluation_get_features( *eval, &feat)); - CCS_VALIDATE(ccs_features_cmp(features, feat, &cmp)); + CCS_VALIDATE(ccs_binding_cmp( + (ccs_binding_t)features, (ccs_binding_t)feat, + &cmp)); if (cmp == 0) size_history += 1; } @@ -363,8 +368,9 @@ _ccs_features_tuner_random_get_history( CCS_VALIDATE( ccs_features_evaluation_get_features( *eval, &feat)); - CCS_VALIDATE( - ccs_features_cmp(features, feat, &cmp)); + CCS_VALIDATE(ccs_binding_cmp( + (ccs_binding_t)features, + (ccs_binding_t)feat, &cmp)); if (cmp == 0) evaluations[index++] = *eval; } @@ -393,7 +399,8 @@ _ccs_features_tuner_random_suggest( d->optima, eval))) { CCS_VALIDATE( ccs_features_evaluation_get_features(*eval, &feat)); - CCS_VALIDATE(ccs_features_cmp(features, feat, &cmp)); + CCS_VALIDATE(ccs_binding_cmp( + (ccs_binding_t)features, (ccs_binding_t)feat, &cmp)); if (cmp == 0) count += 1; } @@ -408,7 +415,9 @@ _ccs_features_tuner_random_suggest( d->optima, eval))) { CCS_VALIDATE(ccs_features_evaluation_get_features( *eval, &feat)); - CCS_VALIDATE(ccs_features_cmp(features, feat, &cmp)); + CCS_VALIDATE(ccs_binding_cmp( + (ccs_binding_t)features, (ccs_binding_t)feat, + &cmp)); if (cmp == 0) { if (indx == 0) break; diff --git a/src/objective_space.c b/src/objective_space.c index 22697d13..1ce0be72 100644 --- a/src/objective_space.c +++ b/src/objective_space.c @@ -270,108 +270,6 @@ ccs_create_objective_space( return err; } -ccs_result_t -ccs_objective_space_get_name( - ccs_objective_space_t objective_space, - const char **name_ret) -{ - CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_VALIDATE(_ccs_context_get_name( - (ccs_context_t)objective_space, name_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_objective_space_get_num_parameters( - ccs_objective_space_t objective_space, - size_t *num_parameters_ret) -{ - CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_VALIDATE(_ccs_context_get_num_parameters( - (ccs_context_t)objective_space, num_parameters_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_objective_space_get_parameter( - ccs_objective_space_t objective_space, - size_t index, - ccs_parameter_t *parameter_ret) -{ - CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_VALIDATE(_ccs_context_get_parameter( - (ccs_context_t)objective_space, index, parameter_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_objective_space_get_parameter_by_name( - ccs_objective_space_t objective_space, - const char *name, - ccs_parameter_t *parameter_ret) -{ - CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_VALIDATE(_ccs_context_get_parameter_by_name( - (ccs_context_t)objective_space, name, parameter_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_objective_space_get_parameter_index_by_name( - ccs_objective_space_t objective_space, - const char *name, - size_t *index_ret) -{ - CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_VALIDATE(_ccs_context_get_parameter_index_by_name( - (ccs_context_t)objective_space, name, index_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_objective_space_get_parameter_index( - ccs_objective_space_t objective_space, - ccs_parameter_t parameter, - ccs_bool_t *found_ret, - size_t *index_ret) -{ - CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_CHECK_OBJ(parameter, CCS_OBJECT_TYPE_PARAMETER); - CCS_VALIDATE(_ccs_context_get_parameter_index( - (ccs_context_t)(objective_space), parameter, found_ret, - index_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_objective_space_get_parameter_indexes( - ccs_objective_space_t objective_space, - size_t num_parameters, - ccs_parameter_t *parameters, - ccs_bool_t *found, - size_t *indexes) -{ - CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_VALIDATE(_ccs_context_get_parameter_indexes( - (ccs_context_t)objective_space, num_parameters, parameters, - found, indexes)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_objective_space_get_parameters( - ccs_objective_space_t objective_space, - size_t num_parameters, - ccs_parameter_t *parameters, - size_t *num_parameters_ret) -{ - CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_VALIDATE(_ccs_context_get_parameters( - (ccs_context_t)objective_space, num_parameters, parameters, - num_parameters_ret)); - return CCS_RESULT_SUCCESS; -} - static inline ccs_result_t _check_evaluation( ccs_objective_space_t objective_space, @@ -408,19 +306,6 @@ ccs_objective_space_check_evaluation( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_objective_space_validate_value( - ccs_objective_space_t objective_space, - size_t index, - ccs_datum_t value, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(objective_space, CCS_OBJECT_TYPE_OBJECTIVE_SPACE); - CCS_VALIDATE(_ccs_context_validate_value( - (ccs_context_t)objective_space, index, value, value_ret)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_objective_space_get_objective( ccs_objective_space_t objective_space, diff --git a/src/tree_evaluation.c b/src/tree_evaluation.c index 17215901..b9a392ed 100644 --- a/src/tree_evaluation.c +++ b/src/tree_evaluation.c @@ -1,14 +1,9 @@ #include "cconfigspace_internal.h" #include "tree_evaluation_internal.h" #include "tree_configuration_internal.h" +#include "objective_space_internal.h" #include -static inline _ccs_tree_evaluation_ops_t * -ccs_tree_evaluation_get_ops(ccs_tree_evaluation_t evaluation) -{ - return (_ccs_tree_evaluation_ops_t *)evaluation->obj.ops; -} - static ccs_result_t _ccs_tree_evaluation_del(ccs_object_t object) { @@ -126,11 +121,12 @@ _ccs_tree_evaluation_serialize( static ccs_result_t _ccs_tree_evaluation_hash( - _ccs_tree_evaluation_data_t *data, - ccs_hash_t *hash_ret) + ccs_tree_evaluation_t tree_evaluation, + ccs_hash_t *hash_ret) { - ccs_hash_t h, ht; - CCS_VALIDATE(_ccs_binding_hash((_ccs_binding_data_t *)data, &h)); + _ccs_tree_evaluation_data_t *data = tree_evaluation->data; + ccs_hash_t h, ht; + CCS_VALIDATE(_ccs_binding_hash((ccs_binding_t)tree_evaluation, &h)); CCS_VALIDATE(ccs_tree_configuration_hash(data->configuration, &ht)); h = _hash_combine(h, ht); HASH_JEN(&(data->result), sizeof(data->result), ht); @@ -141,14 +137,15 @@ _ccs_tree_evaluation_hash( static ccs_result_t _ccs_tree_evaluation_cmp( - _ccs_tree_evaluation_data_t *data, - ccs_tree_evaluation_t other, - int *cmp_ret) + ccs_tree_evaluation_t tree_evaluation, + ccs_tree_evaluation_t other, + int *cmp_ret) { CCS_VALIDATE(_ccs_binding_cmp( - (_ccs_binding_data_t *)data, (ccs_binding_t)other, cmp_ret)); + (ccs_binding_t)tree_evaluation, (ccs_binding_t)other, cmp_ret)); if (*cmp_ret) return CCS_RESULT_SUCCESS; + _ccs_tree_evaluation_data_t *data = tree_evaluation->data; _ccs_tree_evaluation_data_t *other_data = other->data; *cmp_ret = data->result < other_data->result ? -1 : data->result > other_data->result ? 1 : @@ -180,14 +177,14 @@ ccs_create_tree_evaluation( CCS_CHECK_PTR(evaluation_ret); CCS_CHECK_ARY(num_values, values); ccs_result_t err; - size_t num; - CCS_VALIDATE( - ccs_objective_space_get_num_parameters(objective_space, &num)); - CCS_REFUTE(values && num != num_values, CCS_RESULT_ERROR_INVALID_VALUE); + size_t num_parameters = objective_space->data->num_parameters; + CCS_REFUTE( + values && num_parameters != num_values, + CCS_RESULT_ERROR_INVALID_VALUE); uintptr_t mem = (uintptr_t)calloc( 1, sizeof(struct _ccs_tree_evaluation_s) + sizeof(struct _ccs_tree_evaluation_data_s) + - num * sizeof(ccs_datum_t)); + num_parameters * sizeof(ccs_datum_t)); CCS_REFUTE(!mem, CCS_RESULT_ERROR_OUT_OF_MEMORY); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(objective_space), errmem); CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(configuration), erros); @@ -198,7 +195,7 @@ ccs_create_tree_evaluation( (_ccs_object_ops_t *)&_evaluation_ops); eval->data = (struct _ccs_tree_evaluation_data_s *)(mem + sizeof(struct _ccs_tree_evaluation_s)); - eval->data->num_values = num; + eval->data->num_values = num_parameters; eval->data->objective_space = objective_space; eval->data->configuration = configuration; eval->data->result = result; @@ -206,13 +203,15 @@ ccs_create_tree_evaluation( (ccs_datum_t *)(mem + sizeof(struct _ccs_tree_evaluation_s) + sizeof(struct _ccs_tree_evaluation_data_s)); if (values) { - memcpy(eval->data->values, values, num * sizeof(ccs_datum_t)); + memcpy(eval->data->values, values, + num_parameters * sizeof(ccs_datum_t)); for (size_t i = 0; i < num_values; i++) if (values[i].flags & CCS_DATUM_FLAG_TRANSIENT) CCS_VALIDATE_ERR_GOTO( err, - ccs_objective_space_validate_value( - objective_space, i, values[i], + ccs_context_validate_value( + (ccs_context_t)objective_space, + i, values[i], eval->data->values + i), errc); } @@ -262,43 +261,6 @@ ccs_tree_evaluation_get_result( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_tree_evaluation_get_value( - ccs_tree_evaluation_t evaluation, - size_t index, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_VALIDATE(_ccs_binding_get_value( - (ccs_binding_t)evaluation, index, value_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_evaluation_get_values( - ccs_tree_evaluation_t evaluation, - size_t num_values, - ccs_datum_t *values, - size_t *num_values_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_VALIDATE(_ccs_binding_get_values( - (ccs_binding_t)evaluation, num_values, values, num_values_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_evaluation_get_value_by_name( - ccs_tree_evaluation_t evaluation, - const char *name, - ccs_datum_t *value_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_VALIDATE(_ccs_binding_get_value_by_name( - (ccs_binding_t)evaluation, name, value_ret)); - return CCS_RESULT_SUCCESS; -} - ccs_result_t ccs_tree_evaluation_check( ccs_tree_evaluation_t evaluation, @@ -362,35 +324,6 @@ ccs_tree_evaluation_get_objective_values( return CCS_RESULT_SUCCESS; } -ccs_result_t -ccs_tree_evaluation_hash(ccs_tree_evaluation_t evaluation, ccs_hash_t *hash_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - _ccs_tree_evaluation_ops_t *ops = - ccs_tree_evaluation_get_ops(evaluation); - CCS_VALIDATE(ops->hash(evaluation->data, hash_ret)); - return CCS_RESULT_SUCCESS; -} - -ccs_result_t -ccs_tree_evaluation_cmp( - ccs_tree_evaluation_t evaluation, - ccs_tree_evaluation_t other_evaluation, - int *cmp_ret) -{ - CCS_CHECK_OBJ(evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_CHECK_OBJ(other_evaluation, CCS_OBJECT_TYPE_TREE_EVALUATION); - CCS_CHECK_PTR(cmp_ret); - if (evaluation == other_evaluation) { - *cmp_ret = 0; - return CCS_RESULT_SUCCESS; - } - _ccs_tree_evaluation_ops_t *ops = - ccs_tree_evaluation_get_ops(evaluation); - CCS_VALIDATE(ops->cmp(evaluation->data, other_evaluation, cmp_ret)); - return CCS_RESULT_SUCCESS; -} - static inline int _numeric_compare(const ccs_datum_t *a, const ccs_datum_t *b) { diff --git a/src/tree_evaluation_internal.h b/src/tree_evaluation_internal.h index 90794753..9c6cf8ab 100644 --- a/src/tree_evaluation_internal.h +++ b/src/tree_evaluation_internal.h @@ -8,13 +8,14 @@ typedef struct _ccs_tree_evaluation_data_s _ccs_tree_evaluation_data_t; struct _ccs_tree_evaluation_ops_s { _ccs_object_ops_t obj_ops; - ccs_result_t ( - *hash)(_ccs_tree_evaluation_data_t *data, ccs_hash_t *hash_ret); + ccs_result_t (*hash)( + ccs_tree_evaluation_t tree_evaluation, + ccs_hash_t *hash_ret); ccs_result_t (*cmp)( - _ccs_tree_evaluation_data_t *data, - ccs_tree_evaluation_t other, - int *cmp_ret); + ccs_tree_evaluation_t tree_evaluation, + ccs_tree_evaluation_t other, + int *cmp_ret); }; typedef struct _ccs_tree_evaluation_ops_s _ccs_tree_evaluation_ops_t; @@ -27,8 +28,8 @@ struct _ccs_tree_evaluation_data_s { ccs_objective_space_t objective_space; size_t num_values; ccs_datum_t *values; - ccs_tree_configuration_t configuration; ccs_evaluation_result_t result; + ccs_tree_configuration_t configuration; }; #endif //_TREE_EVALUATION_INTERNAL_H diff --git a/tests/test_condition.c b/tests/test_condition.c index 40a62fe6..b07d273c 100644 --- a/tests/test_condition.c +++ b/tests/test_condition.c @@ -45,8 +45,8 @@ test_simple(void) err = ccs_configuration_space_sample( space, NULL, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_get_values( - configuration, 2, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configuration, 2, values, NULL); assert(err == CCS_RESULT_SUCCESS); assert(values[0].type == CCS_DATA_TYPE_FLOAT); f = values[0].value.f; @@ -70,8 +70,8 @@ test_simple(void) for (int i = 0; i < 100; i++) { ccs_float_t f; ccs_bool_t check; - err = ccs_configuration_get_values( - configurations[i], 2, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configurations[i], 2, values, NULL); assert(err == CCS_RESULT_SUCCESS); assert(values[0].type == CCS_DATA_TYPE_FLOAT); f = values[0].value.f; @@ -137,8 +137,8 @@ test_transitive(void) err = ccs_configuration_space_sample( space, NULL, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_get_values( - configuration, 3, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configuration, 3, values, NULL); assert(err == CCS_RESULT_SUCCESS); assert(values[1].type == CCS_DATA_TYPE_FLOAT); f = values[1].value.f; @@ -173,8 +173,8 @@ test_transitive(void) for (int i = 0; i < 100; i++) { ccs_float_t f; ccs_bool_t check; - err = ccs_configuration_get_values( - configurations[i], 3, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configurations[i], 3, values, NULL); assert(err == CCS_RESULT_SUCCESS); assert(values[1].type == CCS_DATA_TYPE_FLOAT); f = values[1].value.f; diff --git a/tests/test_configuration_space.c b/tests/test_configuration_space.c index 8445fbe9..89ac7c5a 100644 --- a/tests/test_configuration_space.c +++ b/tests/test_configuration_space.c @@ -36,23 +36,25 @@ check_configuration( const char *name; ccs_bool_t check; - err = ccs_configuration_space_get_num_parameters( - configuration_space, &sz_ret); + err = ccs_context_get_num_parameters( + (ccs_context_t)configuration_space, &sz_ret); assert(err == CCS_RESULT_SUCCESS); assert(sz_ret == sz); for (size_t i = 0; i < sz; i++) { - err = ccs_configuration_space_get_parameter( - configuration_space, i, ¶meter); + err = ccs_context_get_parameter( + (ccs_context_t)configuration_space, i, ¶meter); assert(err == CCS_RESULT_SUCCESS); assert(parameter == parameters[i]); - err = ccs_configuration_space_get_parameter_index( - configuration_space, parameter, NULL, &index); + err = ccs_context_get_parameter_index( + (ccs_context_t)configuration_space, parameter, NULL, + &index); assert(err == CCS_RESULT_SUCCESS); assert(index == i); } - err = ccs_configuration_space_get_parameters( - configuration_space, sz + 1, parameters_ret, &sz_ret); + err = ccs_context_get_parameters( + (ccs_context_t)configuration_space, sz + 1, parameters_ret, + &sz_ret); assert(err == CCS_RESULT_SUCCESS); assert(sz_ret == sz); for (size_t i = 0; i < sz; i++) @@ -62,8 +64,8 @@ check_configuration( for (size_t i = 0; i < sz; i++) { err = ccs_parameter_get_name(parameters[i], &name); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_space_get_parameter_by_name( - configuration_space, name, ¶meter); + err = ccs_context_get_parameter_by_name( + (ccs_context_t)configuration_space, name, ¶meter); assert(err == CCS_RESULT_SUCCESS); assert(parameter == parameters[i]); } @@ -78,7 +80,8 @@ check_configuration( for (size_t i = 0; i < sz; i++) { ccs_datum_t datum; ccs_datum_t hdatum; - err = ccs_configuration_get_value(configuration, i, &datum); + err = ccs_binding_get_value( + (ccs_binding_t)configuration, i, &datum); assert(err == CCS_RESULT_SUCCESS); err = ccs_parameter_get_default_value(parameters[i], &hdatum); assert(err == CCS_RESULT_SUCCESS); @@ -155,7 +158,7 @@ test_create(void) assert(err == CCS_RESULT_SUCCESS); assert(type == CCS_OBJECT_TYPE_CONFIGURATION_SPACE); - err = ccs_configuration_space_get_name(configuration_space, &name); + err = ccs_context_get_name((ccs_context_t)configuration_space, &name); assert(err == CCS_RESULT_SUCCESS); assert(strcmp(name, "my_config_space") == 0); @@ -295,7 +298,9 @@ test_configuration_deserialize(void) CCS_DESERIALIZE_OPTION_END); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_cmp(configuration_ref, configuration, &cmp); + err = ccs_binding_cmp( + (ccs_binding_t)configuration_ref, (ccs_binding_t)configuration, + &cmp); assert(err == CCS_RESULT_SUCCESS); assert(!cmp); @@ -407,7 +412,7 @@ test_deserialize(void) assert(d.type == CCS_DATA_TYPE_OBJECT); assert(d.value.o == space); - err = ccs_configuration_space_get_parameters(space, 0, NULL, &count); + err = ccs_context_get_parameters((ccs_context_t)space, 0, NULL, &count); assert(err == CCS_RESULT_SUCCESS); assert(count == 3); diff --git a/tests/test_distribution_space.c b/tests/test_distribution_space.c index 1225fcc6..627a5546 100644 --- a/tests/test_distribution_space.c +++ b/tests/test_distribution_space.c @@ -36,23 +36,25 @@ check_configuration( const char *name; ccs_bool_t check; - err = ccs_configuration_space_get_num_parameters( - configuration_space, &sz_ret); + err = ccs_context_get_num_parameters( + (ccs_context_t)configuration_space, &sz_ret); assert(err == CCS_RESULT_SUCCESS); assert(sz_ret == sz); for (size_t i = 0; i < sz; i++) { - err = ccs_configuration_space_get_parameter( - configuration_space, i, ¶meter); + err = ccs_context_get_parameter( + (ccs_context_t)configuration_space, i, ¶meter); assert(err == CCS_RESULT_SUCCESS); assert(parameter == parameters[i]); - err = ccs_configuration_space_get_parameter_index( - configuration_space, parameter, NULL, &index); + err = ccs_context_get_parameter_index( + (ccs_context_t)configuration_space, parameter, NULL, + &index); assert(err == CCS_RESULT_SUCCESS); assert(index == i); } - err = ccs_configuration_space_get_parameters( - configuration_space, sz + 1, parameters_ret, &sz_ret); + err = ccs_context_get_parameters( + (ccs_context_t)configuration_space, sz + 1, parameters_ret, + &sz_ret); assert(err == CCS_RESULT_SUCCESS); assert(sz_ret == sz); for (size_t i = 0; i < sz; i++) @@ -62,8 +64,8 @@ check_configuration( for (size_t i = 0; i < sz; i++) { err = ccs_parameter_get_name(parameters[i], &name); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_space_get_parameter_by_name( - configuration_space, name, ¶meter); + err = ccs_context_get_parameter_by_name( + (ccs_context_t)configuration_space, name, ¶meter); assert(err == CCS_RESULT_SUCCESS); assert(parameter == parameters[i]); } @@ -78,7 +80,8 @@ check_configuration( for (size_t i = 0; i < sz; i++) { ccs_datum_t datum; ccs_datum_t hdatum; - err = ccs_configuration_get_value(configuration, i, &datum); + err = ccs_binding_get_value( + (ccs_binding_t)configuration, i, &datum); assert(err == CCS_RESULT_SUCCESS); err = ccs_parameter_get_default_value(parameters[i], &hdatum); assert(err == CCS_RESULT_SUCCESS); @@ -200,8 +203,8 @@ test_set_distribution(void) err = ccs_configuration_check(configurations[i], &check); assert(err == CCS_RESULT_SUCCESS); assert(check); - err = ccs_configuration_get_values( - configurations[i], 3, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configurations[i], 3, values, NULL); assert(err == CCS_RESULT_SUCCESS); assert(values[0].value.f >= -4.0); assert(values[0].value.f < 4.0); @@ -239,8 +242,8 @@ test_set_distribution(void) err = ccs_configuration_check(configurations[i], &check); assert(err == CCS_RESULT_SUCCESS); assert(check); - err = ccs_configuration_get_values( - configurations[i], 3, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configurations[i], 3, values, NULL); assert(err == CCS_RESULT_SUCCESS); assert(values[2].value.f >= -4.0); assert(values[2].value.f < 4.0); diff --git a/tests/test_features_space.c b/tests/test_features_space.c index c85aab28..5cfb121a 100644 --- a/tests/test_features_space.c +++ b/tests/test_features_space.c @@ -34,22 +34,23 @@ check_features( (ccs_parameter_t *)malloc(sizeof(ccs_parameter_t) * (sz + 1)); const char *name; - err = ccs_features_space_get_num_parameters(features_space, &sz_ret); + err = ccs_context_get_num_parameters( + (ccs_context_t)features_space, &sz_ret); assert(err == CCS_RESULT_SUCCESS); assert(sz_ret == sz); for (size_t i = 0; i < sz; i++) { - err = ccs_features_space_get_parameter( - features_space, i, ¶meter); + err = ccs_context_get_parameter( + (ccs_context_t)features_space, i, ¶meter); assert(err == CCS_RESULT_SUCCESS); assert(parameter == parameters[i]); - err = ccs_features_space_get_parameter_index( - features_space, parameter, NULL, &index); + err = ccs_context_get_parameter_index( + (ccs_context_t)features_space, parameter, NULL, &index); assert(err == CCS_RESULT_SUCCESS); assert(index == i); } - err = ccs_features_space_get_parameters( - features_space, sz + 1, parameters_ret, &sz_ret); + err = ccs_context_get_parameters( + (ccs_context_t)features_space, sz + 1, parameters_ret, &sz_ret); assert(err == CCS_RESULT_SUCCESS); assert(sz_ret == sz); for (size_t i = 0; i < sz; i++) @@ -59,8 +60,8 @@ check_features( for (size_t i = 0; i < sz; i++) { err = ccs_parameter_get_name(parameters[i], &name); assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_space_get_parameter_by_name( - features_space, name, ¶meter); + err = ccs_context_get_parameter_by_name( + (ccs_context_t)features_space, name, ¶meter); assert(err == CCS_RESULT_SUCCESS); assert(parameter == parameters[i]); } @@ -101,7 +102,7 @@ test_create(void) assert(err == CCS_RESULT_SUCCESS); assert(type == CCS_OBJECT_TYPE_FEATURES_SPACE); - err = ccs_features_space_get_name(features_space, &name); + err = ccs_context_get_name((ccs_context_t)features_space, &name); assert(err == CCS_RESULT_SUCCESS); assert(strcmp(name, "my_features_space") == 0); @@ -146,14 +147,15 @@ test_features(void) assert(features_space == features_space_ret); for (size_t i = 0; i < 3; i++) { - err = ccs_features_get_value(features1, i, &datum); + err = ccs_binding_get_value( + (ccs_binding_t)features1, i, &datum); assert(err == CCS_RESULT_SUCCESS); assert(values[i].type == datum.type); assert(values[i].value.f == datum.value.f); } - err = ccs_features_get_values( - features1, 3, values_ret, &num_values_ret); + err = ccs_binding_get_values( + (ccs_binding_t)features1, 3, values_ret, &num_values_ret); assert(err == CCS_RESULT_SUCCESS); assert(3 == num_values_ret); for (size_t i = 0; i < 3; i++) { @@ -161,7 +163,8 @@ test_features(void) assert(values[i].value.f == values_ret[i].value.f); } - err = ccs_features_get_value_by_name(features1, "param2", &datum); + err = ccs_binding_get_value_by_name( + (ccs_binding_t)features1, "param2", NULL, &datum); assert(err == CCS_RESULT_SUCCESS); assert(values[1].type == datum.type); assert(values[1].value.f == datum.value.f); @@ -178,7 +181,8 @@ test_features(void) err = ccs_create_features(features_space, 3, values, &features2); assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_cmp(features1, features2, &cmp); + err = ccs_binding_cmp( + (ccs_binding_t)features1, (ccs_binding_t)features2, &cmp); assert(err == CCS_RESULT_SUCCESS); assert(0 == cmp); err = ccs_release_object(features2); @@ -188,7 +192,8 @@ test_features(void) err = ccs_create_features(features_space, 3, values, &features2); assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_cmp(features1, features2, &cmp); + err = ccs_binding_cmp( + (ccs_binding_t)features1, (ccs_binding_t)features2, &cmp); assert(err == CCS_RESULT_SUCCESS); assert(0 > cmp); err = ccs_release_object(features2); @@ -269,14 +274,14 @@ test_deserialize(void) CCS_DESERIALIZE_OPTION_END); assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_space_get_parameter_by_name( - features_space, "param1", ¶meters_new[0]); + err = ccs_context_get_parameter_by_name( + (ccs_context_t)features_space, "param1", ¶meters_new[0]); assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_space_get_parameter_by_name( - features_space, "param2", ¶meters_new[1]); + err = ccs_context_get_parameter_by_name( + (ccs_context_t)features_space, "param2", ¶meters_new[1]); assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_space_get_parameter_by_name( - features_space, "param3", ¶meters_new[2]); + err = ccs_context_get_parameter_by_name( + (ccs_context_t)features_space, "param3", ¶meters_new[2]); assert(err == CCS_RESULT_SUCCESS); err = ccs_release_object(features_space); @@ -291,14 +296,14 @@ test_deserialize(void) CCS_DESERIALIZE_OPTION_END); assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_space_get_parameter_by_name( - features_space, "param1", ¶meters_new[0]); + err = ccs_context_get_parameter_by_name( + (ccs_context_t)features_space, "param1", ¶meters_new[0]); assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_space_get_parameter_by_name( - features_space, "param2", ¶meters_new[1]); + err = ccs_context_get_parameter_by_name( + (ccs_context_t)features_space, "param2", ¶meters_new[1]); assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_space_get_parameter_by_name( - features_space, "param3", ¶meters_new[2]); + err = ccs_context_get_parameter_by_name( + (ccs_context_t)features_space, "param3", ¶meters_new[2]); assert(err == CCS_RESULT_SUCCESS); err = ccs_map_get(map, ccs_object(features_space_ref), &d); @@ -374,7 +379,8 @@ test_features_deserialize(void) CCS_DESERIALIZE_OPTION_END); assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_cmp(features_ref, features, &cmp); + err = ccs_binding_cmp( + (ccs_binding_t)features_ref, (ccs_binding_t)features, &cmp); assert(err == CCS_RESULT_SUCCESS); assert(!cmp); diff --git a/tests/test_forbidden.c b/tests/test_forbidden.c index 7dcf64c6..19566257 100644 --- a/tests/test_forbidden.c +++ b/tests/test_forbidden.c @@ -44,8 +44,8 @@ test_simple(void) err = ccs_configuration_space_sample( space, NULL, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_get_values( - configuration, 2, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configuration, 2, values, NULL); assert(err == CCS_RESULT_SUCCESS); assert(values[0].type == CCS_DATA_TYPE_FLOAT); f = values[0].value.f; @@ -67,8 +67,8 @@ test_simple(void) for (int i = 0; i < 100; i++) { ccs_float_t f; ccs_bool_t check; - err = ccs_configuration_get_values( - configurations[i], 2, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configurations[i], 2, values, NULL); assert(err == CCS_RESULT_SUCCESS); assert(values[0].type == CCS_DATA_TYPE_FLOAT); f = values[0].value.f; @@ -142,8 +142,8 @@ test_combined(void) err = ccs_configuration_space_sample( space, NULL, NULL, &configuration); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_get_values( - configuration, 3, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configuration, 3, values, NULL); assert(err == CCS_RESULT_SUCCESS); assert(values[1].type == CCS_DATA_TYPE_FLOAT); f = values[1].value.f; @@ -178,8 +178,8 @@ test_combined(void) for (int i = 0; i < 100; i++) { ccs_float_t f; ccs_bool_t check; - err = ccs_configuration_get_values( - configurations[i], 3, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configurations[i], 3, values, NULL); assert(err == CCS_RESULT_SUCCESS); assert(values[1].type == CCS_DATA_TYPE_FLOAT); f = values[1].value.f; diff --git a/tests/test_random_features_tuner.c b/tests/test_random_features_tuner.c index e8021c00..b61954c2 100644 --- a/tests/test_random_features_tuner.c +++ b/tests/test_random_features_tuner.c @@ -74,8 +74,8 @@ test(void) err = ccs_features_tuner_ask( tuner, features_on, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_get_values( - configuration, 2, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configuration, 2, values, NULL); assert(err == CCS_RESULT_SUCCESS); res = ccs_float( (values[0].value.f - 1) * (values[0].value.f - 1) + @@ -99,8 +99,8 @@ test(void) err = ccs_features_tuner_ask( tuner, features_off, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_get_values( - configuration, 2, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configuration, 2, values, NULL); assert(err == CCS_RESULT_SUCCESS); res = ccs_float( (values[0].value.f - 1) * (values[0].value.f - 1) + @@ -351,7 +351,8 @@ test_evaluation_deserialize(void) CCS_DESERIALIZE_OPTION_END); assert(err == CCS_RESULT_SUCCESS); - err = ccs_features_evaluation_cmp(evaluation_ref, evaluation, &cmp); + err = ccs_binding_cmp( + (ccs_binding_t)evaluation_ref, (ccs_binding_t)evaluation, &cmp); assert(err == CCS_RESULT_SUCCESS); assert(!cmp); diff --git a/tests/test_random_tree_tuner.c b/tests/test_random_tree_tuner.c index b4037f57..3eb799be 100644 --- a/tests/test_random_tree_tuner.c +++ b/tests/test_random_tree_tuner.c @@ -256,7 +256,8 @@ test_tree_evaluation_deserialize(void) CCS_DESERIALIZE_OPTION_END); assert(err == CCS_RESULT_SUCCESS); - err = ccs_tree_evaluation_cmp(evaluation_ref, evaluation, &cmp); + err = ccs_binding_cmp( + (ccs_binding_t)evaluation_ref, (ccs_binding_t)evaluation, &cmp); assert(err == CCS_RESULT_SUCCESS); assert(!cmp); diff --git a/tests/test_random_tuner.c b/tests/test_random_tuner.c index cd5ca884..0657d53e 100644 --- a/tests/test_random_tuner.c +++ b/tests/test_random_tuner.c @@ -57,8 +57,8 @@ test(void) ccs_evaluation_t evaluation; err = ccs_tuner_ask(tuner, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_get_values( - configuration, 2, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configuration, 2, values, NULL); assert(err == CCS_RESULT_SUCCESS); res = ccs_float( (values[0].value.f - 1) * (values[0].value.f - 1) + @@ -246,7 +246,8 @@ test_evaluation_deserialize(void) CCS_DESERIALIZE_OPTION_END); assert(err == CCS_RESULT_SUCCESS); - err = ccs_evaluation_cmp(evaluation_ref, evaluation, &cmp); + err = ccs_binding_cmp( + (ccs_binding_t)evaluation_ref, (ccs_binding_t)evaluation, &cmp); assert(err == CCS_RESULT_SUCCESS); assert(!cmp); diff --git a/tests/test_user_defined_features_tuner.c b/tests/test_user_defined_features_tuner.c index eaad2bb8..ffaaf4b9 100644 --- a/tests/test_user_defined_features_tuner.c +++ b/tests/test_user_defined_features_tuner.c @@ -110,7 +110,9 @@ tuner_last_get_optima( tuner_data->last_eval, &feat); if (err) return err; - err = ccs_features_cmp(features, feat, &cmp); + err = ccs_binding_cmp( + (ccs_binding_t)features, (ccs_binding_t)feat, + &cmp); if (err) return err; if (cmp == 0) { @@ -221,8 +223,8 @@ test(void) err = ccs_features_tuner_ask( tuner, features_on, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_get_values( - configuration, 2, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configuration, 2, values, NULL); assert(err == CCS_RESULT_SUCCESS); res = ccs_float( (values[0].value.f - 1) * (values[0].value.f - 1) + @@ -247,8 +249,8 @@ test(void) err = ccs_features_tuner_ask( tuner, features_off, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_get_values( - configuration, 2, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configuration, 2, values, NULL); assert(err == CCS_RESULT_SUCCESS); res = ccs_float( (values[0].value.f - 1) * (values[0].value.f - 1) + diff --git a/tests/test_user_defined_tuner.c b/tests/test_user_defined_tuner.c index 45415e07..adbd2d0e 100644 --- a/tests/test_user_defined_tuner.c +++ b/tests/test_user_defined_tuner.c @@ -193,8 +193,8 @@ test(void) ccs_evaluation_t evaluation; err = ccs_tuner_ask(tuner, 1, &configuration, NULL); assert(err == CCS_RESULT_SUCCESS); - err = ccs_configuration_get_values( - configuration, 2, values, NULL); + err = ccs_binding_get_values( + (ccs_binding_t)configuration, 2, values, NULL); assert(err == CCS_RESULT_SUCCESS); res = ccs_float( (values[0].value.f - 1) * (values[0].value.f - 1) +