🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #12597

Re: % in hash table

#12597
From: Mike Haertel
Date: Wed, 04 Oct 1995 00:16
20 lines
1569 bytes
In article <jgkDFv094.JKJ@netcom.com>, Joe Keane  <jgk@netcom.com> wrote:
>Whenever i find some important hash table, one of the changes that i make is:
>Take out that stupid `%' operator!
>
>People that don't have low-level knowledge of machines don't realize how slow
>that remainder operation is.  Of course, it depends on the machine, so it can
>range from rather slow to extremely slow.  With no exaggeration, a good hash
>table can do several lookups in the time it takes to compute one remainder.

Time required for % also depends on the modulus.  Remainders modulo 2^n, for
example, are really easy to compute.  Good compilers take advantage of this
whenever the modulus is known at compile time.

People who do hashing usually like primes.  There are some primes of the
form 2^n +- 1; remainders modulo such primes still do not require the full
force of a fully general remainder routine.  Most compilers I've seen do not
optimize this case, but they could--it's only a couple extra shifts and
adds over mod 2^n.
--
Mike Haertel <haertel@ichips.intel.com>
Technical Details
Message-ID: <44sjp4$c71@news.jf.intel.com>
Path: arc1-ca.pugleaf.net!news.jf.intel.com!haertel
References: <43tqr6$3au@mikasa.iol.it> <44c0gk$jq4@blather.cs.cornell.edu> <DFLzD9.Anx@uns.bris.ac.uk> <jgkDFv094.JKJ@netcom.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.jf.intel.com!haertel
From: haertel@ichips.intel.com (Mike Haertel)
Newsgroups: comp.arch,comp.arch.arithmetic,comp.lang.c
Subject: Re: % in hash table
Date: 4 Oct 1995 00:16:36 GMT
Organization: Intel Corporation, Hillsboro, Oregon, USA
Message-ID: <44sjp4$c71@news.jf.intel.com>
References: <43tqr6$3au@mikasa.iol.it> <44c0gk$jq4@blather.cs.cornell.edu> <DFLzD9.Anx@uns.bris.ac.uk> <jgkDFv094.JKJ@netcom.com>
NNTP-Posting-Host: pdx404.intel.com
Keywords: hash