Difference between revisions of "LT.c"

From Organic Design wiki
m
(fix highlighting)
 
Line 1: Line 1:
<c>// Start at subject listItem and traverse the key as an association to a new listItem
+
<source lang="c">
 +
// Start at subject listItem and traverse the key as an association to a new listItem
 
// - key is also a listItem reference and its binary address is used as the traversal path
 
// - key is also a listItem reference and its binary address is used as the traversal path
 
// - subject and key (all list-item references are ints starting at item 0)
 
// - subject and key (all list-item references are ints starting at item 0)
 
// - if key is 0 the subject is returned unchanged, key 1 and 2 are the two single-iteration traversals
 
// - if key is 0 the subject is returned unchanged, key 1 and 2 are the two single-iteration traversals
 
item listTraverse(item subject, item key) {
 
item listTraverse(item subject, item key) {
if (key++ > 0) {
+
if(key++ > 0) {
 
int i,j;
 
int i,j;
for (i = 1; i <= key >> 1; i <<= 1) {
+
for(i = 1; i <= key >> 1; i <<= 1) {
 
j = subject * 3;
 
j = subject * 3;
if (key & i) j++;
+
if(key & i) j++;
if (space[j] == 0) space[j] = listInsert();
+
if(space[j] == 0) space[j] = listInsert();
 
subject = space[j];
 
subject = space[j];
 
}
 
}
 
}
 
}
 
return subject;
 
return subject;
}</c>
+
}</source>

Latest revision as of 00:00, 26 May 2016

// Start at subject listItem and traverse the key as an association to a new listItem
// - key is also a listItem reference and its binary address is used as the traversal path
// - subject and key (all list-item references are ints starting at item 0)
// - if key is 0 the subject is returned unchanged, key 1 and 2 are the two single-iteration traversals
item listTraverse(item subject, item key) {
	if(key++ > 0) {
		int i,j;
		for(i = 1; i <= key >> 1; i <<= 1) {
			j = subject * 3;
			if(key & i) j++;
			if(space[j] == 0) space[j] = listInsert();
			subject = space[j];
		}
	}
	return subject;
}