aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--km-rand.c (renamed from km-rand-src.c)24
-rw-r--r--km-set.c4
-rw-r--r--km.h21
-rw-r--r--main.c4
5 files changed, 27 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index 61e8f9e..d23f364 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
APP=km-test
CFLAGS=-W -Wall -Wextra -pedantic -std=c11 -O2
-OBJS=km-set.o km-draw.o km-load.o km-find.o km-rand-src.o km-solve.o main.o
+OBJS=km-set.o km-draw.o km-load.o km-find.o km-rand.o km-solve.o main.o
LIBS=-lm
.PHONY=all clean
diff --git a/km-rand-src.c b/km-rand.c
index 0ddc1bb..fcc6a74 100644
--- a/km-rand-src.c
+++ b/km-rand.c
@@ -4,8 +4,8 @@
// fill buffer with N random floats
bool
-km_rand_src_fill(
- km_rand_src_t * const rs,
+km_rand_fill(
+ km_rand_t * const rs,
const size_t num_floats,
float * const floats
) {
@@ -14,8 +14,8 @@ km_rand_src_fill(
// finalize random source
void
-km_rand_src_fini(
- km_rand_src_t * const rs
+km_rand_fini(
+ km_rand_t * const rs
) {
if (rs->cbs->fini) {
rs->cbs->fini(rs);
@@ -24,8 +24,8 @@ km_rand_src_fini(
// fill callback for system random source
static bool
-rand_src_system_on_fill(
- km_rand_src_t * const rs,
+system_on_fill(
+ km_rand_t * const rs,
const size_t num_floats,
float * const floats
) {
@@ -41,17 +41,17 @@ rand_src_system_on_fill(
}
// system random source callbacks
-static const km_rand_src_cbs_t
-RAND_SRC_SYSTEM_CBS = {
- .fill = rand_src_system_on_fill,
+static const km_rand_cbs_t
+SYSTEM_CBS = {
+ .fill = system_on_fill,
.fini = NULL,
};
// init system random source (uses system rand())
void
-km_rand_src_system_init(
- km_rand_src_t * const rs
+km_rand_init_system(
+ km_rand_t * const rs
) {
- rs->cbs = &RAND_SRC_SYSTEM_CBS;
+ rs->cbs = &SYSTEM_CBS;
rs->data = NULL;
}
diff --git a/km-set.c b/km-set.c
index 5b9ae4c..63ec22a 100644
--- a/km-set.c
+++ b/km-set.c
@@ -219,7 +219,7 @@ km_set_init_rand_clusters(
km_set_t * const cs,
const size_t num_floats,
const size_t num_clusters,
- km_rand_src_t * const rs
+ km_rand_t * const rs
) {
// init cluster shape
const km_shape_t shape = {
@@ -229,7 +229,7 @@ km_set_init_rand_clusters(
// generate random cluster centers
float floats[num_floats * num_clusters];
- if (!km_rand_src_fill(rs, num_floats * num_clusters, floats)) {
+ if (!km_rand_fill(rs, num_floats * num_clusters, floats)) {
// return failure
return false;
}
diff --git a/km.h b/km.h
index 642560b..1d00d50 100644
--- a/km.h
+++ b/km.h
@@ -6,28 +6,28 @@
#include <stdio.h> // FILE
// forward typedef for callbacks
-typedef struct km_rand_src_t_ km_rand_src_t;
+typedef struct km_rand_t_ km_rand_t;
// random number source callbacks
typedef struct {
- _Bool (*fill)(km_rand_src_t * const, const size_t, float * const);
- void (*fini)(km_rand_src_t * const);
-} km_rand_src_cbs_t;
+ _Bool (*fill)(km_rand_t * const, const size_t, float * const);
+ void (*fini)(km_rand_t * const);
+} km_rand_cbs_t;
// random number source
-struct km_rand_src_t_ {
- const km_rand_src_cbs_t *cbs;
+struct km_rand_t_ {
+ const km_rand_cbs_t *cbs;
void *data;
};
// fill buffer with N random floats
-_Bool km_rand_src_fill(km_rand_src_t * const, const size_t, float * const);
+_Bool km_rand_fill(km_rand_t * const, const size_t, float * const);
// finalize random source
-void km_rand_src_fini(km_rand_src_t * const);
+void km_rand_fini(km_rand_t * const);
// init system random source (uses system rand())
-void km_rand_src_system_init(km_rand_src_t *);
+void km_rand_init_system(km_rand_t *);
// shape of data set
typedef struct {
@@ -87,7 +87,7 @@ _Bool km_set_init_rand_clusters(
km_set_t *,
const size_t,
const size_t,
- km_rand_src_t *
+ km_rand_t *
);
typedef struct {
@@ -136,7 +136,6 @@ typedef void (*km_find_data_cb_t)(
typedef struct {
size_t max_clusters;
size_t num_tests;
- km_rand_src_t *rand_src;
km_find_init_cb_t on_init;
km_find_fini_cb_t on_fini;
diff --git a/main.c b/main.c
index bd4192f..af04121 100644
--- a/main.c
+++ b/main.c
@@ -16,7 +16,7 @@
#define NUM_TESTS 100
typedef struct {
- km_rand_src_t rs;
+ km_rand_t rs;
struct {
float distance,
@@ -220,7 +220,7 @@ int main(int argc, char *argv[]) {
// init find data
find_t find_data;
memset(find_data.rows, 0, sizeof(find_data.rows));
- km_rand_src_system_init(&(find_data.rs));
+ km_rand_init_system(&(find_data.rs));
// init data set
km_set_t set;