[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

Re[2]: Sample SQR Code - Sorting Arrays




     Tony,

     In response to your post below:

     1) We are all busy - that's why they pay us. If you want to flame a
     member, please post privately. We read this list because we need help
     or want to share ideas .

     2) I for 1 am guilty of flaming innocent people as well. It is we who
     owe them the apology. It is they who feel attacked. I will give you
     the benefit of the doubt (as I hope others on this list have done for
     me) and let this pass as one *very* bad day.

     3) As I have said to others on the list, I believe that the flow of
     'utilities' is a great thing. I always intend to write them but never
     get around to it. For my 2 cents, please share what you will.

     I hope you have a better day,

     Rick


______________________________ Reply Separator _________________________________
Subject: Re: Sample SQR Code - Sorting Arrays
Author:  "tony delia" <tdelia@erols.com> at internet
Date:    10/6/98 1:04 PM


GOPAL,
   Thankyou for your negative response. I am new to the group and
thought I'd share something with people new to SQR. For an SQR Wizard
such as yourself I'm sure there is nothing new or difficult about a
simple sort algorithm - but this is not GOPAL's group! It is a resource
primarily for new SQR programmers. AND I included the Assembler source
because it is "COMMENTED" and has a description of the process - I KNOW
IBM Mainframe Assembler (370) has absolutely nothing to do with SQRW!!!
I'm busy and didn't want to re-type the description - sorry! AND... I
fully understand there are times to use various sort methods
(Quicksort,  Array Sort, Temporary Tables). This illustrates the method
when an array SORT is required - I'm sure everyone already knows the
other methods! And as far as your fix goes ... YOU BROKE IT BY ADDING
'<=' #ARRmax. I don't set #SORTptr to #ARRmax - EVER!!! When I'm
finished comparing element #ARRmax - 1 to #SCANptr (#ARRmax) I'm DONE!!!
With your "FIX" all you've done is set an extra gyration in the process!
Did you read the comments in the Assembler Version??? That's why I put
them there! Not to be overly sensitive but an apology is in order - My
code always works correctly. Look closer next time. I've had to come in
to work PLENTY of times at 3:00am to fix mistakes due to programmers who
"think" they know what they're doing! I APOLOGIZE TO THE GROUP BUT I
FEEL I'VE BEEN ATTACKED!!! I'll stop posting if this is the response I
get! Have a great day.

                           Tony DeLia

