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 == Data format
[source] [source,title='this_algorithm and S2 CellID Format']
---- ----
Example: Face 2, level 23 === this_algorithm Format ===
WORD3 (13 bits) : vvvvvvvvvvvvv
# Most significant 3 bits are for the face WORD2 (13 bits) : | |vvv vvvvvvvvvv
face_number = 0b010 WORD1 (13 bits) : | | |vvvvvv vvvvvvv
0000 (10 bits) : | | | |vvvvvvvvv v
# This algorithm is always level 23 Not represented : | | | | |
data_bits = level * 2 = 23 * 2 = 46 : | | | | |
Bit : 64 52 48 39 32 26 16 1
# The bit after the data bits is always 1 : | | | | | | | |
# All subsequent bits are always 0 : 0100101110101000 1011100010010011 1001001100100l00 1100000000000000
=== S2 CellID Format === | | || |
Bit : 64 48 32 16 1 Face number : ^^^ || |
: | | | | | Data bits : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^| |
: 01001011101010001011100010010011 1001001100100l001100000000000000 Bit after data bits (1) : ^ |
Face number : ^^^ All remaining bits (0) : ^^^^^^^^^^^^^^
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 == Encoding
[%header,cols="2m,5a"] [%header,cols="2m,5a"]
@ -199,7 +153,14 @@ func cellIDFromFaceIJ(f, i, j int) CellID {
---- ----
[source,rust] [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 n = u64::from(f) << (POS_BITS - 1);
let mut bits = u32::from(f & SWAP_MASK); let mut bits = u32::from(f & SWAP_MASK);