Path: utzoo!censor!geac!jtsv16!uunet!cs.utexas.edu!sun-barr!decwrl!sgi!daisy!cplai From: cplai@daisy.UUCP (Chung-Pang Lai) Newsgroups: comp.lang.postscript Subject: Re: Building A PostScript Toolset Message-ID: <3451@daisy.UUCP> Date: 31 Aug 89 07:29:05 GMT References: <2251@optilink.UUCP> <3965@phri.UUCP> <123996@sun.Eng.Sun.COM> Reply-To: cplai@daisy.UUCP (Chung-Pang Lai) Organization: Daisy/Cadnetix Corp., Mtn. View, CA Lines: 43 This is for your tool set. This routine sorts the dictionary keys and leave them on stack for printing or other purpose. It uses insertion sort. See comment for details. %! % Sort Dictionary key % Stack: Before => After % dict => (keyn) ... (key3) (key2) (key1) n % Dictionary is a hash table, this function is useful when the keys % needed to be printed in increasing order, the results are left on % stack in string datatype. Necessary conversion is needed if used % for other purposes. % Limitation: According to the Red Book, the Operand stack's maximum % depth is 500, this function will fail if the results % overflow the stack. % Written by C.P.Lai Dec 17, 1988 /SortDictKey { % function def /dictcount 1 def { %forall % sort dict keys on operand stack pop % consume the value part % convert Key to string since type is unknown, or else ge may choke 80 string cvs % leave each key in a unique string on stack dictcount -1 2 {% for dup /dictindex exch def % save index of key being checked 1 index exch % copy latest key for ge index % use dictindex to get compare key for ge ge {dictindex 1 roll exit} if % insert into place } for % check from the already sorted high end /dictcount dictcount 1 add def } forall % standard insertion sort algorithm dictcount 1 sub % leave final count on stack } def % DEMO % yourdictionary SortDictKey { % show newline % } repeat -- .signature under construction ... {pyramid, osu-cis, uunet, killer}!daisy!cplai C.P. Lai cplai%daisy.UUCP@uunet.UU.NET cplai%daisy@killer.DALLAS.TX.USA Daisy Systems Corp, 700B Middlefield Road, Mtn View CA 94039. (415)960-6961