BiMap or Inverse Map in Hazelcast

165 views
Skip to first unread message

preeta...@gmail.com

unread,
Feb 5, 2017, 6:02:38 AM2/5/17
to Hazelcast
Hello Everyone ... 

After some searching I am about to conclude that Hazelcast DOES NOT support distributed BiMap or Inverse Map (Refer - https://github.com/google/guava/wiki/NewCollectionTypesExplained#BiMap) out of the box.
And it looks like there is no plan to support it after reading this - https://github.com/hazelcast/hazelcast/issues/36

Is this a reasonable understanding?

Given this - I think if application ensure that the normal Map contains unique values then how to retrieve key given a value.

E.g.

Map<String, Integer> idToName = hazelcastInstance.getMap("my-map")
idToName.put(42, "Bob");
idToName.put(43, "Jack");
idToName.put(44, "Tom");

How can one retrieve "id" given "Name" e.g. how to retrieve "42" given "Bob" in efficient manner ???

Appreciate any help on this ... 
Many Thanks !


Ali Gurbuz

unread,
Feb 5, 2017, 8:49:06 AM2/5/17
to Hazelcast
an easy solution could be storing the keys in another map

Map<Integer, String> nameToId = hazelcastInstance.getMap("inverse-my-map")
nameToId.put("Bob", 42);
nameToId.put("Jack", 43);
nameToId.put("Tom", 44);




--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+unsubscribe@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at https://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/95be0c28-4909-4fb5-a3f5-8e4767c3e80e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Ali Gurbuz
Distinguished Engineer

Mahir İz Cad. No:35, Altunizade, İstanbul
a...@hazelcast.com 
+90 507 857 7815
skype: isbiroglu
@aligurbuz

preeta...@gmail.com

unread,
Feb 5, 2017, 12:51:07 PM2/5/17
to Hazelcast
Thanks Ali ...

Yeah that's one way to achieve but has following concerns
1. Keeping both maps in sync and updates to both needs to be automic
2. Size burden is concerned when the no of records are in hundreds of millions

Is there a way to lookup using values of map ? I am trying using queries using predicate but no luck yet ...

preeta...@gmail.com

unread,
Feb 21, 2017, 4:45:41 AM2/21/17
to Hazelcast, preeta...@gmail.com
Finally able to retrieve keys using values ... 

        IMap<String, String> map = this.hazelcastInstance.getMap("mymap");
        EntryObject entryObject = new PredicateBuilder().getEntryObject();
        Predicate predicate = entryObject.get("toString").equal(value);
        Set<Map.Entry<String, String>> set = (Set<Map.Entry<String, String>>) map.entrySet(predicate);

        if (set.size() > 1) {
            logger.warn("Retrieved more than one record count while getting tokens using value");
        }
        return set.iterator().next().getKey();

Thanks !
Reply all
Reply to author
Forward
0 new messages