|
> -----Original Message----- > From: Peter Dow [mailto:pcdow@yahoo.com] > Sent: Monday, December 13, 1999 3:40 PM > To: RPG400-L@midrange.com > Subject: Re: New RPG Redbook (was Sub Files). > > > Fascinating -- Chapter 5 section 1 is "User exit programs" on > the version I > got. And the Index only has entries for E, Q, and W. I must somehow be > getting the wrong version, although it says its SG24-5402-00 -- > http://www.redbooks.ibm.com/SG245402/sg245402.pdf > > > Here's a test program I wrote last year to play with qsort(). Don't vouch for the quality or style. It loads an array with 10,000 values and sorts it 100 times. I wouldn't be surprised if there weren't some ways to improve it. The key to the use of qsort() and the C library binary search is the comparison function passed in as a function pointer. This is what makes the function generic. Qsort() calls the comparison function(procedure) and acts on the return value. I may have set up my bench mark incorrectly, but I found quick sort over this data isn't significantly faster than sorta (a Shell sort.) The C library binary search is so much quicker than lookup (a linear search) that it's frightening. H OPTION( *SrcStmt: *NoDebugIO) Fhftrap if e disk Dsortit pr extproc('qsort') Darrbase * value Delements 10u 0 value Dsize 10u 0 value Dcompfunc * procptr value D Dcompfunc pr 9b 0 Dlookfor * value Darrelt * value Darray s 7 dim(10000) Dstoreroom s like(array) dim(10000) Dx s 5u 0 Darrsize s 10u 0 Dnumelems s like(arrsize) Dfnptr s * procptr Darrptr s * D C eval arrsize = %size(array) C eval numelems = %elem(array) C eval fnptr = %paddr('COMPFUNC') C eval arrptr = %addr(array) C* Load up the array of test stuff C do 10000 x C read rtrn 99 C eval storeroom(x) = trsr C enddo C* Sort it 100 times C do 100 x C movea storeroom array C callp sortit(arrptr : numelems : C arrsize : fnptr ) C enddo C eval *inlr = *on P* #################################################################### Pcompfunc b D pi 9b 0 Dlookfor * value Darreltptr * value Dkey s 7 based(lookfor) Darrelt s 7 based(arreltptr) C select C when key < arrelt C return -1 C when key > arrelt C return 1 C when key = arrelt C return 0 C endsl Pcompfunc e I offer this as an example of prototyping C library functions. I don't claim that this is the best way to do it. Or, as my standard disclaimer says: ########################################### The above is my personal opinion and is not intended to represent good programming practice or the product of a sound mind. Joel Fritz +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.