4 ms·
How do you represent hierarchical data in a single hashmap?
by aidenn0 11y ago
How do you represent hierarchical data in a single hashmap?
- JBReefer 11y agoYou can frequently buy a performance increase by representing nested calculation logic in hashmaps via memoization.
- KingMob 11y agoDepending on your problem domain, you might be able to flatten it by just combining keys together (subject to keys being combinable like with string concatenation, using separators to ensure uniqueness of combined keys, etc.) E.g., turn {"foo": {"bar": "moop"}} into {"foo-bar": "moop"}. This also requires writing accessor fns, but it might be worth it, depending.
- aidenn0 11y agoRight, that works fine so long as you only ever go up the hierarchy, but going down the hierarchy would require a prefix search, which is the one place where trees actually do win over hashes.