A Scala Iterable has a toMap method, which returns a Map. What is this map backed by? What are its performance characteristics?
Is there any way to specify that toMap should return a HashMap?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It returns an
immutable.HashMap, which is actually an immutable hash array mapped trie. This data structure is essentially a hybrid between a multilevel hashtable and a trie. The worst-case complexity of a hash array mapped trie isO(log n)for all operations, although with a very low constant factor – hash array mapped tries are very shallow, and typically have only a few indirections. You can read more about the performance characteristics here or run a couple of microbencharks. The performance is acceptable in most cases.The
toMapalways returns a hash trie. If you want a mutable hash table, then do this:instead of: