What's the difference between hashtable and maps?

来源:互联网 发布:pat端口地址转换 编辑:程序博客网 时间:2024/05/22 14:23

From the point of view of the syntax and how you use them, there is little difference. The main difference is that the entries in a std::map and std::multimap are always sorted while they are not in hash tables.

The main difference otherwise is a difference in the speed at which you can access individual elements. Maps are usually stored as binary trees and hash maps are stored as hash tables. This means that if you have N elements in your container, then accessing an element in a map requires O(log(N)) time and the same operation in a hash map is O(1). So hash maps are faster, in general than maps.

0 0
原创粉丝点击