🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #50022

Re: Threading algorithm

#50022
From: Curt Welch
Date: Wed, 21 Jul 1999 00:00
60 lines
3550 bytes
"Matthias Jordan" <mjordan@sensenet.wirepool.free.de> wrote:
> Hi, Curt!
>
> >> moment it works really great so I decided to implement threading. I
> >> hacked a quick-and-dirty algorithm together but it has complexity
> >It would really help if you told us what the algorithm did.

Oh, I see :).  For some reason I thought "threading" meant process
treads of some type.  And now after sticking my foot in my mouth
I guess I have to answer you :)...

> It sorts newsgroup articles by thread. In this particular case by use
> of the References header line. My current algorithm works like this:
>
> For every new article to insert into a newsgroup do this: If the new
> article has a References line, see whether there is the original
> article the new article refers to. If so, insert the new article
> behind the original one.

Threading is a bit more complex than that.  You have to deal with missing
articles.  For example, articles B and C both refer to A, but A is gone.
In this case, B and C should still end up together (even if they have
different subjects).

Also, do you just use the last ID on the References: line or do you
use all of them?  You should use all of them.  i.e., if the last one
doesn't turn up a thread to attach the current article to, then try
the next one, etc.

So are you doing something gross like a linear search of the current
list to find the old article?  If, so I could see where that would kill
you.

You either build a big list of message IDs and sort it with a real
sort algorithm (n log n instead of n^2), or you build some type of
structure to index the message-ids quckly back to the threads they
are associated with.  Something like a hashed array of linked lists
is what I like to use.  Various types of b-trees work fine as well.

For each article, you take all the message-IDs in the references
and the articles own message-ID and look them up in this index to
see if any of the ids are allready associated with one or more threads.

If more than one thread comes up, then you need to combine the two
threads together.  If nothing comes up, then you start a new thread.

But in all cases you add all the message-ids from this new article
to the index if they are not already there.

If you have enough memory to do all this and create the right index
then it behaves more like O(n) to do the threading where n is the number of
Message-IDs you have to deal with - then you have to sort the threads
(internally and externally), and those are a bunch of standard n log n
sorts.

-- 
Curt Welch                                            http://CurtWelch.Com/
curt@kcwc.com                          Webmaster for http://NewsReader.Com/

Technical Details
Message-ID: <19990721185421.427$Xb@newsreader.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
References: <3796119b$0$216@nntp.ruhr.de> <19990721144534.708$be@newsreader.com> <37964124$0$217@nntp.ruhr.de>

Show Full Headers
Complete Article Headers
Message-ID: <19990721185421.427$Xb@newsreader.com>
Subject: Re: Threading algorithm
Date: Wed, 21 Jul 1999 00:00:00 +0000
From: curt@kcwc.com (Curt Welch)
References: <3796119b$0$216@nntp.ruhr.de> <19990721144534.708$be@newsreader.com> <37964124$0$217@nntp.ruhr.de>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
X-Deja-AN: 503723537
X-Face: "p}G*1KH{+F7EYGKLb>ogDguabZ+%,?^epeFB!nzu`)`$=QcvL1KF6<0GH!Tbc!Sqo[|tV5 %IW48mQf3K=Ci&gZ7]]aazx@]Y-nq!r5{yH/#,?@lDdUDvOfByB2hVW0.@OM%{l/{cT'{w
X-User: Curt@NewsReader.Com
Organization: NewsReader.Com
X-Url: http://CurtWelch.Com/
Newsgroups: news.software.readers