holepunchto / hypercore

Hypercore is a secure, distributed append-only log.
https://docs.holepunch.to
MIT License
2.59k stars 182 forks source link

Documentation request: magic numbers in bitfield.js #185

Closed aral closed 2 years ago

aral commented 5 years ago

Is there any documentation on the magic numbers in the bitfield.js (https://github.com/mafintosh/hypercore/blob/master/lib/bitfield.js)?

e.g.,

var INDEX_UPDATE_MASK = [63, 207, 243, 252]
var INDEX_ITERATE_MASK = [0, 192, 240, 252]
var DATA_ITERATE_MASK = [128, 192, 224, 240, 248, 252, 254, 255]
var DATA_UPDATE_MASK = [127, 191, 223, 239, 247, 251, 253, 254]
…
var nibble = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4]

I was looking at the Rust implementation and it appears that they are unsure of their meaning/use also: https://github.com/datrs/hypercore/blob/master/src/bitfield/masks.rs

If there’s already some reference/paper/etc. where these are documented, it would help folks trying to understand/port this to have a link to it.

joehand commented 5 years ago

@yoshuawuyts are you covering some of this in https://github.com/datprotocol/book?

aral commented 5 years ago

Ooh, that looks like it’s going to be an invaluable resource; thanks for the link @joehand :)

PS. I think one thing that would help is a good “State of DAT” page that lists the relevant/currently-being-worked on modules/projects (out of the dozens) and documentation and has pathways to discovery for people interesting in using, developing with, and porting DAT. Something short, concise, and frequently updated.

yoshuawuyts commented 5 years ago

@joehand yeah, working on documenting that. It was probably one of the biggest gotchas when implementing hypercore.

It's not quite done yet though. Until then an annotated overview can be found in datrs/hypercore/mask.rs.

mafintosh commented 2 years ago

Closing cause old and lots have changed