Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/sort for stable sort, arrange so that really only re...
details: https://anonhg.NetBSD.org/src/rev/7f703a42b653
branches: trunk
changeset: 502159:7f703a42b653
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Fri Jan 12 19:39:02 2001 +0000
description:
for stable sort, arrange so that really only relevant part of line
is used for sort - this makes sort pass regression test number 36
while here, slighly adjust code formating on couple of places
diffstat:
usr.bin/sort/fields.c | 44 +++++++++++++++++++++++++++-----------------
1 files changed, 27 insertions(+), 17 deletions(-)
diffs (117 lines):
diff -r 1c343add6967 -r 7f703a42b653 usr.bin/sort/fields.c
--- a/usr.bin/sort/fields.c Fri Jan 12 19:38:46 2001 +0000
+++ b/usr.bin/sort/fields.c Fri Jan 12 19:39:02 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fields.c,v 1.4 2000/10/17 15:13:40 jdolecek Exp $ */
+/* $NetBSD: fields.c,v 1.5 2001/01/12 19:39:02 jdolecek Exp $ */
/*-
* Copyright (c) 1993
@@ -41,7 +41,7 @@
#include "sort.h"
#ifndef lint
-__RCSID("$NetBSD: fields.c,v 1.4 2000/10/17 15:13:40 jdolecek Exp $");
+__RCSID("$NetBSD: fields.c,v 1.5 2001/01/12 19:39:02 jdolecek Exp $");
__SCCSID("@(#)fields.c 8.1 (Berkeley) 6/6/93");
#endif /* not lint */
@@ -56,9 +56,8 @@
while (!((FLD_D | REC_D_F) & l_d_mask[*++pos])); \
}
-extern u_char *enterfield __P((u_char *, u_char *, struct field *, int));
-
-extern u_char *number __P((u_char *, u_char *, u_char *, u_char *, int));
+static u_char *enterfield __P((u_char *, u_char *, struct field *, int));
+static u_char *number __P((u_char *, u_char *, u_char *, u_char *, int));
extern struct coldesc clist[(ND+1)*2];
extern int ncols;
@@ -80,7 +79,7 @@
struct recheader *keybuf; /* pointer to start of key */
DBT *line;
int size;
- struct field fieldtable[];
+ struct field *fieldtable;
{
int i;
u_char *l_d_mask;
@@ -120,12 +119,22 @@
fieldtable->flags)) == NULL)
return (1);
- if (UNIQUE)
- *(keypos-1) = REC_D;
keybuf->offset = keypos - keybuf->data;
+
+ /*
+ * Make [s]radixsort() only sort by relevant part of key if:
+ * 1. we want to choose unique items by relevant field[s]
+ * 2. we want stable sort and so the items should be sorted only by
+ * the relevant field[s]
+ */
+ if (UNIQUE || (stable_sort && keybuf->offset < line->size))
+ keypos[-1] = REC_D;
+
keybuf->length = keybuf->offset + line->size;
- if (keybuf->length + sizeof(TRECHEADER) > size)
- return (1); /* line too long for buffer */
+ if (keybuf->length + sizeof(TRECHEADER) > size) {
+ /* line too long for buffer */
+ return (1);
+ }
memcpy(keybuf->data + keybuf->offset, line->data, line->size);
return (0);
}
@@ -133,7 +142,7 @@
/*
* constructs a field (as defined by -k) within a key
*/
-u_char *
+static u_char *
enterfield(tablepos, endkey, cur_fld, gflags)
struct field *cur_fld;
u_char *tablepos, *endkey;
@@ -157,18 +166,19 @@
else {
if (tcol.indent) {
end = tcol.p->start;
- if (flags & BT) blancmange(end);
+ if (flags & BT)
+ blancmange(end);
end += tcol.indent;
end = min(end, lineend);
} else
end = tcol.p->end;
}
+
if (flags & N) {
Rflag = (gflags & R ) ^ (flags & R) ? 1 : 0;
- tablepos = number(tablepos, endkey, start, end, Rflag);
- return (tablepos);
+ return number(tablepos, endkey, start, end, Rflag);
}
- mask = alltable;
+
mask = cur_fld->mask;
lweight = cur_fld->weights;
for (; start < end; start++)
@@ -181,7 +191,7 @@
} else {
*tablepos++ = lweight[*start];
if (tablepos == endkey)
- return (NULL);
+ return (NULL);
}
}
*tablepos++ = lweight[0];
@@ -201,7 +211,7 @@
* Reverse order is done analagously.
*/
-u_char *
+static u_char *
number(pos, bufend, line, lineend, Rflag)
u_char *line, *pos, *bufend, *lineend;
int Rflag;
Home |
Main Index |
Thread Index |
Old Index