Gopal Nandakumar wrote:
>
> Hello,
>
>         The sort method you used is very commonly used method and nothing new
or
> difficult to code.    The following changes have to be made in your code in
> order to make to work correctly:
>
> >begin-procedure Sort-Array
> >
> >let #ARRmax  = #ARRctr
> >let #SORTptr = 0
> >
> >while #SORTptr <= #ARRmax
> >
> >   let #SCANptr = #SORTptr + 1
> >
> >   get $SORTrec $SORTkey $SORTsec -
> >       from ARRdat (#SORTptr) ARRrec ARRkey ARRsec
> >
> >   while #SCANptr <= #ARRmax
>
>         The while statements should have a condition of "<=".
>
>         I do not understand the rationale in using assembler code in SQRW.
One
> of the main selling point for SQR is its independence of Database and
> Platform.   Once we start using assembler code then we loose the
> independence.    If we want to use assembler code we may be better of
> writing programs in assember completely instead of using SQRW.
>
>         It is also very hard to say which SORT routine is best to use.    Almo
st
> in every interface we write in SQRW, a sort routine is used.     We use the
> follwoing rule of thumb:
>
>         1.      If the array size is 300 or less use Quick Sort routine
>         2.      If the array size is 301 - 5000 use Bubble Sort
>         3.      If the array size if over 5000 use Temporary Tables.
>
>         Thanks.
>
> Gopal.
> TCS INC.
> (210) 491 0046
>
> At 01:09 PM 10/2/98 -0400, you wrote:
> >Hello...
> >
> >Since there seems to be some interest in my SQR Tools Site I thought I'd
> >post a small sample. Here is some "snippets" of an Array Sorting
> >Algorithm.
> >I've also included my Assembler Version (Snippets) because I've included
> >comments and a brief narrative of the sorting process within the
> >program.
> >Also, maybe there are some old timers out there learning SQR!
> >The SQR Example sorts an array with a primary key (ARRkey), a secondary
> >key (ARRsec) and has the data stored in ARRrec (I used 1 field for
> >illustrative purposes). SORTptr is the main pointer- SCANptr is the
> >pointer for comparison. Hope nobody minds me posting to the site.
> >
> >
> >                                   -Tony DeLia
> >
> >
> >
> >!**********************************************************************
> >!*                                                                    *
> >!*       MODULE:  SORT EXAMPLE.                                       *
> >!*       AUTHOR:  TONY DELIA.                                         *
> >!*         DATE:  10/02/1998.                                         *
> >!*       SYSTEM:  TD SQR UTILITY SERIES.                              *
> >!*         DESC:  SORTING ARRAYS.                                     *
> >!*                                                                    *
> >!**********************************************************************
> >
> >..
> >..
> >do Define-Array
> >do Load-Array
> >do Sort-Array
> >..
> >..
> >
> >!**********************************************************************
> >!*       Define Array                                                 *
> >!**********************************************************************
> >
> >begin-procedure Define-Array
> >
> >create-array name=ARRdat size=2000 field=ARRrec:char   -
> >                                   field=ARRkey:char   -
> >                                   field=ARRsec:char
> >
> >let #ARRmax = 2000
> >let #ARRctr = 0
> >
> >end-procedure
> >
> >!**********************************************************************
> >!*       Load Array                                                   *
> >!**********************************************************************
> >
> >begin-procedure Load-Array
> >
> >let #ARRctr = 0
> >
> >while 1 = 1
> >
> >   read #mmc-i-no into $rec:200
> >
> >   if #end-file = 1
> >      break
> >   end-if
> >   .
> >   .
> >   put $rec $skey $ssec into ARRdat (#ARRctr) ARRrec ARRkey ARRsec
> >
> >   let #ARRctr = #ARRctr + 1
> >
> >end-while
> >
> >end-procedure
> >
> >!**********************************************************************
> >!*       Sort Array                                                   *
> >!**********************************************************************
> >
> >begin-procedure Sort-Array
> >
> >let #ARRmax  = #ARRctr
> >let #SORTptr = 0
> >
> >while #SORTptr < #ARRmax
> >
> >   let #SCANptr = #SORTptr + 1
> >
> >   get $SORTrec $SORTkey $SORTsec -
> >       from ARRdat (#SORTptr) ARRrec ARRkey ARRsec
> >
> >   while #SCANptr < #ARRmax
> >
> >      get $SCANrec $SCANkey $SCANsec -
> >          from ARRdat (#SCANptr) ARRrec ARRkey ARRsec
> >
> >      if  ($SORTkey > $SCANkey)
> >      or  ($SORTkey = $SCANkey
> >      and  $SORTsec > $SCANsec)
> >
> >          put $SORTrec $SORTkey $SORTsec -
> >              into ARRdat (#SCANptr) ARRrec ARRkey ARRsec
> >
> >          put $SCANrec $SCANkey $SCANsec -
> >              into ARRdat (#SORTptr) ARRrec ARRkey ARRsec
> >
> >          let $SORTrec =  $SCANrec
> >          let $SORTkey =  $SCANkey
> >          let $SORTsec =  $SCANsec
> >
> >      end-if
> >
> >      let #SCANptr = #SCANptr + 1
> >
> >   end-while
> >
> >   let #SORTptr = #SORTptr + 1
> >
> >end-while
> >
> >end-procedure
> >
> >!**********************************************************************
> >
> >Here's the Assembler Version (see comments for description of the
> >above process).
> >
> >         TITLE 'TDSRT - ASSEMBLER SORT TABLE // TONY DELIA'
> >***********************************************************************
> >*                                                                     *
> >*        MODULE:  TDSRT.                                              *
> >*        AUTHOR:  TONY DELIA.                                         *
> >*          DATE:  06/28/90.                                           *
> >*          DESC:  SORT TABLE OF ELEMENTS.                             *
> >*                                                                     *
> >***********************************************************************
> >         .
> >         .
> >***********************************************************************
> >*        SORT TABLE                                                   *
> >***********************************************************************
> >         DC    F'0'                          RETURN ADDRESS SAVE AREA
> >SORT     EQU   *
> >         ST    6,*-4                         SAVE RETURN ADDRESS
> >*
> >         LH    5,SCTR                        LOAD ENTRY COUNT
> >         CH    5,=H'1'                       ONLY 1 ENTRY ???
> >         BE    SORTX                         YES - EXIT SORT ROUTINE
> >*
> >         BCTR  5,0                           DECREMENT ENTRY COUNT BY 1
> >         MH    5,=Y(SLEN)                    MULTIPLY BY ENTRY LENGTH
> >         LA    5,STABLE(5)                   POINT TO LAST ENTRY
> >         ST    5,SLAST                       SAVE LAST ENTRY ADDRESS
> >*
> >         LA    4,STABLE                      INIT LO PTR - 1ST ENTRY
> >         LA    5,SLEN(,4)                    INIT HI PTR - 2ND ENTRY
> >SORTIT   EQU   *
> >         CLC   0(SLEN,4),0(5)                IS LO ENTRY > HI ENTRY ??
> >         BNH   BUMPHI                        NO  - BUMP HI PTR
> >         XC    0(SLEN,4),0(5)                YES - ISOLATE UNIQUE BITS
> >         XC    0(SLEN,5),0(4)                REPLACE LO WITH HI ENTRY
> >         XC    0(SLEN,4),0(5)                REPLACE HI WITH LO ENTRY
> >BUMPHI   EQU   *
> >         LA    5,SLEN(,5)                    BUMP HI POINTER
> >         C     5,SLAST                       HI POINTER PAST LIMIT ??
> >         BNH   SORTIT                        NO  - COMPARE AGAIN
> >BUMPLO   EQU   *
> >         LA    4,SLEN(,4)                    YES - BUMP LO POINTER
> >         LA    5,SLEN(,4)                    RESET HI PTR = LO + 1
> >         C     4,SLAST                       LO POINTER PAST LIMIT ??
> >         BL    SORTIT                        NO  - KEEP SORTING
> >SORTX    EQU   *
> >         L     6,SORT-4                      RESTORE LINK REGISTER
> >         BR    6                             BRANCH ON LINK REGISTER
> >***********************************************************************
> >*                                                                     *
> >*        BUBBLE SORT LOGIC: (LOW VALUES RISE LIKE BUBBLES TO TOP).    *
> >*                                                                     *
> >*        INITIALLY, LO PTR (4) POINTS TO ENTRY 1 AND HI PTR (5) AT 2. *
> >*        LO PTR WILL REMAIN THE SAME UNTIL HI PTR REACHES THE END OF  *
> >*        TABLE. EACH TIME HI PTR MOVES ALONG A COMPARE IS MADE WITH   *
> >*        LO PTR AND ELEMENTS MAY BE SWAPPED. THIS FORCES THE LOWEST   *
> >*        VALUE TO THE BEGINNING OF THE TABLE. THEN LO PTR IS BUMPED   *
> >*        TO THE NEXT ENTRY AND HI PTR IS RESET TO LO PTR + 1 ENTRY.   *
> >*        PROCESS IS THEN REPEATED FORCING THE NEXT LO VALUE TO 2ND    *
> >*        TABLE POSITION. THIS WILL REPEAT ITSELF UNTIL LO PTR HAS     *
> >*        REACHED THE LAST TABLE POSITION. NOTE THAT EACH TIME LO PTR  *
> >*        IS BUMPED, THE PRECEDING ELEMENTS ARE IN SORTED ORDER AND    *
> >*        ARE NO LONGER INCLUDED IN THE SORT PROCESS (TABLE SHRINKS).  *
> >*                                                                     *
> >***********************************************************************
> >         EJECT
> >***********************************************************************
> >*        TABLE                                                        *
> >***********************************************************************
> >SLEN     EQU   2                             TABLE ENTRY LENGTH
> >SLAST    DC    F'0'                          LAST ENTRY ADDRESS
> >SCTR     DC    H'0'                          NUMBER OF TABLE ENTRIES
> >STABLE   DC    100CL2'  '                    2-DIGIT TABLE
> >STABLEX  DC    X'FF'                         END-OF-TABLE MARKER
> >***********************************************************************
> >         END   TDSRT
> >
> >
> >
> >--
> >Tony DeLia
> >AnswerThink Consulting Group
> >PeopleSoft Solutions Practice - Delphi Partners
> >tdelia@erols.com
> >

--
Tony DeLia
AnswerThink Consulting Group
PeopleSoft Solutions Practice - Delphi Partners
tdelia@erols.com