home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!world!jhallen
- From: jhallen@world.std.com (Joseph H Allen)
- Subject: Re: Locating duplicates
- Message-ID: <C07z6L.1Aq@world.std.com>
- Organization: The World Public Access UNIX, Brookline, MA
- References: <C07FJo.4vq@ux1.cso.uiuc.edu> <1993Jan2.041658.21596@organpipe.uug.arizona.edu> <DOUGM.93Jan2014723@titan.cs.rice.edu>
- Date: Sat, 2 Jan 1993 09:18:20 GMT
- Lines: 14
-
- Another way is to use a clash detection table. For each integer apply a
- hash function which returns an integer of about log2(2*size of array) bits.
- Use this as an index into a bit map which is 1/16 the size of the array. If
- the bit is clear, set it. If it's set, you might have a duplicate. Store
- the potential duplicate in some kind of database. Make a second pass
- through the array to verify the duplicates.
-
- This method will approach O(n) if the number of expected duplicates is small
- and if the hash function is good.
- --
- /* jhallen@world.std.com (192.74.137.5) */ /* Joseph H. Allen */
- int a[1817];main(z,p,q,r){for(p=80;q+p-80;p-=2*a[p])for(z=9;z--;)q=3&(r=time(0)
- +r*57)/7,q=q?q-1?q-2?1-p%79?-1:0:p%79-77?1:0:p<1659?79:0:p>158?-79:0,q?!a[p+q*2
- ]?a[p+=a[p+=q]=q]=q:0:0;for(;q++-1817;)printf(q%79?"%c":"%c\n"," #"[!a[q-1]]);}
-