jb55 on Nostr: trees can be scary to programmers: lots of pointers flying around everywhere to ...
trees can be scary to programmers: lots of pointers flying around everywhere to different parts of memory, lots of memory allocations, but fixed and balanced trees have a very simple representation that you can store and navigate in a straight line (programmers like straight lines, we call them arrays)
The numbers in this image are the index into an array. Given any position in the tree, you can find a parent or sibling element with a few arithmetic operations which result in another index.
No allocating complex data structures, no chasing pointers around, just a bit of math to jump around a tree flattened into a straight line. As a programmer finding elegant solutions like this is a pure dopamine hit. Code can be beautiful 🥹
#nerdstr #treestr
Published at
2024-05-12 02:09:25Event JSON
{
"id": "42c6d99f0b990187c9c8d2ad49bf8c74bb066cb7bd0f346d6af8efce9335a306",
"pubkey": "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245",
"created_at": 1715479765,
"kind": 1,
"tags": [
[
"imeta",
"url https://i.nostr.build/O49QP.jpg",
"blurhash efG%o*=Y=}xD=|gLrsS4nja{}twbNGWENGtQn+WEazjZ^7sRNbWrR*",
"dim 1174x798"
],
[
"t",
"nerdstr"
],
[
"t",
"treestr"
],
[
"r",
"https://i.nostr.build/O49QP.jpg"
]
],
"content": "trees can be scary to programmers: lots of pointers flying around everywhere to different parts of memory, lots of memory allocations, but fixed and balanced trees have a very simple representation that you can store and navigate in a straight line (programmers like straight lines, we call them arrays)\n\nThe numbers in this image are the index into an array. Given any position in the tree, you can find a parent or sibling element with a few arithmetic operations which result in another index.\n\nNo allocating complex data structures, no chasing pointers around, just a bit of math to jump around a tree flattened into a straight line. As a programmer finding elegant solutions like this is a pure dopamine hit. Code can be beautiful 🥹\n\n#nerdstr #treestr https://i.nostr.build/O49QP.jpg ",
"sig": "c0598174984a239f5cd1882dfdcaf3b4760279e2ad1eec3b18c90553ac99c55c79df03a07cd2bb7f7174c6171967980b8fccfae45f42b83f7c80164c17673508"
}