/**
- * collectd - src/sn_network.c
- * Copyright (C) 2008,2009 Florian octo Forster
+ * libsortnetwork - src/sn_network.c
+ * Copyright (C) 2008-2010 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * Florian octo Forster <octo at verplant.org>
+ * Florian octo Forster <ff at octo.it>
**/
#ifndef _ISOC99_SOURCE
return (n_copy);
} /* }}} sn_network_t *sn_network_clone */
+int sn_network_comparator_add (sn_network_t *n, /* {{{ */
+ const sn_comparator_t *c)
+{
+ sn_stage_t *s;
+
+ if ((n == NULL) || (c == NULL))
+ return (-1);
+
+ if (n->stages_num > 0)
+ {
+ s = n->stages[n->stages_num - 1];
+
+ if (sn_stage_comparator_check_conflict (s, c) == 0)
+ {
+ sn_stage_comparator_add (s, c);
+ return (0);
+ }
+ }
+
+ s = sn_stage_create (n->stages_num);
+ sn_stage_comparator_add (s, c);
+ sn_network_stage_add (n, s);
+
+ return (0);
+} /* }}} int sn_network_comparator_add */
+
+int sn_network_get_comparator_num (const sn_network_t *n) /* {{{ */
+{
+ int num;
+ int i;
+
+ if (n == NULL)
+ return (-1);
+
+ num = 0;
+ for (i = 0; i < n->stages_num; i++)
+ num += n->stages[i]->comparators_num;
+
+ return (num);
+} /* }}} int sn_network_get_comparator_num */
+
int sn_network_show (sn_network_t *n) /* {{{ */
{
int i;
#define SNPRINTF_OR_FAIL(...) \
status = snprintf (buffer, buffer_size, __VA_ARGS__); \
- if ((status < 1) || (status >= buffer_size)) \
+ if ((status < 1) || (((size_t) status) >= buffer_size)) \
return (-1); \
buffer += status; \
buffer_size -= status;