Path: utzoo!mnetor!uunet!husc6!bbn!uwmcsd1!ig!agate!ucbvax!hplabs!hpcea!hpfcdc!hpfelg!jk From: jk@hpfelg.HP.COM (John Kessenich) Newsgroups: comp.lang.c Subject: Re: Fast way to update grids Message-ID: <690005@hpfelg.HP.COM> Date: 1 Feb 88 17:16:37 GMT References: <255@imagine.PAWL.RPI.EDU> Organization: HP Elec. Design Div. -FtCollins Lines: 29 Use an array (it is the fastest know data structure for linear traversal in an aribitrary direction), but take advantage of C's pointer arithmetic. Example: int a[16][16]; #define NO 1 #define SO -1 #define EA 16 #define WE -16 Then if you want to know about a[x][y] neighbors, look at b = &a[x][y]; b + NO; b + SO; b + EA; b + WE; If you are going through the array in some order, the address step may not even be necessary. Also, for addressing, subscript ranges equal to powers of two will yield faster results. Why? They are compiled as << instead of *. -------------- John Kessenich