Comments (7)
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
from gods.
Yes. This looks great!
from gods.
What about if there are more than 2, where each can lookup any other? Is there a such a thing as n-directional map?
from gods.
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.
from gods.
You can now use the bidirectional map in GoDS, e.g:
package main
import "github.com/emirpasic/gods/maps/hashbidimap"
func main() {
m := hashbidimap.New() // empty
m.Put(1, "x") // 1->x
m.Put(3, "b") // 1->x, 3->b (random order)
m.Put(1, "a") // 1->a, 3->b (random order)
m.Put(2, "b") // 1->a, 2->b (random order)
_, _ = m.GetKey("a") // 1, true
_, _ = m.Get(2) // b, true
}
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
from gods.
What about if there are more than 2, where each can lookup any other? Is there a such a thing as n-directional map?
Maybe he was talking about Multi-index Container (http://www.boost.org/doc/libs/1_61_0/libs/multi_index/doc/index.html)?
Let me know if this works for you.
Yes! This looks like it will work. Thank you!
from gods.
Maybe he was talking about Multi-index Container
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.
from gods.
Related Issues (20)
- I would like to know how to delete a node data while treemap loop read. I want to know where is my code wrong? HOT 2
- Add to Go official wiki? HOT 3
- generic upgrade request HOT 3
- RedBlackTree: Iterators become invalid after removing an element. HOT 2
- DS which can give element if present or next greater if not present, elements should be stored in sorted order HOT 2
- LinkedHashMap Sort? HOT 3
- Multiset support HOT 1
- deque support
- hashset should support NewWith Comparator
- Add method of Set lack info about the insert take place or not
- treeset:The names of each element are not equal, why is second_8 disappearing? HOT 1
- godslist.js refrence in chrome 120.0.6099.225 console
- Add elements of a slice [] T
- Red black tree: Unresolved reference 'NewWithIntComparator'
- Red black tree: package cmp is not in GOROOT (/usr/lib/golang/src/cmp)
- Interfaces support any types HOT 5
- Why cannot index priorityqueue.NewWith (value of type func(comparator utils.Comparator) *priorityqueue.Queue)? HOT 1
- A issue In BinaryHeap
- linkedhashmap json.Marshal error HOT 1
- treeset json.Unmarshal error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gods.