680 karma · joined February 26, 2023
struct Node<T> {
pub data: T,
pub prev: Option<Weak<RefCell<Node<T>>>>,
pub next: Option<Rc<RefCell<Node<T>>>>,
}
Moreover, if you have cycles instead of trees, you can use a garbage collector with support for cycles, like rust-cc[1].So yes, it's cannot be done statically, because Rust is not designed for that.
However, problem disappears when 'static lifetime is used (or arenas). Nodes can be marked as deleted, instead of dropping them, so pointers are always valid.
In same vein, when nodes are deleted rarely, they can be simply marked as deleted, without dropping them completely (until sibling nodes are updated, at least):
struct Node<T> {
pub data: Option<T>,
pub prev: Option<Weak<RefCell<Node<T>>>>,
pub next: Option<Rc<RefCell<Node<T>>>>,
}
When node is deleted (its payload is dropped), linked list is still walkable.Borrow checker is my friend, it helps me write better code, but it doesn't stops me when I don't care about code quality and just want a task to be done.
Can you show example of "written by random cat" code you often see?
As I see here[0], cement stucko on top of natural stone was pretty popular technique back then.
[0]: https://odysee.com/@hiddenincatours:3/megalithic-saqsaywaman...
See https://wiki.mate-desktop.org/developers-corner/wayland-meso...
Quote:
> One of the most notable improvements is the enhanced support for Wayland, bringing us closer to a fully native MATE-Wayland experience. Several components have been updated to work seamlessly with Wayland, ensuring a more integrated and responsive desktop environment.
Usually, locals doesn't steal from locals in conflict zones, because their throats, or throats of their families, will be cut by other armed locals in no time.
Invaders and mercenaries often rob or kill locals in many, many cases.
man --html=firefox manDeveloped countries installs thousands of regulations (100k - 2M regulatory acts per developed country) on top of wild capitalism to tame it.
However, even heavily regulated liberal capitalism is better than other systems.
"We" actually experienced all social systems "we" invented so far, which are allowed by "our" productivity.
A layman can understand (real) physics easily, but cannot accurately predict anything except some simple things. Each additional digit of accuracy requires additional complexity in models, which laymen nor need nor understand.
Unfortunately, real physical physics, with inaccurate physical models, completely replaced by much more accurate mathematical models by «shut up and calculate» guys, which explicitly ignore real physical processes behind the scenes to perform calculations faster and with more accuracy.
It's similar to how we use AI: we ask questions, AI system performs abstract calculations, then we have an answer.
To advance in physics, we need to create inaccurate physical models of physical world. For example, hydrodynamic quantum analogs[1] are highly inaccurate, but they allow to develop intuition about quantum world.
[1]: https://en.wikipedia.org/wiki/Hydrodynamic_quantum_analogs
int average(int x, int y) {
long sum = (long)x + y;
if(sum > INT_MAX || sum < INT_MIN)
return -1; // or any value that indicates an error/overflow
return (int)(sum / 2);
}