3 ms·
I don't know Rust. Can someone explain how this data structure stores whether a node is itself a valid word or whether it only leads to more nodes? For example
by wolf550e 2y ago
I don't know Rust. Can someone explain how this data structure stores whether a node is itself a valid word or whether it only leads to more nodes? For example the node "do" in their (“and”, “ant”, “dad”, “do”, & “dot”) example. I guess it's a discriminated union provided by Rust algebraic data types or something like that, but why not show the full bit pattern in memory?
- SkiFire13 2y agoBy looking at the source code [1] they have a discriminated union with 3 variants representing the possible combinations of representing a valid word and leading to more nodes (excluding the case where it is neither, which is impossible). So the node for the 'o' in "do" should be a `SearchOrLeaf` storing "do", its corresponding value (the `T`, in a set this would be empty) and the `SearchNode` containing the successors, which should only contain a 't' to "dot". [1]: https://github.com/cloudflare/trie-hard/blob/3d8163ca2d9208c663d6dbac48105a96ac540306/src/lib.rs#L114 https://github.com/cloudflare/trie-hard/blob/3d8163ca2d9208c...
- steveklabnik 2y ago> why not show the full bit pattern in memory? Rust doesn't guarantee a particular memory layout except for types explicitly requesting that you get a specific representation, so showing this would at least require a caveat that it's not guaranteed to be accurate. Furthermore, this specific data structure's internals are generic, so to show the memory layout, it would have to be for a specific instantiation. (They do also provide a structure that includes instantiations between u8 and u256, mentioning in a doc comment that the 256 size dominates overall size, and so if you want to slim it down, use the internals directly.)