1

I have a scenario where in strings and numbers are combined into a single entity. I need to search based on the string or the number. How do I go about with the data structure for this? I thought of coming up with a hashing for strings and search tree approach for numbers. Can you please comment on my choice and also suggest better structures if any?

Thanks!

4
  • Could you elaborate on your "single entity" and give examples? Commented Oct 22, 2010 at 18:53
  • I think that depends very much of the number of strings and numbers you have. Usually, using the standard std::map or tr1::unordered_map do the trick without creating any ad-hoc structures. Commented Oct 22, 2010 at 18:54
  • by single entity, I mean, they'll be available as objects or as a part of structure. Please note that I can have millions of entries and hence, I need an optimised answer... Commented Oct 22, 2010 at 18:55
  • please restrict your answers to C++ domain. Commented Oct 22, 2010 at 18:56

1 Answer 1

1

Use two std::maps, one from std::string to a pointer and the other from number to a pointer. The pointers go to your "single entity". See how far you can scale this (millions of entries...) before trying to optimize further.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.