Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

228
Visualizações
Using a HashMap for quickly looking up relationships between two entities

Tools used

Assume the language is JavaScript here, and the implementation of the HashMap is the Map class.

Data structure

Say I have a bunch of "People" objects that look similar to these two (which we will focus on), objects "John" and "Sally".

{
    id: "someUUID-John",
    name: "John"
}
{
    id: "someUUID-Sally",
    name: "Sally"
}

I also have n number of objects representing relationships between the above objects like so:

{
    id: "someRelationshipId",
    from: "someUUID-John",
    to: "someUUID-Sally",
    type: "phone_call"
}

The above example defines a relationship from John to Sally. Assume that there are multiple relationships going this same direction, and multiple going the other way (i.e. from Sally to John). There are also multiple relationships between other "People" objects and between both John and Sally to those other People.

Problem statement

The id of the above relationship is what this question is about.

I wish to use a HashMap to easily look up relationships. At the time I wish to look this up, it's safe to assume one of the two following scenarios:

  • I have a reference to John or Sally, but not both
  • I have a reference to both John and Sally

My question is, A) Is it possible to construct or use a hashing algorithm to generate a key that can be used to look up the relationship given a reference or both of the related objects and B) If so, what algorithm should I use or implement?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda