Re: Combining single-key sorts to form concatenated-key sort

From: Kristian Damm Jensen <kristian-Damm.Jensen_at_REMOVEcapgemini.dk>
Date: Mon, 05 Feb 2001 06:58:28 +0100
Message-ID: <3A7E4104.83B8241_at_REMOVEcapgemini.dk>


Brian Inglis wrote:
>
> On 3 Feb 2001 06:51:48 -0000, Frog2
> <FrogRemailer_at_NoReply.Invalid> wrote:
>
> >I'm trying to sort some records. Each record consists of three data fields I wish to use
> >as a concatenated key for sorting purposes and some detail fields. All three key fields
> >are alphanumeric. All key fields in every record will always contain a value (no NULLs).
> >
> >Here's the problem: the language I'm using has a sort function but that function will
> >only let me sort on *one* field of my choice, not all three at once. So how can I achieve
> >a primary - secondary - tertiary sort of these records. Presumably there's some scalable
> >way to sort/merge each lower key with the key above it (or perhaps the reverse, sort from
> >primary key down to lowest-order key).
> >
> >What I've come with so far is make a list of each key field's unique values
> > unique_p , unique_s, unique_t
> >sorted in the order I want. But then how could I use these to extract the records in
> >correct overall sorted order?

<snip>

> Sort by least significant key field, and so on up to most
> significant key field. Think about whay it works.

And pray that the sort is stable. Otherwise it will not work.

--
Kristian Damm Jensen              | Feed the hungry. Go to 
kristian-damm.jensen_at_capgemini.dk | http://www.thehungersite.com
Received on Mon Feb 05 2001 - 06:58:28 CET

Original text of this message