🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: demon.ip.developers
Article #129

Re: Newshistory checking

#129
From: Chris Croughton
Date: Wed, 14 Jul 1999 00:00
36 lines
2033 bytes
On Tue, 13 Jul 1999 21:05:00 +0100 (BST), Terrance Richard Boyes 
   <tez@pierrot.co.uk> wrote:

>I'm looking for an efficient way to check for duplicate Message-IDs
>in a large NewsHistory file against the output of NEWNEWS (or XOVER
>after extracting the Message-ID).

>As in those languages it's much quicker than scanning through
>an array.
>
>Any thoughts on the best way to do it in C ?

The way I'd do it would be to read in the file, in file order, then use
qsort (ANSI C routine) to sort it (or rather sort an array of pointers
to the strings) and then use bsearch to find them.  You don't need to
add the new IDs to the list as they come in, as they should be unique
anyway among themselves.

>NB a pointer to some source what I want will do just as well as
>a detailed answer ;)

If you want a general facility for adding elements to a database and
searching quickly, have a look for packages called btree and ctree.
These maintain a database in "balanced tree" style, so that the lookup
time is proportional to log(n) (n is number of elements in the
database).  There used to be at least one implementation which was
public domain generic C source.

Alternatively (my favourite solution), use C++ where the map class is
explicitly designed for that sort of thing.  However, it's a relatively
recent addition to C++ (in the last couple of years) and older C++
compilers didn't always have it implemented.

HTH

Chris C
Technical Details
Message-ID: <slrn7oo9bq.j5g.chris@ccserver.keris.org>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <19990713.200500.0AA80202.PEaa@pierrot.co.uk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10bb05,75d5f9974c0fd91a
X-Google-Attributes: gid10bb05,public
From: chris@keris.demon.co.uk (Chris Croughton)
Subject: Re: Newshistory checking
Date: 1999/07/14
Message-ID: <slrn7oo9bq.j5g.chris@ccserver.keris.org>
X-Deja-AN: 500818581
References: <19990713.200500.0AA80202.PEaa@pierrot.co.uk>
X-Original-NNTP-Posting-Host: 194.112.32.19
X-Trace: reader.news.dircon.net 931932004 26082 194.112.32.19
Organization: Keristor Systems
User-Agent: slrn/0.9.5.3 (UNIX)
Newsgroups: demon.ip.developers