Update algorithm doc

This commit is contained in:
Austen Adler 2023-02-15 20:00:12 -05:00
parent 69f8c41e68
commit 31550c0586

View File

@ -12,71 +12,25 @@
== Data format
[source]
[source,title='this_algorithm and S2 CellID Format']
----
Example: Face 2, level 23
# Most significant 3 bits are for the face
face_number = 0b010
# This algorithm is always level 23
data_bits = level * 2 = 23 * 2 = 46
# The bit after the data bits is always 1
# All subsequent bits are always 0
Bit : 64 48 32 16 1
: | | | | |
: 01001011101010001011100010010011 1001001100100l001100000000000000
Face number : ^^^
Data bits : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
Bit after data bits (1) : ^
All remaining bits (0) : ^^^^^^^^^^^^^^
=== this_algorithm Format ===
WORD3 (13 bits) : vvvvvvvvvvvvv
WORD2 (13 bits) : | |vvv vvvvvvvvvv
WORD1 (13 bits) : | | |vvvvvv vvvvvvv
0000 (10 bits) : | | | |vvvvvvvvv v
Not represented : | | | | |
: | | | | |
Bit : 64 52 48 39 32 26 16 1
: | | | | | | | |
: 0100101110101000 1011100010010011 1001001100100l00 1100000000000000
=== S2 CellID Format === | | || |
Face number : ^^^ || |
Data bits : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^| |
Bit after data bits (1) : ^ |
All remaining bits (0) : ^^^^^^^^^^^^^^
----
[source]
----
All remaining bits (0) : vvvvvvvvvvvvvv
Bit after data bits (1) : v
Data bits : vvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvv
Face number : vvv
Bit : 64 48 32 16 1
: | | | | |
: 01001011101010001011100010010011 1001001100100l001100000000000000
Not represented : ^^^^^^^^^^^^^^^
0000 (10 bits) : ^^^^^^^^^^
WORD1 (13 bits) : ^^^^^^ ^^^^^^^
WORD2 (13 bits) : ^^^^^^^^^^^^^
WORD3 (13 bits) : ^^^^^^^^^^^^^
----
Alternative format (generated using link:https://github.com/luismartingarcia/protocol[protocol^])
[source]
----
./protocol 'Face:3,Data:46,1:1,0:14?bits=32'
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Face| Data |
+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |1| 0 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
----
[source]
----
./protocol 'WORD3:13,WORD2:13,WORD1:13,Number:10?bits=32'
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| WORD3 | WORD2 | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| WORD1 | Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
----
== Encoding
[%header,cols="2m,5a"]
@ -199,7 +153,14 @@ func cellIDFromFaceIJ(f, i, j int) CellID {
----
[source,rust]
----
fn fij_to_cellid(f: u8, s: u32, t: u32) -> u64 {
const FACE_BITS: u64 = 3;
const NUM_FACES: u8 = 6;
const MAX_LEVEL: u64 = 30;
const POS_BITS: u64 = (2 * MAX_LEVEL) + 1;
const MAX_SIZE: u64 = 1 << MAX_LEVEL;
const WRAP_OFFSET: u64 = (NUM_FACES as u64) << POS_BITS;
fn fij_to_cellid(f: u8, i: u32, j: u32) -> u64 {
let mut n = u64::from(f) << (POS_BITS - 1);
let mut bits = u32::from(f & SWAP_MASK);