Giter VIP home page Giter VIP logo

Comments (7)

emirpasic avatar emirpasic commented on July 22, 2024 1

@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

from gods.

5k3105 avatar 5k3105 commented on July 22, 2024

Yes. This looks great!

from gods.

nkev avatar nkev commented on July 22, 2024

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.

emirpasic avatar emirpasic commented on July 22, 2024

@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.

image002

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.

emirpasic avatar emirpasic commented on July 22, 2024

@5k3105

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.

5k3105 avatar 5k3105 commented on July 22, 2024

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.

emirpasic avatar emirpasic commented on July 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.