[comp.sys.mac.hypercard] Sorting Efficiently

mlloyd@maths.tcd.ie (Michael Lloyd) (03/11/89)

This is a rather esoteric one, I reckon, and will probably require fairly
in-depth knowledge of sorting.

A friend is developing a large bibliographic stack - by large, I mean ~700
cards thus far, with no end in sight.  When references are added, they are
done via New Card at the end of the stack.  After an adding session, they have
to be inserted alphabetically into the card order - hence a sort command.

My question is, as this sort takes long enough to be VERY irritating (it needs
doing very often), would there be any better place to create new cards?  I
might (wildly) guess that cards created at the START of the stack might speed
up the process - this could happen if the cards are treated in order when
sorts go into action.

Anyone got anything to say?

I have a few other equally obscure queries which I might circulate if I get
any joy on this one.

Thanks,

Mike.

Mike Lloyd, Dept of Statistics, |
Trinity College, Dublin,        |      "COGITO, ERGO CHICO & ZEPPO"
Ireland.                        |          Tonio K.
(mlloyd@maths.tcd.ie)           |

jgreely@diplodocus.cis.ohio-state.edu (J Greely) (03/13/89)

In article <670@maths.tcd.ie> mlloyd@maths.tcd.ie (Michael Lloyd) writes:
>A friend is developing a large bibliographic stack - by large, I mean ~700
>cards thus far, with no end in sight.  When references are added, they are
>done via New Card at the end of the stack.  After an adding session, they have
>to be inserted alphabetically into the card order - hence a sort command.

Why not insert them into the correct position when they're created?
In a "New Card" button, ask for the Index field, do a binary search
to find the correct insertion position, create the card, and go.
If you trap doMenu, you can guarantee that all new cards will be
inserted in order.  If you get stumped on the scripting, let me know,
and I'll send you a sample script/stack.

-=-
J Greely (jgreely@cis.ohio-state.edu; osu-cis!jgreely)

dan@Apple.COM (Dan Allen) (03/14/89)

In article <670@maths.tcd.ie> mlloyd@maths.tcd.ie (Michael Lloyd) writes:
>My question is, as this sort takes long enough to be VERY irritating (it needs
>doing very often), would there be any better place to create new cards?  I
>might (wildly) guess that cards created at the START of the stack might speed
>up the process - this could happen if the cards are treated in order when
>sorts go into action.

If you want to always keep a stack in sorted order, sort in once and
then do the following whenever you want to insert a new card: do a
binary search and then do a New Card.  The New Card will be placed after
the current card.

Adding cards to the beginning of a stack or end of a stack should not
matter that much.  Cards are actually kept in a somewhat arbitrary order
on disk.  (Compact stack will actually reorganize them to allow scanning
through a stack to be as fast as possible.)

A different problem is growing an existing card.  Let's say that you
frequently add text to the first card in a stack.  The card will no
longer fit where it was, so it will probably be moved to the end of the
stack on disk, and the file will be grown.  The card's former location
will be empty and will be used the next time something can fit in the
hole that was left.

Dan Allen
Apple Computer