" Normalized: %4s\n"
" Sorts: %7s\n"
" Rating: %4i\n"
+ " Hash: 0x%08"PRIx32"\n"
"\n",
comparators_num,
(normalized ? "yes" : "no"),
((inputs_num > 16) ? "unknown" : (sorts ? "yes" : "no")),
- (stages_num_compressed * inputs_num) + comparators_num);
+ (stages_num_compressed * inputs_num) + comparators_num,
+ sn_network_get_hashval (n));
exit (EXIT_SUCCESS);
} /* int main */
return (0);
} /* int sn_comparator_compare */
+uint32_t sn_comparator_get_hashval (const sn_comparator_t *c) /* {{{ */
+{
+ if (c == NULL)
+ return (0);
+
+ /* 100937 and 103319 are some random prime numbers */
+ return ((((uint32_t) c->min) * 100937)
+ + (((uint32_t) c->max) * 103319));
+} /* }}} uint32_t sn_comparator_get_hashval */
+
/* vim: set shiftwidth=2 softtabstop=2 : */
#ifndef SN_COMPARATOR_H
#define SN_COMPARATOR_H 1
+#include <stdint.h>
+#include <inttypes.h>
+
/**
* Struct representing a comparator. Don't access the members of this struct
* directly, use the macros below instead.
int sn_comparator_compare (const sn_comparator_t *c0,
const sn_comparator_t *c1);
+uint32_t sn_comparator_get_hashval (const sn_comparator_t *c);
+
#endif /* SN_COMPARATOR_H */
/* vim: set shiftwidth=2 softtabstop=2 : */
return (n);
} /* }}} sn_network_t *sn_network_unserialize */
+uint32_t sn_network_get_hashval (const sn_network_t *n) /* {{{ */
+{
+ uint32_t hash;
+ int i;
+
+ if (n == NULL)
+ return (0);
+
+ hash = (uint32_t) n->inputs_num;
+
+ for (i = 0; i < n->stages_num; i++)
+ hash = (hash * 104207) + sn_stage_get_hashval (n->stages[i]);
+
+ return (hash);
+} /* }}} uint32_t sn_network_get_hashval */
+
/* vim: set sw=2 sts=2 et fdm=marker : */
#define SN_NETWORK_H 1
#include <stdio.h>
+#include <stdint.h>
+#include <inttypes.h>
#include "sn_comparator.h"
#include "sn_stage.h"
* \see sn_network_serialize
*/
sn_network_t *sn_network_unserialize (char *buffer, size_t buffer_size);
+
+uint32_t sn_network_get_hashval (const sn_network_t *n);
+
#endif /* SN_NETWORK_H */
/* vim: set shiftwidth=2 softtabstop=2 : */
return (s);
} /* sn_stage_t *sn_stage_unserialize */
-/* vim: set shiftwidth=2 softtabstop=2 expandtab : */
+uint32_t sn_stage_get_hashval (const sn_stage_t *s) /* {{{ */
+{
+ uint32_t hash;
+ int i;
+
+ if (s == NULL)
+ return (0);
+
+ hash = (uint32_t) s->depth;
+
+ for (i = 0; i < s->comparators_num; i++)
+ hash = (hash * 99991) + sn_comparator_get_hashval (s->comparators + i);
+
+ return (hash);
+} /* }}} uint32_t sn_stage_get_hashval */
+
+/* vim: set shiftwidth=2 softtabstop=2 expandtab fdm=marker : */
#define SN_STAGE_H 1
#include <stdio.h>
+#include <stdint.h>
+#include <inttypes.h>
#include "sn_comparator.h"
*/
sn_stage_t *sn_stage_unserialize (char **buffer, size_t *buffer_size);
+uint32_t sn_stage_get_hashval (const sn_stage_t *s);
+
#endif /* SN_STAGE_H */
/* vim: set shiftwidth=2 softtabstop=2 : */