From 33a722132491ebdd31722f0cada0f81f6b082282 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 3 Feb 2019 18:36:52 -0500 Subject: cluster init refactoring, fix best sort, add km_score() --- km-init-type.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 km-init-type.c (limited to 'km-init-type.c') diff --git a/km-init-type.c b/km-init-type.c new file mode 100644 index 0000000..27fc1ee --- /dev/null +++ b/km-init-type.c @@ -0,0 +1,32 @@ +#include // size_t +#include // strcmp() +#include "km.h" + +static const struct { + const km_init_type_t type; + const char * const name; +} TYPES[] = {{ + .name = "rand", + .type = KM_INIT_TYPE_RAND, +}, { + .name = "forgy", + .type = KM_INIT_TYPE_FORGY, +}}; + +#define NUM_TYPES (sizeof(TYPES) / sizeof(TYPES[0])) + +km_init_type_t +km_get_init_type( + const char * const s +) { + // find init method + for (size_t i = 0; i < NUM_TYPES; i++) { + if (!strcmp(s, TYPES[i].name)) { + // return type + return TYPES[i].type; + } + } + + // return failure + return KM_INIT_TYPE_LAST; +} -- cgit v1.2.3