Data Structures like HashMap would retrieve data based on equality of key.
If I want to retrieve data based the comparison results, what data structure should I be using?
As has been answered already, a balanced tree is good.
You didn't mention anything about your speed or memory requirements for insertion though. A sorted array can also be very fast to search (binary search), but slow to insert.
I assume are talking about indexing with strings. The fastest lookup is a dictionary (in my benchmarks, twice as fast as the C++ map), but it is heavy on storage.
With a dictionary, each node has an array of pointers (to nodes): one for each possible string character. To insert, you walk through each character in the string, and add a node for that character (if one does not already exist), traverse to that node and continue until you are at the end of your string. You then store your data at that node. This data structure has the added bonus of giving you the option to build word-completion lists when you have a partially-complete key.
Generally, you should use a balanced binary tree. In C++, you can get one by
For unusual cases, other structures such as a Splay Tree or even a simple linked list may be better. It just depends on your needs.