From f393a5cc0a2a7b0cd1d5b06166966d7af6f9daf5 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 7 Jul 2010 15:54:01 +0200 Subject: [PATCH] src/graph.[ch]: Implement "graph_sort_instances". --- src/graph.c | 14 ++++++++++++++ src/graph.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/graph.c b/src/graph.c index 49bd765..9d435c2 100644 --- a/src/graph.c +++ b/src/graph.c @@ -484,6 +484,20 @@ int graph_compare (graph_config_t *cfg, const graph_ident_t *ident) /* {{{ */ return (ident_compare (cfg->select, ident)); } /* }}} int graph_compare */ +int graph_sort_instances (graph_config_t *cfg) /* {{{ */ +{ + if (cfg == NULL) + return (EINVAL); + + if (cfg->instances_num < 2) + return (0); + + qsort (cfg->instances, cfg->instances_num, sizeof (*cfg->instances), + (void *) ident_compare); + + return (0); +} /* }}} int graph_sort_instances */ + int graph_clear_instances (graph_config_t *cfg) /* {{{ */ { size_t i; diff --git a/src/graph.h b/src/graph.h index 2be1a96..26b4ac6 100644 --- a/src/graph.h +++ b/src/graph.h @@ -85,6 +85,8 @@ int graph_inst_search_field (graph_config_t *cfg, int graph_compare (graph_config_t *cfg, const graph_ident_t *ident); +int graph_sort_instances (graph_config_t *cfg); + int graph_clear_instances (graph_config_t *cfg); int graph_get_rrdargs (graph_config_t *cfg, graph_instance_t *inst, -- 2.30.2