🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #64519

Re: Newsreader programming - sorting one million lines ?

#64519
From: Heiko Studt
Date: Tue, 25 Mar 2003 12:08
104 lines
5532 bytes
Juergen Helbing did nothing on 25.03.2003 07:08:53:

> >Then you save *everything*.
> Yes, I'm having all Xover-headers in a single file.

Ok.

> >You save every XOver(?)-Line in one line in a "Direktzugriffs"-file.
> >(In a kind of form you like)
> >Now you save a pointer to the beginning of the line in a
> >fixed-width-record-file.
> This is already my actual structure.

To go further: Save the things to sort in a different file, or something like
that.

> >Now you load 10 chars from all subjects to memory and save the index of it.
> >Therefor you can use a sorted stringlist. (AFAIK sorting by including is
> >fastest, isn't it?). After all you have a pre-sorted list where you have to
> >resort all "similar" things with full-width subject, date and so on.

> This sounds reasonable and I remember the "5 tape sorting"
> from the 50's :-) Reading the entire file once for presorting
> and making 'small range sorting' on a smaller file-portion
> sounds also good. But there seems to be one big problem:

Those are tow different things:
1 Sort to Ranges, goto 1 til all are sorted

Presort into smaller Ranges, on demand get the "samelooking" into memory 
and sort them with Bubble/Heap-Sort.

If you use the second one you would have a *sorted* index-file and an unsorted.
The unsorted is used to access to different items for sorting.
The same things can be done for threading:

XOver.txt      All XOvers are saved
XOver.idx      Begin of every line is saved by index (0..n)
Threading.idx  For every item the parent is saved and the index in XOver.idx
Sorted.idx     Based on XOver.idx or direct for XOver.txt, sorted.
               The 10 chars used for presorting are saved too.

As you load the 'old' datas you load Sorted.idx and sort it with bubble-sort
again (or otherwise: the best sorting algo for presorted lists)

For being sure you can also try to rebuild XOver.idx before and look if it's
the same as the old file.

Now you load new XOvers, save the *new* XOver at the end of XOver.txt, save
the pointer to XOver.idx and now sort into sorted.idx. If you need to you sort
it into Threading too.


Now, on screen, you want to show a new line: You load the complete XOvers of
those lines you show and those which have the same sorting-10-chars. Now you
can sort *these* in a complete way (subject, Date, else) and save the sorting
to the .idx-file. As you showed every line in your reader you have sorted the
complete XOver-list. As you use Bubble sort for this smaller Ranges, you would
have a good presorting-algo to not waste too much performance.

> The "small range sorting" requires access across the entire
> file (The similar subject is used everywhere within one gig
> of headers). And these disk-accesses are very slow....

Why? You *only* need to get for every XOver the sort-string. This has to be
done in *any* algorithmic as best as this would be. After that you would have
a well-presorted list you can sort on demand. If you use Threading you would
even be able to have a less-sorting.

BTW: If you use Delphi: VirtualTreeview is genious fast, even for sorting.

> >This is a smaller solution in Delphi:
> >      tsl.AddObject(GetSortingItems(s), tObject(temI));

> The "GetSortingItems(s)" seems to include an 
> "fseek(randompostion-within-fullfile)"... and this is

No.
You get the XOver line by line. In *any* case.
Now you can parse this line to get the things you need for sorting (10 chars).

> used 1e6 times....  Having a fast disk with 1 mSec 
> access to every item would still need 1000 seconds....

A fast disc should AFAIK even be faster... ;-P
But you didn't understand me. I want to sort *while* loading the XOvers. BTW:
You have anyway the problem of loading the XOvers out of disk. This can't be
prevented in any kind you want to try.

> Obviously the required time for "external sorting" is
> not acceptable.....

Do you want to save the real XOver to disc afterwards or not? Perhaps I didn't
understand. As this complete discussion is OT, I set a F'up2:Poster. Perhaps a
German-Mailcontact would be less misunderstandable


MFG

-- 
Heiko Studt
http://www.goldpool.org/temp/IMAPHamster.zip 20.3.2003 24:00

Technical Details
Message-ID: <b5pkd8.1kg.1@Heiko.Studt.dialin.t-online.de>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.stueberl.de!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail
References: <4540d.o33203@archiver.winews.net> <b5nnpr.180.1@Heiko.Studt.dialin.t-online.de> <53087.p33205@archiver.winews.net>

Show Full Headers
Complete Article Headers
Message-ID: <b5pkd8.1kg.1@Heiko.Studt.dialin.t-online.de>
Subject: Re: Newsreader programming - sorting one million lines ?
Date: Tue, 25 Mar 2003 13:08:56 +0100
From: Heiko Studt <UsenetBecky@goldpool.org>
References: <4540d.o33203@archiver.winews.net> <b5nnpr.180.1@Heiko.Studt.dialin.t-online.de> <53087.p33205@archiver.winews.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.stueberl.de!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail
Newsgroups: news.software.nntp
Followup-To: poster
Organization: HSR
Lines: 103
Reply-To: Heiko.Studt@gmx.de
Mime-Version: 1.0
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-Trace: news.t-online.com 1048595689 05 26322 dXwtEBDGSPYjhB 030325 12:34:49
X-Complaints-To: abuse@t-online.com
X-ID: rZRE-0ZZoeDPpDUwUgR0TRwOJvbjpElcSlvSkVwMSqie2LtUU7pzEh
X-Mailer: Becky! ver. 2.05.10 with BkNews Plug-In ver. 2.0
User-Agent: Hamster-Pg/1.8