Int pairs #22
Labels
No labels
bug
discussion
documentation
duplicate
ignore
new feature
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
golibs/gms-gods#22
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi,
I use pairs of ints which are id's for my data. These are 'maps' - relations between two data. What data structure do you suggest I use? Treemap.Map would seem slow for lookup because I can only Get by Key and I'd like to Get by Key or Value.
If I use 2 lists or 2 sets the int pairs will not align.
Should I just use a 2 dimensional int slice? [][]int{}
Thanks.
@5k3105
It seems to me that you are in need of a bidirectional map, if I understood correctly.
I have all intention of implementing that data structure, since it had helped me a few times in the past (albeit Java implementation). It won't take long, give me a few days to find some free time and implement it.
For now, you can use two maps (HashMap if you don't care about keys ordering). First map is for mapping first value to second, and the second map the second value to the first. This is somewhat ugly, since you have to care of consistency of those two maps (if you delete in one, you have to delete in the other, same goes with adding). This is ugly, but it will work.
I'll notify you when the bidirectional map is done in GoDS.
Cheers
Yes. This looks great!
What about if there are more than 2, where each can lookup any other? Is there a such a thing as n-directional map?
@nkev
To my best knowledge, I haven't heard of that. At least not in that terminology, but the structure that can support that is simply a graph.
Specifically speaking, the closest type of graph I can think of is a tripartite graph or some variation of it.
Initially, I had the intention of covering graphs before trees, since trees are acyclic specializations of graphs. However, I didn't want to get into graph theory madness that would consume me. The challenge is intriguing, so I hope to do it one day, hopefully with somebody's help that has a better understanding of graphs than me.
@5k3105
You can now use the bidirectional map in GoDS, e.g:
Over the course of the few next day I will implement also another bidirectional map implementation using the red-black tree that will be more memory efficient.
Let me know if this works for you.
Cheers
Maybe he was talking about Multi-index Container (http://www.boost.org/doc/libs/1_61_0/libs/multi_index/doc/index.html)?
Yes! This looks like it will work. Thank you!
It could be, but I am not 100% sure. One could make something similar with multi-index container, but it more looks like a graph to me, at least in my head.
On another note, I'll keep this issue open until the TreeBidiMap is implemented as an alternative to HashBidiMap.