🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.hypercube
Article #16

Re: T or routing question

#16
From: grunwald
Date: Thu, 16 Jul 1987 13:11
43 lines
1417 bytes
The following program contains functions to compute one of many grey codes
and the inverse function for that grey code.

The loop would be defined as grey(0), grey(1), ...., grey(N-1) for N nodes.
If each node was 'nodeNumber', then you can define: 

#define wrap(x,y,z) ( (x) < y ? y : ( ( (x) > z ) ? z : x ))

	gNode = grey(nodeNumber)
	leftNode = greyinv( wrap(gNode-1, 0, N-1) );
	rightNode = greyinv( wrap(gNode+1, 0, N-1) );

'wrap' simply servers to keep the node numbers in the range 0..N-1. More
complicated structures.

main()
{
    int i;
    for (i = 0; i < 8; i++) {
	printf("%3d: [%3d, %3d] [%3d,%3d]  [%3d, %3d]\n",
	       i,
	       grey(i-1), invgrey(grey(i-1)),
	       grey(i), invgrey(grey(i)),
	       grey(i+1), invgrey(grey(i+1)));
    }
}

grey(i)
int i;
{
    return (i >> 1) ^ i;
}

invgrey(i)
int i;
{
    int j = i;
    do {
	j = ( j >> 1 );
	i ^= j;
    } while (j != 0);
    return(i);
}
Technical Details
Message-ID: <308@hubcap.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!seismo!gatech!hubcap!grunwald

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!seismo!gatech!hubcap!grunwald
From: grunwald@M.CS.UIUC.EDU
Newsgroups: comp.hypercube
Subject: Re: T or routing question
Message-ID: <308@hubcap.UUCP>
Date: Thu, 16-Jul-87 09:11:27 EDT
Article-I.D.: hubcap.308
Posted: Thu Jul 16 09:11:27 1987
Date-Received: Sat, 18-Jul-87 06:41:58 EDT
Sender: fpst@hubcap.UUCP
Lines: 43
Approved: hypercube@hubcap.clemson.edu