1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
$NetBSD: patch-ac,v 1.1.1.1 2007/01/29 16:40:58 minskim Exp $
4.4BSD's radixsort() is unportable, replace it with slower qsort() for now.
--- main.c.orig 2007-01-26 18:24:41.000000000 +0100
+++ main.c
@@ -249,6 +249,15 @@ void add_string(char *string)
strcpy(strings[nr_of_strings-1], string);
}
+/*
+ * this is for system lacking radixsort() facility for sorting strings effectively
+ * hopefully gcc optimizes this out otherwise
+ */
+int
+pstrcmp (const void *s1, const void *s2)
+{
+ return strcmp (*(u_char **)s1, *(u_char **)s2);
+}
/*
* main():
@@ -296,10 +305,16 @@ int main(int argc, char *argv[])
add_string(s);
}
+#ifdef BSD
printf ("radixsort...\n");
i = radixsort((const u_char **)strings, nr_of_strings, NULL, 0);
if (i)
printf("radixsort result = %i\n", i);
+#else
+ printf ("quicksort...\n");
+ qsort((void *)strings, nr_of_strings, sizeof (u_char *), pstrcmp);
+ printf ("quicksort finished.\n");
+#endif
/* for (i=0; i<nr_of_strings; i++)
printf("strings[%i]: %s", i, strings[i]); */
|