home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!nntp-server.caltech.edu!toddpw
- From: toddpw@cco.caltech.edu (Todd P. Whitesel)
- Newsgroups: comp.programming
- Subject: Re: Modulo n arithmetics
- Date: 17 Nov 1992 11:17:53 GMT
- Organization: California Institute of Technology, Pasadena
- Lines: 19
- Message-ID: <1eakd1INNg8d@gap.caltech.edu>
- References: <92-11-029@comp.compilers> <92-11-043@comp.compilers> <92-11-078@comp.compilers>
- NNTP-Posting-Host: sandman.caltech.edu
- Keywords: arithmetic
-
- wendt@CS.ColoState.EDU (alan l wendt) writes:
-
- >If the algorithm maintains the queue head pointer and the queue length,
- >instead of head and tail, the two cases can be disambiguated easily!
-
- Sorry if this is nitpicking, but if your length ranges from 0..2^N and you
- want to store the length in a bitfield or packed subrange for some reason,
- you need to be careful. Thankfully, this is not much of a problem anymore
- (except on 8 bit embedded systems and such), but it is easy to solve:
-
- >Horowitz & Sahni (Fundamentals of Computer Algorithms) suggest that one
- >might maintain an additional boolean to disambiguate the two situations,
-
- If you use _two_ booleans, you get mutual exclusion for free. It's been
- a while since I worked it out though, so I'd have to dig up my notes to
- remember the whole algorithm. I do remember that it is fairly symmetric.
-
- Todd Whitesel
- toddpw @ cco.caltech.edu
-