From d658ac9e61a78122c9fe0cfba3797dead382ba3b Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Thu, 9 Jul 2020 00:15:21 +0200 Subject: Added -b to ndpiReader to evaluate bins --- src/lib/ndpi_analyze.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src/lib') diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c index 8d4e939f0..8c21c0e0e 100644 --- a/src/lib/ndpi_analyze.c +++ b/src/lib/ndpi_analyze.c @@ -476,25 +476,29 @@ float ndpi_bin_similarity(struct ndpi_bin *b1, struct ndpi_bin *b2, u_int8_t nor - (in) bins: a vection 'num_bins' long of bins to cluster - (in) 'num_clusters': number of desired clusters 0...(num_clusters-1) - (out) 'cluster_ids': a vector 'num_bins' long containing the id's of each clustered bin - + - (out) 'centroids': an optional 'num_clusters' long vector of (centroid) bins See - https://en.wikipedia.org/wiki/K-means_clustering */ int ndpi_cluster_bins(struct ndpi_bin *bins, u_int16_t num_bins, - u_int8_t num_clusters, u_int16_t *cluster_ids) { + u_int8_t num_clusters, u_int16_t *cluster_ids, + struct ndpi_bin *centroids) { u_int16_t i, j, max_iterations = 100, num_iterations = 0, num_moves; - struct ndpi_bin *centroids; - u_int8_t verbose = 0; + u_int8_t verbose = 0, alloc_centroids = 0; if(num_clusters > num_bins) return(-1); - if((centroids = (struct ndpi_bin*)ndpi_malloc(sizeof(struct ndpi_bin)*num_clusters)) == NULL) - return(-2); - else { - for(i=0; i