- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We need to access same data from concurrent hash map using two different keys (say using user id OR using user name).
Currently we are achieving it by inserting data twice, each with different key. It is working, but is there a better way?
Thanks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
can anyone or intel support help please. I am not liking idea or keeping duplicate entries in hashmap.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
anyone? intel support??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Is it possible that you have only user id or user name?
- Is it possible that the same user have multiple ids or multiple ids are assigned to the same user?
If the both statement are negative than you can insert structures of <id, name> and define your own HashCompare that implements equal with the following behavior:
- returns true for <id, 0> and <id, X>
- returns true for <0, name> and <X, name>
- returns true for <id, name> and <id, name>
- returns false for any other case
Where X any value, 0 is impossible value.
Than if you need to find something by id, find <id,0>. If by name, find <0, name>.
Regards,
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Alex,
Thanks for the suggestion. Each user has an unique id and a name.
However, what about hash() function? the hash for <id, name> will be different from <id, 0> or <0, name> hash and in this case equal() will not be called at all. Pls correct me if wrong but I assume equal() only gets called for hash collisions (same hash).
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are right. I though about iterating over the container but it is not concurrent and it will be a linear search (that is not what is expected). Looks like you really need two maps.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page