Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Efficient coding considered harmful? Message-ID: <8819@smoke.BRL.MIL> Date: 2 Nov 88 17:36:22 GMT References: <3105@hubcap.UUCP> <34112@XAIT.XEROX.COM> <1700@dataio.Data-IO.COM> <8630@smoke.ARPA> <1704@dataio.Data-IO.COM> <119@twwells.uucp> <7700@bloom-beacon.MIT.EDU> <137@twwells.uucp> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 16 In article <137@twwells.uucp> bill@twwells.UUCP (T. William Wells) writes: >#define HASHSIZE 4 /* A power of two, or else! */ To continue my complaint against using bitwise operators where arithmetic is called for, let me point out that most reasonable hashing schemes work best of the hash table size is NOT a power of two. Now, if you had used arithmetic instead of bit-diddling throughout your hashing code, most likely a programmer could change HASHSIZE to some useful number like 113 and that would be all it would take to improve the hashing scheme. On the other hand, your code would force him to either use 128 (and obtain suboptimal performance), or else go through the code and try to put it back in the shape it should have had from the outset. Again, this is a case that any decent compiler would have been able to handle just as well if you had used division and remainder operators. The trickery is not only unnecessary, but (as I said previously) it gets in the way of code reliability and maintainance.