Tries can only be used when the keys to be stored can be processed in digits or characters by character. C ++ std::map and std::set are designed to work with any comparable elements as keys and, therefore, cannot be implemented in such a way as to process characters by characters. Instead, they (usually) use balanced binary search trees that do not require key introspection and can instead simply use a comparator for quick searches.
If you know for sure that some properties are stored for your keys, you can in some cases do even better than try (see the Van Emde Boas tree for an example). However, library developers must develop many use cases and, therefore, you may need to choose options that are slower than the absolutely best option, since they must handle as many parameters as possible.
In addition, it is possible that the corresponding C ++ implementation contains the specialization std::map or std::set , which uses trie when the keys are strings. I do not think this is possible, but it is possible.
Hope this helps!
source share