Assume the language is JavaScript here, and the implementation of the HashMap is the Map class.
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.
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:
John or Sally, but not bothJohn and SallyMy 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?