Difference between revisions of "Binary traversal"
(It may be possible to make traversal work as a Patricia trie) |
|||
Line 1: | Line 1: | ||
− | + | == Associations == | |
− | + | {{:association}} | |
− | = | + | == Making a unique bit sequence from a node index == |
− | |||
− | |||
− | = Making a unique bit sequence from a node index = | ||
The [[node]]s of a [[node space]] are all identified by an [[node references|integer index]] which starts at 0 for the first element created (the [[root|root node]]), and 1 for the next and so on. All integers can be represented as a unique binary sequence which allows them to all exhibit an address based on a unique path, this kind of data structure is called [[Wikipedia:Trie|trie]]. here is a table showing some integers and their binary and path representations: | The [[node]]s of a [[node space]] are all identified by an [[node references|integer index]] which starts at 0 for the first element created (the [[root|root node]]), and 1 for the next and so on. All integers can be represented as a unique binary sequence which allows them to all exhibit an address based on a unique path, this kind of data structure is called [[Wikipedia:Trie|trie]]. here is a table showing some integers and their binary and path representations: | ||
− | + | {{code|1= | |
<table border=0 width=100> | <table border=0 width=100> | ||
Line 63: | Line 60: | ||
<td style="text-align:right;">1-0-0-0-0-0-0-0-0-0 | <td style="text-align:right;">1-0-0-0-0-0-0-0-0-0 | ||
− | |||
</table> | </table> | ||
+ | }} | ||
Both the decimal and the binary numbers really have an infinite number of leading zeros before them, but we can still maintain a unique sequence of digits to represent every integer even if we omit all leading zeros as we have in this table. The point is that this rule means that every single number except for 0 always ends with a non-zero digit (numbers are read from right to left). While this may not be of much interest for most number systems, you will notice that with binary it means that every number except zero ends with a 1 - and if we forget about the two first items in the list, then we could drop the last bit altogether. As can be seen from the ''Nodal Path'' column in the list, that's exactly what we do in path traversal. This can't usually work with normal numeric data types because ''0'' and ''00'' evaluate to the same, but a ''sequence'' of binary digits is more like a string comparison of ''"0"'' and ''"00"''. | Both the decimal and the binary numbers really have an infinite number of leading zeros before them, but we can still maintain a unique sequence of digits to represent every integer even if we omit all leading zeros as we have in this table. The point is that this rule means that every single number except for 0 always ends with a non-zero digit (numbers are read from right to left). While this may not be of much interest for most number systems, you will notice that with binary it means that every number except zero ends with a 1 - and if we forget about the two first items in the list, then we could drop the last bit altogether. As can be seen from the ''Nodal Path'' column in the list, that's exactly what we do in path traversal. This can't usually work with normal numeric data types because ''0'' and ''00'' evaluate to the same, but a ''sequence'' of binary digits is more like a string comparison of ''"0"'' and ''"00"''. | ||
Line 70: | Line 67: | ||
In the actual implementations of the ''listTraverse'' function, a multiplication by three must also occur to account for the fact that [[list item]]s are groups of three [[node references]]. | In the actual implementations of the ''listTraverse'' function, a multiplication by three must also occur to account for the fact that [[list item]]s are groups of three [[node references]]. | ||
− | = Zero length traversal = | + | == Zero length traversal == |
In the table above showing the conversion of integer [[node references]] into binary paths, we see that the first two indexes, 0 and 1 both translate to a null path which involves no traversal at all, and then index 2 and 3 translate to the paths of "0" and "1" which involve a single iteration of traversal. In the actual implementations of the ''listTraverse'' function an addition of 1 occurs before translation to a binary sequence so that only index 0 results in no traversal, and indexes 1 and 2 result in the two single iteration traversals. | In the table above showing the conversion of integer [[node references]] into binary paths, we see that the first two indexes, 0 and 1 both translate to a null path which involves no traversal at all, and then index 2 and 3 translate to the paths of "0" and "1" which involve a single iteration of traversal. In the actual implementations of the ''listTraverse'' function an addition of 1 occurs before translation to a binary sequence so that only index 0 results in no traversal, and indexes 1 and 2 result in the two single iteration traversals. | ||
This ''zero length traversal'' is still valid because the subject node from which traversal would start has a value just like every other [[node]] or [[list item]]. If a non-zero value is returned from ''nodeGetValue'' when passed a zero key, the value is the [[focus]] of the subject node's [[loop]]. | This ''zero length traversal'' is still valid because the subject node from which traversal would start has a value just like every other [[node]] or [[list item]]. If a non-zero value is returned from ''nodeGetValue'' when passed a zero key, the value is the [[focus]] of the subject node's [[loop]]. | ||
+ | {{code|1= | ||
+ | ''List space traversal function in C'' | ||
− | + | {{embed|LT.c}} | |
− | + | }} | |
− | |||
− | = Notes = | + | == Notes == |
*It may be possible to make traversal work as a [[w:Patricia trie|Patricia trie]] which combines all path segments that have only one direction | *It may be possible to make traversal work as a [[w:Patricia trie|Patricia trie]] which combines all path segments that have only one direction | ||
*[[Wikipedia:Trie]] | *[[Wikipedia:Trie]] | ||
*[[Wikipedia:Linked list]] | *[[Wikipedia:Linked list]] | ||
+ | [[Category:Nodal Concepts]]__NOTOC__ |
Revision as of 03:46, 30 August 2007
Associations
Making a unique bit sequence from a node index
The nodes of a node space are all identified by an integer index which starts at 0 for the first element created (the root node), and 1 for the next and so on. All integers can be represented as a unique binary sequence which allows them to all exhibit an address based on a unique path, this kind of data structure is called trie. here is a table showing some integers and their binary and path representations:
Both the decimal and the binary numbers really have an infinite number of leading zeros before them, but we can still maintain a unique sequence of digits to represent every integer even if we omit all leading zeros as we have in this table. The point is that this rule means that every single number except for 0 always ends with a non-zero digit (numbers are read from right to left). While this may not be of much interest for most number systems, you will notice that with binary it means that every number except zero ends with a 1 - and if we forget about the two first items in the list, then we could drop the last bit altogether. As can be seen from the Nodal Path column in the list, that's exactly what we do in path traversal. This can't usually work with normal numeric data types because 0 and 00 evaluate to the same, but a sequence of binary digits is more like a string comparison of "0" and "00".
In the actual implementations of the listTraverse function, a multiplication by three must also occur to account for the fact that list items are groups of three node references.
Zero length traversal
In the table above showing the conversion of integer node references into binary paths, we see that the first two indexes, 0 and 1 both translate to a null path which involves no traversal at all, and then index 2 and 3 translate to the paths of "0" and "1" which involve a single iteration of traversal. In the actual implementations of the listTraverse function an addition of 1 occurs before translation to a binary sequence so that only index 0 results in no traversal, and indexes 1 and 2 result in the two single iteration traversals.
This zero length traversal is still valid because the subject node from which traversal would start has a value just like every other node or list item. If a non-zero value is returned from nodeGetValue when passed a zero key, the value is the focus of the subject node's loop.
Notes
- It may be possible to make traversal work as a Patricia trie which combines all path segments that have only one direction
- Wikipedia:Trie
- Wikipedia:Linked list