 Hey, everybody, it's Brian. Welcome to the 41st Qt tutorial with C++ and GUI programming. Today I wanted to cover the Q hash. Now, what you see before you is the remnants of our last tutorial, the Q map. And I wanted to discuss what is a Q hash and what is a Q map. Well, first let me explain why we have the source code for the previous example. Because the Q map and the Q hash have almost identical implementations. So you can literally just change your Q map to hash and recompile, and everything should run as expected. So why do you need a hash and a map? What are the differences between the two? If you go into the Help module, you'll see a Q hash class is a template class that provides a hash table-based dictionary. And clicking More will actually show you that a Q hash class template provides a hash table dictionary, blah, blah, blah, and is one of the generic container classes. So what's so special about this? Well, it provides similar functionality to a Q map. We've already discussed that. There are differences. Here are the differences. The Q hash provides faster lookups than Q map, much faster lookups, I should say. When iterating over a Q map, the items are always sorted by key. With hash, the items are arbitrarily ordered. What does that mean? Well, in a map, the items are sorted by the key. In a hash, the keys you add are actually hashed in the background. There is a hash. If you don't know what a hash is, it is an alphanumerical representation of a value. It's kind of like a CRC or an MD5 or an SHA1. If you know what any of those are, if not, go Google them. They're actually pretty interesting. The reason why it does this is there's an internal algorithm it uses. So let's say you have hashes 1 through 10. And you want to know the value of, say, Mary. So we'll say Q debug employees value. And we know her key is 3. So we just want to see what that is. We'll say 3 equals. And let's just comment all this other stuff out real quick here. So we're performing a lookup here. We're saying, give me the value of this key. Well, when the hash goes out, the first thing it does, it says, OK, you've got a bunch of things. We're just going to, for the sake of argument, say we have 10 things. It's going to split that in half and say, is the hash in the first half or the second half? Well, it's in the second half. Or the first half. And then it's going to take, wherever it finds it, in this case, it'd be in the first half. And it would say, OK, split that again. And it just keeps dividing until it finds and narrows it down. And it's very, very fast. Whereas a map will actually go through the entire list of keys until it finds it. So pretty neat, pretty powerful. If you're making some sort of program, let's say you're making a collection of, I don't know, you're making a collection of cats. And you're trying to go over them and do a lookup. And the lookups are just starting to take forever. Switch from the Q map to the Q hash, and you'll see your lookups are just much, much faster. Well, this is Brian. I know this is a short tutorial, but you really need to know the differences between these two. It'll make your life in Codingland a lot happier down the road. Hope you found this video educational and entertaining. And thank you for watching.