}
}
-static int label_pair_compare(void const *a, void const *b) {
+static int label_name_compare(void const *a, void const *b) {
return strcmp(((label_pair_t const *)a)->name,
((label_pair_t const *)b)->name);
}
};
label_pair_t *ret = bsearch(&label, labels->ptr, labels->num,
- sizeof(*labels->ptr), label_pair_compare);
+ sizeof(*labels->ptr), label_name_compare);
if (ret == NULL) {
errno = ENOENT;
return NULL;
labels->ptr[labels->num] = pair;
labels->num++;
- qsort(labels->ptr, labels->num, sizeof(*labels->ptr), label_pair_compare);
+ qsort(labels->ptr, labels->num, sizeof(*labels->ptr), label_name_compare);
return 0;
}
return fam->metric.ptr;
}
+
+static int label_pair_compare(label_pair_t a, label_pair_t b) {
+ int cmp = strcmp(a.name, b.name);
+ if (cmp != 0) {
+ return cmp;
+ }
+
+ return strcmp(a.value, b.value);
+}
+
+int label_set_compare(label_set_t a, label_set_t b) {
+ if (a.num != b.num) {
+ return a.num < b.num ? -1 : 1;
+ }
+
+ for (size_t i = 0; i < a.num; i++) {
+ int cmp = label_pair_compare(a.ptr[i], b.ptr[i]);
+ if (cmp != 0) {
+ return cmp;
+ }
+ }
+
+ return 0;
+}
+
+int metric_family_compare(metric_family_t const *a, metric_family_t const *b) {
+ int cmp = strcmp(a->name, b->name);
+ if (cmp != 0) {
+ return cmp;
+ }
+
+ return label_set_compare(a->resource, b->resource);
+}
* initializes the label set to zero. */
void label_set_reset(label_set_t *labels);
+/* label_set_compare compares two label sets. It returns an integer indicating
+ * the result of the comparison, as follows:
+ *
+ * - 0, if the a and b are equal;
+ * - a negative value if a is less than b;
+ * - a positive value if a is greater than b.
+ */
+int label_set_compare(label_set_t a, label_set_t b);
+
/*
* Metric
*/
* metric_family_free(). */
metric_family_t *metric_family_clone(metric_family_t const *fam);
+/* metric_family_compare compares two metric families, taking into account the
+ * metric family name and any resource attributes. It returns an integer
+ * indicating the result of the comparison, as follows:
+ *
+ * - 0, if the a and b are equal;
+ * - a negative value if a is less than b;
+ * - a positive value if a is greater than b.
+ */
+int metric_family_compare(metric_family_t const *a, metric_family_t const *b);
+
#endif