Download src/algorithm_registry.c from Jack698/ucissl: direct link, hf CLI and curl.
- Browser
- Download file 2.35 kB
-
https://huggingface.co/spaces/Jack698/ucissl/resolve/main/src/algorithm_registry.c
- Command line
-
hf download hf://spaces/Jack698/ucissl/src/algorithm_registry.c
-
curl -L -o algorithm_registry.c https://huggingface.co/spaces/Jack698/ucissl/resolve/main/src/algorithm_registry.c
2.35 kB
| static uci_algorithm_impl_t *algorithm_table[MAX_ALGORITHMS]; | |
| static size_t algorithm_count = 0; | |
| int registry_init(void) { | |
| memset(algorithm_table, 0, sizeof(algorithm_table)); | |
| algorithm_count = 0; | |
| return UCI_SUCCESS; | |
| } | |
| int registry_cleanup(void) { | |
| for (size_t i = 0; i < algorithm_count; i++) { | |
| if (algorithm_table[i]) { | |
| free(algorithm_table[i]); | |
| algorithm_table[i] = NULL; | |
| } | |
| } | |
| algorithm_count = 0; | |
| return UCI_SUCCESS; | |
| } | |
| int registry_register_algorithm(const uci_algorithm_impl_t *impl) { | |
| if (!impl) { | |
| return UCI_ERROR_INVALID_PARAM; | |
| } | |
| if (algorithm_count >= MAX_ALGORITHMS) { | |
| return UCI_ERROR_INTERNAL; | |
| } | |
| for (size_t i = 0; i < algorithm_count; i++) { | |
| if (algorithm_table[i] && algorithm_table[i]->info.id == impl->info.id) { | |
| return UCI_ERROR_INTERNAL; | |
| } | |
| } | |
| uci_algorithm_impl_t *new_impl = (uci_algorithm_impl_t *)malloc(sizeof(uci_algorithm_impl_t)); | |
| if (!new_impl) { | |
| return UCI_ERROR_INTERNAL; | |
| } | |
| memcpy(new_impl, impl, sizeof(uci_algorithm_impl_t)); | |
| algorithm_table[algorithm_count++] = new_impl; | |
| return UCI_SUCCESS; | |
| } | |
| const uci_algorithm_impl_t *registry_get_algorithm(uci_algorithm_id_t algorithm) { | |
| for (size_t i = 0; i < algorithm_count; i++) { | |
| if (algorithm_table[i] && algorithm_table[i]->info.id == algorithm) { | |
| return algorithm_table[i]; | |
| } | |
| } | |
| return NULL; | |
| } | |
| int registry_list_algorithms(uci_algorithm_type_t type, uci_algorithm_id_t *algorithms, size_t *count) { | |
| if (!count) { | |
| return UCI_ERROR_INVALID_PARAM; | |
| } | |
| size_t matched = 0; | |
| for (size_t i = 0; i < algorithm_count; i++) { | |
| if (!algorithm_table[i]) { | |
| continue; | |
| } | |
| if (type == algorithm_table[i]->info.type || type == -1) { | |
| if (algorithms && matched < *count) { | |
| algorithms[matched] = algorithm_table[i]->info.id; | |
| } | |
| matched++; | |
| } | |
| } | |
| if (algorithms && matched > *count) { | |
| *count = matched; | |
| return UCI_ERROR_BUFFER_TOO_SMALL; | |
| } | |
| *count = matched; | |
| return UCI_SUCCESS; | |
| } | |