]> mj.ucw.cz Git - libucw.git/blobdiff - lib/sort-test.c
Added secondary sorting (i.e., breaking ties when two documents have the same Q)
[libucw.git] / lib / sort-test.c
index 2f61b1528d783b71fe27172bd276d381f38ccdc7..448abdc31b517fe72e0b39e0c64898613b005a96 100644 (file)
@@ -8,13 +8,15 @@
 #include <string.h>
 
 struct key {
-  char line[1024];
+  char line[4096];
 };
 
 #define SORT_KEY struct key
 #define SORT_PREFIX(x) s_##x
+#define SORT_PRESORT
 #define SORT_INPUT_FILE
 #define SORT_OUTPUT_FILE
+#define SORT_UNIFY
 
 static inline int
 s_compare(struct key *a, struct key *b)
@@ -34,16 +36,53 @@ s_copy_data(struct fastbuf *src UNUSED, struct fastbuf *dest, struct key *k)
   bputsn(dest, k->line);
 }
 
+static inline byte *
+s_fetch_item(struct fastbuf *src UNUSED, struct key *k, byte *limit UNUSED)
+{
+  byte *end = (byte *) k->line + strlen(k->line) + 1;
+#if 0                                  /* Testing splits */
+  uns r = random_max(10000);
+  if (end + r <= limit)
+    return end + r;
+  else
+    return NULL;
+#else
+  return end;
+#endif
+}
+
+static inline void
+s_store_item(struct fastbuf *f, struct key *k)
+{
+  s_copy_data(NULL, f, k);
+}
+
+#ifdef SORT_UNIFY
+static inline void
+s_merge_data(struct fastbuf *src1 UNUSED, struct fastbuf *src2 UNUSED, struct fastbuf *dest, struct key *k1, struct key *k2 UNUSED)
+{
+  s_copy_data(NULL, dest, k1);
+}
+
+static inline struct key *
+s_merge_items(struct key *a, struct key *b UNUSED)
+{
+  return a;
+}
+#endif
+
 #include "lib/sorter.h"
 
 int
 main(int argc, char **argv)
 {
   log_init(NULL);
-  cf_read(DEFAULT_CONFIG);
   if (cf_getopt(argc, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL) >= 0 ||
       optind != argc - 2)
-    die("Usage: sort-test <input> <output>");
+  {
+    fputs("This program supports only the following command-line arguments:\n" CF_USAGE, stderr);
+    exit(1);
+  }
 
   s_sort(argv[optind], argv[optind+1]);
   return 0;