Re: Rexxtacy



I'd store the lines in an auxiliary area and never move them. Then I'd store and array of pointers contiguously (50,000*4 = 200K) and sort those. This has the advantage that you don't need to assume a maximum line length, and shorter lines require only the storage actually occupied and not some theoretical maximum. Allocate storage for the lines as you read them in chunks which are multiples of 64K.

Mie wrote:
When I'm going to translate a Rexx app to C, I'll have a basic problem
with this parts. The app sorts a text file. It also performs more than
that, e.g. data checks, but I don't have a problem with the difficult
steps... :-)

Such a text file has a header line, followed by XXXXX lines with data.
A line never is longer than 86 bytes, but assuming 96 or 128 bytes per
line is safer. IRL the number of lines is about 50,000 per text file,
200 items*265 weekdays, but the number of items depends on the user.
Nevertheless it's okay to perform all operations in memory, about 6 MB
of RAM isn't that much nowadays.

There's an ugly work-around I do understand, but that involves a file
per item. I'ld like to avoid that, just like I'ld like to avoid using
existing tools. For one because its already a collection of many tools,
and data quality (compared to other os'es) is an important issue.

The Rexx-version uses the simplest bubble sort. The data is reasonably
sorted already, but more important is that I'l understand that better
than a more complex sorting method. Feel free to improve that, but I do
like to see some understandable bubble sort too.

Not explained, but occuring in the Rexx-version: skip emtpy lines, and
skip lines starting with "<" (excluding the header line). Left out: the
obvious fclose()'s, and so on.

So, basicly: how do I store about 50,000 lines in an array of chars,
how do I check the first character of each line, how can I e.g. print
e.g. line number 100, and how do I swap 2 lines?


/* Save the header line (no knowledge problem here) */
CALL LineOut target,LineIn(source)


/* I don't know how to do this _with about 6 MB of data / >stack_ */
count=0
DO WHILE Lines(source)>0
line=Strip(LineIn(source))
IF line<>'' THEN DO
IF Left(line,1)<>'<' THEN DO
count=count+1
line.count=line
END
END
END


/* Bubble sort */
j=1
DO WHILE j<count
k=j+1
IF line.j>line.k THEN DO
temp=line.j
line.j=line.k
line.k=temp
j=0
END
j=j+1
END


/* Append the result to the target file */
DO j=1 TO count
CALL LineOut target,line.j
END j

/* Or, perhaps addressing the same data access-issue: */
SAY line.100



---

.



Relevant Pages

  • [8FOLD] Template #3
    ... "You lead a very eventful life, don't you, Mr. Kidman?" ... lunatics collapsing in the middle of your store... ... threats have some sort of motivation behind them. ...
    (rec.arts.comics.creative)
  • Re: Bad feelings in Wickes
    ... to sort it out. ... insisted that I should approach the exit without the carrier bag, ... test if the machine would beep. ... A few years My brother and I went into a Wicks Store and bought a large ...
    (uk.legal)
  • C 128s ROM socket
    ... sort of a new topic, so I didn't reply to that. ... I've thought about that ROM socket in the C128 a lot and have on occasion ... So I'm hoping to use something on the IEC port to store more ... up trying to read/write to a serial flash ram chip via the user port.. ...
    (comp.sys.cbm)
  • Re: opendir()
    ... as a recursive function. ... I cant simply sort them cos they are not stored using array and if I ... another question here: this by using File::Find can I store the result ...
    (perl.beginners)
  • Re: all this talk of clothing made in china...
    ... USA." and in her store, she's only going to sell items that are made ... and just the sort of person that should think about joining the ... I was brought up by parents (mother, mostly) who instilled me with all ...
    (uk.people.support.depression)