On Sun, Jan 9, 2022 at 11:52 PM jlfo...@berkeley.edu <jlforr...@berkeley.edu>
wrote:

>
> I'm wondering if there's a map-like data structure that would store a
> string
> as the key, and the address of the key as the value. I'm aware that a
> standard
> Go map can't be used for this because its components might be moved around
> while a program is running so taking the address of the key would be
> dangerous,
> which is why it isn't allowed.
>
>
Somewhat late answer:

If you want to squeeze the CPU/Memory trade-off even more, and you have
strings where many of them are prefixes of each other, then you can look
into Trie-structures, where each internal node has some compression scheme
depending on its density.

Even more squeezing can be had by using Level-Compressed Tries,
Radix/Crit-bit/Patricia trees, and so on. Also, depending on what you want
to do with the data, generalized suffix trees, and Aho-Corasick comes to
mind.

Tries are map-like in the following way: they are bootstrapped by means of
an underlying map. Each internal node is a map-like structure, generalizing
from "rank-0" maps to "rank-1" maps.

Of course, depending on your actual data, these data structures might end
up taking more memory than simpler interning schemes. But one can often
compress them further in memory if space is paramount.

-- 
J.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGrdgiWXiB3SQi6hsYg5AsFTBSj8-dnaL8S-GttQUk9xkjigbQ%40mail.gmail.com.

Reply via email to