Difference between revisions of "Binary traversal"
(put path examples into an expandable table) |
m |
||
Line 1: | Line 1: | ||
[[Category:Nodal Concepts]] | [[Category:Nodal Concepts]] | ||
The array elements of a [[Nodal Space]] are all identified by an integer index which starts at 0 for the first element created, and one for the next and so on. All integers can be represented as a unique binary sequence as in the ''decimal'' and ''binary'' columns of the following list of example index numbers: | The array elements of a [[Nodal Space]] are all identified by an integer index which starts at 0 for the first element created, and one for the next and so on. All integers can be represented as a unique binary sequence as in the ''decimal'' and ''binary'' columns of the following list of example index numbers: | ||
− | <table class="expandable" title="Example integers and their equivalent binary paths"><tr><td> | + | <table class="expandable" title="Example integers and their equivalent binary paths"><tr><td><br> |
− | <table | + | <table border=0 width=100> |
<tr><th>Decimal <th>Binary <th>Nodal Path | <tr><th>Decimal <th>Binary <th>Nodal Path | ||
Line 57: | Line 57: | ||
<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><br> |
</table> | </table> | ||
Revision as of 03:49, 9 November 2006
The array elements of a Nodal Space are all identified by an integer index which starts at 0 for the first element created, and one for the next and so on. All integers can be represented as a unique binary sequence as in the decimal and binary columns of the following list of example index numbers:
|
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".
So that's how the binary conversion from a decimal index goes, but in the actual code, a multiplication by the size of three list items is also needed, and an addition of one so that the indexes 1 and 2 map to the single-bit sequences of 0 and 1. Traversing the index of zero (root) means to return the subject unchanged with no traversal occuring (i.e. a zero-length traversal). Here's the traversal function from the peerd.c version.
[[+LT.c|]] |
- See also
- List Space - the abstraction layer which uses binary traversal
- listSpace.c - functioning implementation of List Space
- Trie data structure