WEBVTT

0:00:15.100 --> 0:00:21.023
<v A>Hey everybody, we're here with

0:00:21.833 --> 0:01:06.029
<v B>a duo episode. We've moved on to two episodes a month. I'm sure people have noticed by now, which is really, really cool. And I probably talk about that too much, but I just can't tell you how excited I am that we have an actual producer and we can up the amount of content that we get out to everybody, which is really cool. Exciting. Yeah. So this episode, we're going to talk about HashMaps, which is really cool. So before we get into the actual show, I just had like a pre-show. So I wasn't sure if HashMaps include HashTables or like what the umbrella term is. I think HashMaps kind of cover everything. I think.

0:01:06.029 --> 0:01:14.800
<v A>They include, I know HashMaps and HashSets are basically the same thing. Yeah, that's true. But then HashTable, I mean, does that just mean you're using an array?

0:01:15.520 --> 0:03:15.460
<v B>Yeah, I don't know either. We'll look it up. We'll look it up. Okay. But yeah, our show is going to be all about hashing and all the different things you can do with hashing and all the clever stuff that it unlocks. So we're really excited about that. And I actually, another thing I'm excited about is I got an Oculus Quest, one of the Quest 2s. And I think in our very first show, I think I talked about, or maybe it was one of the first few episodes, how I got a cell phone and how that was kind of a big deal. And I was such a, or a smartphone, sorry, smartphone. I was a late adopter to the whole smartphone thing. And I'm also a late adopter here. So I feel like I've been consistent. But I got a Quest 2. So I got Beat Saber and a lot of things that everyone knows about. And it's been fun. I've been exercising a lot with it. One of the things I was able to do with it that I didn't expect is I've had a racing wheel. So it's like a USB wheel that actually clamps to my desk. And it comes also with foot pedals. And so I'm really into racing games. And so I can play like F1 and Project Cars and Dirt and these other racing games with an actual steering wheel. And I've had that for a little while. But I actually was able to play a VR racing game with the wheel and the Quest. So the Quest has this thing called Oculus Link. And so you can connect the Quest to the computer and use it, have your computer drive it kind of like the Rift. So you can use the Quest in this way. And so with that whole like Frankenstein kind of set up here with the wheel and the computer and the Link and the Quest, I was able to actually do a racing game with like physical controls and VR. And it was awesome. Like it was really, really fun. I was racing go-karts and you could actually like as you pass someone, you can look or if someone's behind you and you want to see how close they are, you could turn your head and like look at them and then turn back. It was really fun. And even just the feeling of like you kind of like instinctively lean when you turn the steering wheel. And so when I lean, you know, my head actually leans and the view changes.

0:03:15.760 --> 0:03:19.420
<v B>And it was super, super fun. I have to admit it was a total blast.

0:03:20.200 --> 0:03:37.519
<v A>Yeah, I also got an Oculus Quest 2. There's some like I don't use Facebook personally, like nothing against Facebook. It's just like it's not something that I engage with regularly. So it was a little awkward that it's so heavily linked between sort of like Facebook, which you can go read about all on the Internet and people have very strong opinions.

0:03:38.160 --> 0:04:10.000
<v B>Yeah. So I just set this up. I could talk to this. When I started it, it said, 'Hey, do you want to create a Facebook account or an Oculus account?' And I said, 'I'll create an Oculus account and try and keep things separate.' So that way I can use Key Pass. I have a separate password, et cetera. So I went through like the whole sign-up flow. And then at some point really early on, I think it's like I went to get my first game or something. They're like, 'Yeah, actually about that. You're going to have to link these two accounts.' And the one you just created is going to get deleted in a year. I was like, 'What?' Yeah.

0:04:10.299 --> 0:05:50.919
<v A>But aside from that, I also have enjoyed it. My kids have really enjoyed it. We do it in small, small doses and we cast from the headset to the TV so other people can watch. Wait, what? Wait, wait. How do you do that? There's an option like a Cast option on the main menu. So you can either from your phone, if you have it linked to your phone, you can just watch it on your phone or tablet. But then you can also send it if you have a Chromecast. I think it also might support the Apple TV AirPlay. I've not tried that yet. But yeah, that it's pretty cool experience. I actually have the tool to show. I won't spoil it is an Oculus Quest game that I put as tool of the show before we decided to talk about VR at the beginning. So I'll leave that for then. But there's been a couple of games I really enjoyed, you know, being able to play and being immersive. One that was really different was I think it's called Acorn, which is like a permutation of the letters of the letters of Acorn about a tree and not stealing squirrels. And the interesting thing is that the person wearing the VR goggles is a tree that can throw, you know, sort of, I guess, like bombs and balls and whatever at squirrels that are running towards it, trying to eat the nuts that are at the base of the tree and take them back to their sort of base. But instead of having only bots do this, you can have other people on their phones, download the game and take control of the squirrels. So they become the squirrels. And you take turns or at least we do. We take turns. Who's the tree? You have giant, you know, tree limb arms and you're picking up these things and throwing them at the squirrels. And, you know, the other people in the room are playing with you. Right. They're the squirrels trying to come and steal your nuts.

0:05:51.400 --> 0:05:52.026
<v B>Well, that sounds

0:05:52.026 --> 0:06:41.680
<v A>awesome. And so it's super cool, you know, just like an experience that you wouldn't otherwise have. The only kind of like downside that I've gotten is one is like the battery life isn't super long. You can easily, you know, taking turns with everyone, eat through the batteries. And then the second thing is you actually need a fairly large space for the games that don't have you stationary. For the games where you actually like move or walk around the space, which I find to be kind of like the most immersive and most cool. You actually need a fairly decent space that's clear of objects. So like a living room or something, you need probably a good, I don't know what they recommend, like eight feet by eight feet or 10 feet by 10 feet. But it's actually surprisingly difficult, at least was in my house to like find such a space. And so we had to kind of like make an arrangement where we move some of the furniture to be able to, you know, have a big enough space to really fully enjoy it.

0:06:42.220 --> 0:08:28.500
<v B>Yeah. Yeah. I was playing this game called, I think it's called Rocket RX, but it's effectively like, uh, it's like Solitaire Tennis, where you're surrounded, you're encased in like a sphere. And so you hit the ball off the sphere at different points to hit, you know, various targets and stuff that are like overlaid on the sphere. Right. And so you're, and the harder you swing, well, it's not, if you swing hard enough, then the ball will actually skate along the surface. So for example, if you hit it hard enough, then you don't have to like hit the target directly. You just have to be kind of a leading the target and the ball will kind of go through it. And so it kind of encourages you to swing a little bit hard. I don't think the harder you swing, the better it is, but you have to swing hard enough. And so I had drawn my guardian, which is what they call the sort of border you set up before you start playing. I had drawn it kind of right up to the wall and not really thinking about it. Oh no. Yeah. By the time the guardian warned me like a split second later, I'd like punch the wall and it wasn't a big deal, but, but, yeah, you easily like kind of lose track of where you are spatially. And, and I was actually, that was one of the things that surprised me. I've only played it for a few days now, but surprised me was how often the guardian is actually, you know, warning me, like how often I get far away from where I was originally standing. I also got a game called Gorn G-O-R-N, which is a, it's like a Roman Coliseum. And there's a bunch of like weapons on the ground. And so you actually reach down to the ground, pick them up and and you have to sort of fight other people in this Coliseum. And, it is, I mean, all of these games are a huge, huge workout. I mean, I was sweating afterwards. It was a lot of fun.

0:08:29.039 --> 0:08:47.300
<v A>Oh, this is, it feels like that movie WALL-E, you know, like all the people like riding around in their, you know, chairs and drinking their Slurpees. Like we're, we can't go outside and exercise, you know, it's too much work. So we're going to put on these goggles and stay inside and exercise. It's just kind of, we're getting there.

0:08:47.660 --> 0:09:00.700
<v B>It's pretty wild. I mean, it's, it's yeah, it's interesting because it's definitely more of a workout than playing like Quake or something. So in a sense, it's like a step in the right direction as far as not ending up like a person in WALL-E.

0:09:02.240 --> 0:09:12.700
<v B>But yeah, you're right. It is actually there is a, I saw a game in the store that said VR, VR, where I guess you go around putting on VR goggles in VR.

0:09:12.700 --> 0:10:00.595
<v A>So there is, I think it's this super hot. So I think Superhot, which I believe is available. We should say there's lots of VR goggles out there. I mean, these are, I think this one's gaining momentum towards being like kind of more commonplace than just early adopters. Well, I think the Quest is the only one that's self-contained, right? At least that I know of. I think there are others, but they're not at the same performance. Like they were much cheaper ones further back like years ago. Again, we're late to the party. Yep. Yep. So in Superhot, the, which is an interesting game. They have, I believe it's there a scene where you reach up and pull down VR goggles onto your head to use your controllers to reach up and grab it and pull it down onto your head. And it's sort of that same surreal thing. Wait, I have on VR goggles and I'm reaching for VR goggles in VR to put on my VR goggles. Oh, it's

0:10:02.654 --> 0:10:09.800
<v A>amazing. I look forward to all of these little cheeky puns in these games as people start adopting these more and more.

0:10:10.579 --> 0:11:04.180
<v B>Yeah. I mean, another thing I did just for the experience, yeah, I don't think I would do it again, but it was actually pretty interesting was I watched an episode of Family Guy in VR. And so you're just like in this, like, I think you're in like some kind of a tree house or something, whatever that environment is when you start the Quest for the first time you're, you're in this environment and there's basically just a giant, enormous TV that's just suspended in midair. And it's playing Family Guy. And yeah, there's something just interesting about that experience. Like, I don't think I would do it again. You know, it's like you might as well just watch the TV, of course. Right? But there's just something kind of interesting about that. Part of it too is I was just surprised how comfortable it was. That really shocked me, actually. I think that having the strap that goes over your head and, you know, just getting all those straps, you know, tighten the right way actually made a really big difference.

0:11:04.180 --> 0:11:25.459
<v A>I think it's a time for news. Go for it. What's your news? All right. My first one is a YouTube video called The Water Computer, or I guess it's called I Made a Water Computer by Steve Mould, which I guess he's a fairly famous YouTuber. I keep coming across YouTubers who have like a million subscribers and I'm like, I never heard of this person before.

0:11:25.900 --> 0:11:31.819
<v B>Yeah. I wonder what the percentile is there. Like, I bet there's, there's got to be over a hundred thousand.

0:11:32.319 --> 0:12:33.540
<v A>Maybe. Everyone's probably groaning like, oh, of course I already saw this video. I knew it's got, well, I didn't. I never heard of it. So I came across this video by Steve Mould saying I made a water computer and he is doing it with another sort of like math YouTuber, Matt Parker, which Matt Parker, I've watched his videos before. So I'm not sure I don't watch all of them, but I'm not sure how I miss this. Anyways, the guy has an interesting mechanism for building logic gates out of sort of plastic and doing the computation instead of electricity, you use water. And I just thought it was pretty cool. So in college, I took some amount of classes in digital logic, discrete logic, these kinds of things about building up an entire CPU out of just gates. This is pretty common in a lot of electrical engineering or computer engineering curriculum. So I'm not unique, but I always just come back to it as like a sort of very enjoyable way to kind of think about these like individual gates and how that they grow up, up, up. And eventually you're playing VR on a headset.

0:12:33.540 --> 0:12:39.839
<v B>So just to be clear, like this doesn't mean a waterproof computer. This is literally a computer that uses water instead of electricity.

0:12:40.480 --> 0:14:01.140
<v A>Oh, OK. So, yeah, I was about to get there, but thank you for making sure to clarify that. Yeah. So this is like a class of people who have done what I guess what you call like physical computing, where instead of having like silicon logic gates or it used to be, I guess, vacuum tube gates, you actually make anything that by having two physical objects. And then if both of them are in the quote unquote one state, then, you know, and you have an AND gate, then you get some sort of output. So I've seen them built of Legos, of Tinker Toys, of now somebody with, you know, flowing water. These are always just like super fascinating to me. And in theory, I mean, there's some nuance to using water for doing your actual computation. But in theory, you could build up a fully functioning computer using this. I mean, it would get unreasonably large. I mean, modern silicon has an enormous amount of transistors in it. So you would end up, you know, it wouldn't be practical, but it's just a fun, thoughtful way to see the kinds of things people are able to do. And so you actually build something they can add to. Oh, I don't have it in front of me. Two four bit numbers or two five bit numbers. And then the output computation is a given by water flowing through this series of valves. So if you've never seen it before, you know, check that one out or just in general, you know, the fascination around using physical objects to do.

0:14:01.360 --> 0:14:16.900
<v B>Yeah. So when you go to take your SATs and they tell you you can't bring your calculator, just be like, it's all right. I got this, guys. Can you please define calculator for me? Yeah, I just it's OK. I don't need a calculator, but can you bring me like 10 jugs of water? Yeah.

0:14:18.439 --> 0:14:26.140
<v A>Can I have a 55 gallon barrel of water? Oh, wait, guys, it's still dripping. It's still dripping. Hang on. I need I need 10 more seconds.

0:14:28.140 --> 0:14:38.079
<v B>Oh, my gosh. Yeah. I mean, that brings back so many memories of I think that SAT, you could have a regular calculator, but the ACT, you couldn't have anything. I'm sure it's changed now.

0:14:38.459 --> 0:14:43.339
<v A>I haven't kept up with it, but I remember, yeah, there being like a specific list of approved calculators you could use.

0:14:43.640 --> 0:15:43.220
<v B>Yeah, that's right. That's right. Cool. Yeah, that sounds awesome. I'll give this a shot. Actually, you know, I was thinking about it the other day. A lot of the videos that are in my YouTube history are videos that you've posted. Oh, really? So, yeah, this is yet another creator. I guess another way of putting it is maybe not the history because that's too shallow, but like the like too recent. But a lot of the people I subscribe to are people that you found for me. Ah, so cool. I'll have to return the favor. Maybe next show I'll do. Have you heard of Colin Furzey? Yes. Yeah. Okay. Okay. That's one person that I found on my own. So just for people who haven't heard of him on the show, he does. He just makes crazy things. He's like a mechanical engineer extraordinaire and just builds all sorts of wild things. The most maybe not the most recent episode, but a recent episode, he made a car waterproof. The interior of the car is totally waterproof. And so then he filled it up full of water and he had like a car that was also a hot tub. What? Okay.

0:15:43.540 --> 0:15:44.660
<v A>I've not seen this one yet.

0:15:44.760 --> 0:17:41.000
<v B>Yeah. You got to check that out. It's a convertible and it's a hot tub. And while you're driving, there's like water splashing out of the car and everything. All right. My news. One of my news is this really cool guide to something called attention mechanisms. And so many to kind of, you know, explain and build up to this, but, um, you know, as a lot of people know, if you want to do what people call supervised learning, which means someone gives you a label. So they say like, okay, here's a picture. This is a dog. Here's a picture. This is a cat. Here's a picture. It's a dog. They give you a bunch of those. You can do supervised learning and you could train a machine learning model to predict the output. So you could give that model a new image and it will tell you whether it's a dog or a cat. Actually, it'll give you the probability that it's a dog, the probability that it's a cat. Right. And so, you know, you might have, let's say a table full of data in Excel or something, and then you have this one column and that one column in the table, maybe sometimes it's missing. And so you want to try and predict the value of that column when you don't have it. And so you would train a machine learning model to do that. And you would take all the other columns, you'd pass them in as inputs. That's relatively straightforward. And you'd have some kind of neural network or some kind of model to do that. Now, when you have images, that's more tricky because an image, every single pixel and really every channel of every pixel is a separate input. And so if you just use a regular neural network or some other model, it's just going to have too, it's too expressive, too open-ended, and it can't really learn effectively. And it won't be able to handle different sized images and stuff like that. And so for images, they've made this thing called a convolutional network. And so the convolutional network is kind of nice. Think of it as like a roving eye. So it's like a little eye that can look at a piece of the image and that eye kind of moves

0:17:41.000 --> 0:19:38.310
<v B>across the image doing the same thing at all the different spots in the image. And so if you know how to detect a dog in one spot of an image, that same dog detector will run everywhere else. And so you could end up with the output could be, let's say, another black and white image. And the more intense the image, the more likely there's a dog there or not. And that image is created by this eye that kind of like roves over the image doing the same thing over and over again. And because you only have to learn that eye once, then it makes it practical to build these models. And so it's cool for images. But then you have this, you have a lot of other modalities that you want to maybe learn from, right? And one might be language. So you might say, well, here I have a sentence and I want to predict whether this sentence is, I don't know, makes people happy or sad. And so you have a bunch of sentences and then you have another column that tells you whether the person was happy or sad and you want to train the same type of model. But how do you do that with a sentence, right? It's not really clear like how to what sort of model or what sort of topology you need to do that. And the thing that's especially challenging about sentences is that they can go on forever. Just, and other than the image, if there's a dog, the dog will probably just be in one spot of the image, right? Like you're, or if the dog is going to be over the whole image, you could shrink the image down. There are tricks you can do where you only have to look at, let's say, a certain spot of the image, but for sentences, you can't do that. Especially for certain languages and things like that, but even probably across all the languages, like the first part of the sentence might be really important when you're reading the end of the sentence. And so the sort of structure that they've designed to do things based off language is called LSTM, which stands for Long Short-Term Memory.

0:19:38.648 --> 0:21:38.360
<v B>And it's similar to this roving eye. I mean, it's a different technology, but it's similar in the sense that it uses a certain mechanism to kind of go over the whole sentence and be able to sort of build up knowledge as it goes through the sentence. So with all that groundwork, LSTMs are similar to convolutional nets that they didn't work for a really long time. And recently people have been able to get LSTMs to actually work and be really accurate and train models that are really accurate. And it's through something called an attention mechanism. So, the problem with LSTMs is, this LSTM, think of it like an accumulator, like a battery, right? And things are coming into this battery, like knowledge is coming into this battery and this battery is sort of storing this knowledge. And then when you finish storing the knowledge and the battery now has kind of everything in it, now you can start draining the battery, draining that knowledge. So you can imagine if you're, let's say, translating English to French, you would store all this English knowledge and then you'd have another model that kind of drains it in French. And if in French, you would have reversed the order of the words in a sentence, that's okay because the battery kind of has everything, right? The problem that they were having was as you store new things, they were kind of erasing the older things. And it's very hard actually to kind of keep storing more and more and more words without destroying like the very first word you put in. And so the attention mechanism is a way to prevent that from happening. And the article gets a lot more detailed than that, but this guide is really cool because it goes through the whole history and explains it with pictures. So if you've ever wondered how machine learning works on words, check out this guide. It's got a lot of good info.

0:21:39.237 --> 0:21:39.962
<v A>You make my

0:21:39.962 --> 0:21:45.260
<v B>news article seem so shallow. Well, that's probably the deepest one I've ever liked.

0:21:45.479 --> 0:22:55.719
<v A>So it's a sample size of one. Yeah, that's super fascinating. I think that was a great overview. My news article is another abrupt, 180-degree different direction, which is the successful launch and landing of Starship SN15. We have a little bit, I guess Jason was mentioning about being a late adopter to smartphones. We have a history as well as covering some amounts of space articles and making space predictions. This happened a couple of weeks ago while we're recording this. So it's sort of old news, but I just want to celebrate. I think it's super cool. This is a SpaceX prototype and they were able to launch it out of Texas up to, I don't remember where they go up to about 10 kilometers or something. And then land it back just next to where it took off from. But just the whole thing flying and launching it, it looks so ridiculous. And to actually see them do it successfully, they've managed to sort of land before, but there was always problems one kind or another. So this is the first time they sort of took off, landed no major issues. In fact, they're looking to potentially do it again. I guess they're doing inspections and stuff.

0:22:56.000 --> 0:23:04.860
<v B>So, oh, I was going to ask about that. Cause I thought they had done it before, but yeah, maybe there were problems. You know, it might've looked like it landed, but something broke or something. Yeah.

0:23:05.320 --> 0:23:45.600
<v A>And there was also the, they did tests earlier, which were not as high and weren't didn't have aerodynamic surfaces. So they did some like tests of the engines and stuff. This is the first time they sort of sent up what would end up being the final stage, like the orbital part of the thing. And now it looks like they're based on filings. They're thinking about launching up to orbit from Texas and splashing down somewhere around Hawaii sometime soon, which would require, I think them to stack two stages together. So this thing's huge. If you've not go look at the diagrams for how big the final thing is going to be compared to like a person or existing launch vehicles. And it's absolutely insane.

0:23:45.600 --> 0:23:59.699
<v B>Wow. That's amazing. Yeah. So how far are we away from being able to get a ride on one of those as a passenger? You and me or an arbitrary rich person? Let's say, let's say an arbitrary rich person.

0:24:00.159 --> 0:24:37.133
<v A>I mean, I think they're going to fly several civilian launches this year. I think SpaceX is doing one on the Falcon, their current ones that go up to the Space Station. They're going to launch some civilians, which will sort of kick off another set of civilian space travel, which hasn't happened for a few years. But I think on Starship, I would say probably still sort of two, three years away. I mean, there's the Japanese person who bought a trip around the Moon on one of these Starships and they haven't set exact date yet, but I think they're saying it's going to be closer than you think. Wow. It's amazing. Now you and

0:24:37.133 --> 0:24:40.899
<v B>I affording it. Yeah, that's a whole other question. Yeah.

0:24:42.300 --> 0:24:42.780
<v A>Yeah.

0:24:42.780 --> 0:24:49.688
<v B>Maybe if we stopped buying so much junk food, maybe we can get there. How much

0:24:49.688 --> 0:24:50.580
<v A>Dogecoin did you buy?

0:24:50.720 --> 0:24:52.100
<v B>Oh gosh, Dogecoin.

0:24:54.100 --> 0:25:14.640
<v B>Oh yeah. Last show, or a couple of shows ago, a few features ago, we were talking about, you know, like, fractures or banking and those things, the last duo episode. And since then people have been trading their dollars for Doge money. So I think, I think that just kind of tells you everything you need to know.

0:25:16.740 --> 0:27:15.741
<v B>So, okay. My second news article is on Mailspring. So I actually use Mailspring. If you've ever gotten an email from me recently, you'll actually see this little footer because I've never bothered to change a default, which is great advertising for them. You'll see this little footer saying Mailspring, the best free email app or something like that. But I actually love Mailspring. We should definitely do it as tool to show some time if I haven't already, but it's a nice desktop email app. It has a lot of really nice features. It collects all your inboxes. I just feel like it has a great interface. I'm a big fan. And for a while it, the Mailspring kind of front end, which is all an Electron was open source. But the backend, which actually handled, you know, ingesting mail from, you know, a trillion different sources, you know, they handle like Exchange, they handle Gmail, they do all of that. That was all closed source. And so, I don't remember if Mailspring is on Linux. I know it's on Mac and Windows. I'm sure it's on Linux too, but in general, like you always, when something's closed source, you always kind of wonder how long it's going to survive. And now they recently decided to open source the whole backend, which is really cool. Not only does it mean Mailspring will be around for forever, but also if you ever needed to do that, like if you needed to ingest mail and basically Mailspring basically converts email into think of it as like a SQLite table. And so if you ever needed sort of a database representation of your email, and one that sort of is kept, kept in sync and kept alive, Mailspring does exactly that. And so I think it's a really nice thing to have for the community. So, I'm really excited about all of that. I think email is,

0:27:16.298 --> 0:27:36.500
<v B>still an area where there's a lot of low hanging fruit. I mean, I spend a ton of time on email, you know, something that kind of organized email. I do think there is something to that. And this will sort of open up that where people can write new front ends and new mail experiences without having to learn ten different protocols.

0:27:36.620 --> 0:27:37.660
<v A>Oh man, that's cool.

0:27:38.040 --> 0:28:04.960
<v B>Yeah. There are some email clients that are premium, like there's Superhuman and there's Hey, but I haven't really tried them yet. But yeah, there's gotta be, I think a better way to do email, like something that suggested. Like, I don't want something that automatically puts things in different folders. Cause you never really know what it's going to do, but something that somehow like just suggested ways for me to do email better. I think that could be cool.

0:28:04.960 --> 0:28:21.659
<v A>I mean, I was, I much preferred Inbox, Google's Gmail client that they experimented with a while. I still feel I'm worse at email using the Gmail app than I was using Inbox. So I too still have a hole in my soul.

0:28:22.340 --> 0:28:27.747
<v B>Yeah. I actually switched. I found a mailspring when Inbox was shut down.

0:28:27.747 --> 0:28:29.974
<v A>Okay. Well, we're not going to get on that. It's gonna make me sad. It's

0:28:29.974 --> 0:30:26.139
<v B>time for. Yeah, it's true. Inbox was so good, but it is what it is. Time for book of the show. All right. My book of the show, which actually, you know, this might be the first time ever, but I already read this book. I'm not suggesting a book and walking someone off a plank. But yeah, this book is self-titled: it's Elon Musk. And so it's all about Elon Musk. I think it's awesome. Actually, I found the book fascinating. I think that it really did a good job of covering the good and bad stuff. It's really interesting. The foreword—or maybe the first chapter preface or whatever—is from the author, first person talking about the negotiation he had to go through with Elon to write the book. And originally Elon wanted all these footnotes, and I guess he has a sort of engineer mindset where he wants to just correct the record and wants everything to compile. But they would kind of went back and forth on that a lot, but you know, as you can imagine, someone like that's really concerned about their image and everything. That's not a surprise, but yeah, I felt like the book was extremely well balanced. It had a lot of really good detail. It covered all different chapters in Elon Musk's life. So he started off as an intern at some software company and then just doing a bunch of coding. One thing I noticed was, and one thing you kind of take for granted or at least I kind of took for granted, is the support that he received from his family. So one thing that—there's a bit of trivia here—like Elon Musk is one of his things he's known for is having a rough childhood. Like his parents were really strict, and I'm not taking anything away from that, but his parents actually funded the first company.

0:30:26.140 --> 0:31:34.780
<v B>And actually when I've read about other tech billionaires, you kind of see that pattern over and over again. So I was thinking, it made me think a lot about that sort of community—like Elon Musk's and the Mark Zuckerberg's and the Bill Gates and what have you. And a lot of these people are in a position where they can take some of those really big risks. So like, someone in all of these cases offered them millions of dollars to their company, and they turned them down. I feel like that would be pretty extraordinary to do. But then when you see the background, it's like, okay, well, actually these people already had millions of dollars usually through their family. So that kind of made more sense, but still, Elon Musk is a total genius. I felt like yeah, I have a ton of respect for him after reading the book, and I thought it was a fantastic read. It actually is very exciting. I was really interested in it the whole time. So it doesn't—a lot of these can tend to drag on because they might say, well, here's sort of the middle years where nothing happened. And there really wasn't a lot of that. The book was super entertaining all the way through.

0:31:35.220 --> 0:31:40.800
<v A>Nice. I've actually not read any Elon Musk biography. I not too much studied him as a person.

0:31:41.500 --> 0:32:04.520
<v B>Yeah. I know very little also about a lot of. I don't really study a lot of people, but for some reason, I was really just drawn to reading this biography. The only other biography I've read is the Steve Jobs biography. And yeah, there are just a lot of really interesting parallels. And yeah, it was a solid book. Nice.

0:32:05.280 --> 0:33:06.280
<v A>My book of the show is Ready Player Two. This is the follow-up to Ready Player One by Ernest Cline, set in the same universe as Ready Player One. I guess it's a low hanging fruit, not a super deep book, but enjoyable. I enjoyed it as much as Ready Player One, but definitely pretty solid. I'm not getting through as many books nowadays as I used to. Yep. Same here, but this one was nice, easy. I actually listened to it, but a nice, easy listen. And kind of did it in the background. I thought it was good. You know, the same kind of thing. If you liked the first one, you probably liked the second one. If you didn't like the first one, I wouldn't bother with the second one. Yeah. I mean, it's the same kind of pop culture laden exploration of the eighties and a little bit more music bent maybe than the first one. But yeah, a good read. I always struggle. I don't unlike a biography; I don't want to spoil the fiction too much. So I don't really want to say too much about what the book is, but yeah. I'm Ready Player Two by Ernest Cline.

0:33:07.000 --> 0:33:16.240
<v B>Cool. Yeah. You recommended the first one a while back and I gave it a read and I thought it was fabulous. So yeah, I'll definitely—I think I already bought this book as soon as I saw it, but I haven't read it yet.

0:33:16.560 --> 0:33:24.580
<v A>Yeah, my backlog is getting pretty big, so I got to start spending some dedicated time getting through all these books I want to read.

0:33:24.760 --> 0:33:43.260
<v B>Yeah. I noticed that I've kind of caught myself switching to podcasts because you know, I don't have the long commute or anything. So, but I think I'm going to try to get back into doing full books, but just in bite-sized pieces and see how that works out. Is it time for tool of the show?

0:33:43.760 --> 0:35:41.000
<v B>Tool of the show. My tool of the show is Datadog, which is an amazing tool. It is super fun. The way Datadog works is: you're developing, let's say some kind of app. It could be an Android app, could be a website with some web backend or even on the front end, on the browser. Anything you develop, you're going to give it to somebody, and that person's going to run it when you're not around. And so a bunch of logs are going to be generated right now. Like if it crashes, that's a whole other thing. I think I already mentioned Sentry in a previous episode. So if it crashes, you have Breakpad, you have Crashpad, you have Sentry, you have a million different tools—Rollbar, etcetera. But then like, there's also just like, is this healthy? Like in general, you don't want to crash websites or apps. But you still want to know, for example, how many people are opening your app, like clicking on, let's say the settings and then leaving the whole app. Well, that would probably be good to know, or just anytime you have any type of log—like sometimes you have a log should never get here. And it fires. So most apps, sites, etcetera, are generating logs. And it's great to have those sort of aggregated. And so what Datadog does is they have a bunch of clients for a whole bunch of different languages. I actually ended up writing my own client because they didn't have a C++ one. But they have a very straightforward JSON API. So you could write a client and just about anything, even if they don't have one for that. And you basically just through this API, you make a POST request with your application ID and a bunch of logs. And then what Datadog does is it collects all of that. And then it presents you with this really nice web UI where you can—there's something called Live Tail, and you can actually see logs as they come.

0:35:41.000 --> 0:37:38.280
<v B>In and then you can write rules, and they actually have this sort of way to automatically find patterns in your logs. So if you have a bunch of logs that says, you know, received 26 packets, received 31 packets, received a hundred packets, right? All of those lines are going to be different, but they all have the same pattern: it's just 'received, N packets.' Datadog will automatically pull out that pattern and then group all of those logs together. To be honest, I haven't ever used any of the premium features. I've only ever used the free tier, which makes me think that they probably should maybe charge more or something, but nothing I've talked about costs any money. They do all of this for free. And then you can write rules on top of that. So you can say, for example, you know, all of the logs that have the severity level of 'error.' I want all of those to get written to an S3 bucket. So S3 is Amazon, AWS, a file system. Like I have—that's one of the rules I have set up. Whenever an error log happens on Eternal Terminal, I've actually gone through and looked at all the error logs to make sure that there's nothing like personal, like someone's name or IP address or anything like that. And so I know all these error logs are safe. And then whenever any one of those error logs are written, it will get sent to Datadog and then it gets dumped through an S3 bucket. So all of that is super nice. The other part of it is—yeah, Datadog, as I was saying, kind of alluding to earlier, you know, they're using your own kind of infrastructure. Like, so Datadog's not actually storing anything. You know, they have a way where you give them permission to a folder on your AWS. And so you're effectively paying for all the hosting costs and stuff yourself. And because of that, there's no limits. Like they can just take tons and tons of data.

0:37:38.720 --> 0:37:57.840
<v B>And if they have to write a lot of data, you're going to pay for it through Amazon, not through them. So it's an amazing service for free. I have to look up what, I think for a premium, they'll let you do alerts and more fancy things, but yeah, definitely check that out if you're building anything that's going to be looked at by other people.

0:37:58.520 --> 0:38:12.840
<v A>Super cool. Yeah, they're like a publicly traded company and stuff now, right? That's a good question. I don't know. This is super cool to hear you say like kind of like their niche on top of other people's services; I guess it's kind of cool.

0:38:13.460 --> 0:38:43.279
<v B>Yeah, actually that was—I felt like a really good sort of business decision because in my case, you know, it's an open-source project. I'm not too worried about if they get hacked these sort of error logs, which as I said, have no personal real data on them. But the fact that, you know, it's passing through their system briefly and then it's gone is kind of nice from a security standpoint. And it means for them, they don't really have a big footprint.

0:38:43.880 --> 0:38:54.980
<v A>My tool of the show is—I already teased it, not a tool, but a game. I expect you to die. I played it on the Quest too, but I believe it's actually on a lot of VR platforms.

0:38:55.500 --> 0:39:19.037
<v B>So real quick, Datadog is publicly traded. And actually that company has a market cap of $28 billion. So that is a much—I kind of thought that it was just a small company; I guess I was totally off the mark there. But I think if you're going to buy Dogecoin instead, buy a share of Datadog. That's my advice. Shares.

0:39:19.037 --> 0:39:21.771
<v A>Are a million dollars a piece. So my game

0:39:23.712 --> 0:40:35.680
<v A>is I Expect You to Die. I guess it's a little bit like an escape room kind of feel—you unlike the ones I was saying where you move around the room here, you're actually supposed to be sort of seated, but all of the scenarios make sense with you being stationary. So either you're sitting or standing in one spot and moving your body sort of rotating around the room to do various items, and there are various puzzles. And it's themed as a spy going on missions. But there's not a ton of explanation and various things that you do in trying to solve the puzzles cause you to die. So you may be like in a car and there's poison gas outside. And if you break the window somehow, the poison gas is going to come in and kill you, but that's not the only way; there might be a grenade. And if you drop the handle off the grenade, the grenade will explode. So you aren't expected—at least I guess, based on the title—I assume you're not expected to not die. So you die and then you try again. And you sort of figure out the puzzles. Puzzle rooms is an interest. It's I've never done an actual puzzle room like in real life. Like I've never gone to one.

0:40:36.339 --> 0:40:39.899
<v B>Oh, my family loves them. They're so fun. Like escape rooms. You mean?

0:40:40.040 --> 0:42:26.720
<v A>Oh, that's what I mean. Yeah. Sorry. Escape rooms. I don't even know the name. I don't—this is not my—they are so good. But I sense it's probably something similar where there's a kind of language to them that you have to figure out. Like if you just went to one, never having heard of it before, you're not going to necessarily do so well because you don't—the premise can be; you may need to know a certain trope or a certain way of thinking for it to start to make sense. The same is true of a lot of things. So I feel this one does a good balance of understanding where the puzzle is. Sometimes when I've played games that are claimed to be sort of escape room themed, I don't even—I can't figure out where the puzzle is. I understand I'm supposed to do something, but I don't get that you're supposed to just tap around the screen or you're supposed to bash open things to look what's inside. But those aren't intuitive to me, but this game, I feel like strikes a really nice balance of how it's clear what things I can affect. And then by working through the interactions between them, I can see where the puzzle is and I can see how to solve the puzzle. I don't always get it right the first time, but each time I can continue to make progress. And so I find it for my naive level of sophistication. I don't have to go consult a walkthrough repeatedly to keep making progress. Like I'm able to work it through on my own and it's at just the right difficulty level where I don't get bored of it and I don't just cruise right through it either. So I very much enjoyed, and the theming is kind of cool too—a little bit James Bondy, a little bit, you know, the spy thing. And it has a little bit of story without being too much. I find it'd be a really good experience. And each level is sort of bite-sized enough that for me, like sitting and doing one VR session, I can get through kind of like one level, and that's about the right for me.

0:42:27.260 --> 0:43:30.959
<v B>Cool. It makes sense. And so, yeah, I guess one of the challenges with that—I mean, puzzle games in general—it's like you never really know as a puzzle game designer how you're supposed to deal with someone not figuring it out. That seems like the hardest part, right? Like with these escape rooms, what they've done is, for example, we did one where, and we've done a bunch, but we did one where there was just a trick that we didn't get. I think it was some kind of language trick where there were like four different cat names. And based on the cat names, that was the clue. Like you just had to know some factoid that none of us had really heard of. And so we were really stuck. And so they have this thing where you can press a button and basically they'll kind of give you—I think there's two levels of hints—but yeah, kind of getting that right. I think especially for VR, it's really important because you don't want to take the headset off and then go look on Wikipedia, you know? And so actually how do you die in these games? Like, does the screen just go black?

0:43:31.520 --> 0:44:05.963
<v A>Yeah. I think it—I don't remember exactly. I think it believed that like fades to red, you know? And then it's just like but whatever, when it happens, like an explosion of a grenade or like gas coming in and you starting to black out and you have a few seconds to react because sometimes you can stop it, but sometimes like a grenade exploding, you can't. And then it fades right. And you go to like a sort of death screen where it makes some funny quip about you sucking and not figuring it out or so much wasted training on you or some such something. And then you can replay the level, but there are achievements that sometimes require you to die in certain ways or whatever. So.

0:44:05.963 --> 0:44:30.900
<v B>Yeah. That makes sense. Yeah. I used to play a game when I was really little called Lost Vikings, which was a puzzle game. And one thing that I thought was pretty interesting was, if you lost, if like you died three times trying to finish the level, that on the fourth time they would offer you to skip it. And yeah, I feel like that actually is probably the hardest part of all these games is figuring out what to do there.

0:44:30.960 --> 0:44:40.422
<v A>They do that in some Super Mario games, like the newer ones. If you die too many times, they give you like a special power-up or whatever that makes it a little easier. Yep. Yep.

0:44:40.600 --> 0:44:41.180
<v B>That makes sense.

0:44:41.380 --> 0:45:19.819
<v A>But yeah, I so I really enjoyed it. You know, I think I want to get more into these puzzle games, but like you pointed out, they need to be kind of well designed or else it just becomes frustrating. I still find myself frustrated at some of the puzzle games where you need to do an action repeatedly, even though it's not resulting in anything happening. Like, Oh yeah. This character and the character burps and you have to kick the character and they just keep burping in exactly the same way. But on the 13th burp, they belch out a potion in their belch bubble or something. And it's like, what? Like, why would I sit here and click the same thing, getting the same result? If you don't give me some indication that progression is being made, I'm going to go do something else.

0:45:20.740 --> 0:45:29.680
<v B>Yeah. Yeah, exactly. Like there should be a way to just using logic and observations to not have to guess. I think that's really important.

0:45:30.379 --> 0:45:31.232
<v A>Yes. Yeah. Yeah.

0:45:31.440 --> 0:45:38.033
<v B>Yeah. Actually the I used to do those puzzle championships, like the World Puzzle Championships and all of that. Oh,

0:45:38.033 --> 0:45:39.450
<v A>like the MIT one and stuff.

0:45:39.799 --> 0:45:53.420
<v B>Yeah. Yeah. People would think that you would guess, but it would just take forever or like Sudoku. So it's a much more common example. Like you shouldn't be doing a lot of guessing in Sudoku. Like if you're doing a lot of guessing. No, no guessing.

0:45:53.980 --> 0:46:32.674
<v A>A properly designed Sudoku puzzle requires zero guessing. I thought there were some where like there would be maybe one guess. It may need a very advanced technique or whatever, right? Like if it's a hard puzzle, like you may not know the deduction method that's needed and therefore you would have to guess if it's like above your level, but a prop, like any, like, I don't want to say like, you can make whatever Sudoku puzzle you want. Right? As long as if it has a unique solution and it could require guessing though, but they're like when the algorithms design them, they or the designers design them, they're supposed to know here's the only kind of techniques, you know, and it should be forward solvable using only deduction. Oh,

0:46:33.079 --> 0:47:11.605
<v B>Interesting. Yeah. That makes a lot of sense. I think I think yeah, there was this other puzzle game I used to really enjoy. And I watched a actually a podcast. There's a podcast called Game Design. I can't remember the exact name of it. It was Game Design Podcast. And one of the inventors, the person who wrote that game was on that podcast and it's actually really clever. They just kind of and Sudoku probably works somewhat similar as it kind of worked backwards from the answer. And but you have to work backwards in a way where it's not ambiguous, but yeah, I think I think that sounds awesome. Actually, I'll give that a shot. I'm looking for another quest game to pick up. Yeah.

0:47:11.740 --> 0:47:38.959
<v A>This is one where like, I pretty much sure like the kids will play a level I've already played. And once they learn like, you know, kind of thing, but it's over their head, but they enjoy watching me. Like, Oh daddy. Sometimes I do it on purpose. Sometimes like I realize there's a novel way to die and I'll let myself die just for kicks. But they, they always think it's hilarious. Oh daddy. You suck. Like you can't, like you didn't realize that grenade was going to kill you. Like how dumb are you? No, I mean, I'm being hyperbolic, but it's an enjoyable family experience that way. Yeah.

0:47:39.140 --> 0:48:37.026
<v B>My son does the same thing with me and Zelda. So he, um, I made it to this one temple and Zelda where I really was too advanced. It's one of these ones you have to battle a robot. People have played The Breath of the Wild. There's some of these temples where you fight battles, but the game is nonlinear. So you could get there at any point. And this one robot, I just ended up basically, if he hit me at all, I just died instantly. And so it made, it made this battle way harder than it really needed to be by doing it so early. And, uh, yeah, my son actually was filming it on his iPad for his school share day. And he's like, 'Dad's going to die again.' He's going to die. Watch. He's going to die. And then I died. He's like, 'Yep. Dad died again.' There's a game over screen. I was like, I honestly, like it's the first time in probably 25 years where I wanted to throw the controller for 35 years or something. But I was like, you know, having the, having the, uh, having the audience support actually didn't help that much. Oh, all

0:48:37.026 --> 0:50:35.877
<v A>Right. Hash maps. Hash maps. Yeah. I'm going to kick it off. So, you know, before, when I was in college and learning about data destruction algorithms, of course I learned about hash maps, and, you know, Oh, cool. Like we're going to talk about what makes them interesting in a minute, but it never really clicked to me. But I was mentioning this to Jason in the pre-show. I don't think we'll get to it at the end because we're already going along. But when I went to start looking at sort of what you call Silicon Valley companies, big companies like interviewing there. Like I kept reading, 'Oh, hash maps. You got no hash maps. You got no.' I hadn't really used hash maps, and I thought they were overplaying it, but sure enough, all my interviews, some solutions needed familiarity with hash maps and intricacies of hash maps. And then showing up to my first jobs there, like sure enough, hash maps were super common. When you get to kind of really big data, I was really surprised. I underestimated the importance of hash maps early in my computer science career. Yep. Same here. So the promise of a hash map is insertion and lookup being constant time. The idea is if you think of like a binary tree—we talked about trees, I think in our last duo episode—then you get log event insertion, right? The insertion, if you just insert into a sorted array, for instance, and you don't use binary search, you'd have to sort of go through each element in the array to find where you need to insert it. So that would be like linear time. If your stuff is a well-formed binary tree, then you need log event like visits to nodes before you find where to insert. But hash maps promise to blow that away by saying, 'I'll give you a constant time insertion and a constant time lookup.' So if you're trying to see if this key is in your hash map,

0:50:36.045 --> 0:50:58.840
<v A>you can do that in sort of constant time. That doesn't mean zero time. It just means that it doesn't really matter how many items are in your map; no matter how big your map grows within bounds, you would still get sort of this algorithmic constant time. And so that's a super powerful thing. And we're going to talk a little bit about the various ways that can be accomplished.

0:50:59.520 --> 0:52:58.960
<v B>Cool. Yeah. Totally makes sense. Yeah. I think it actually will surprise a lot of people how ubiquitous hash functions are. They're really just everywhere, but yeah, at a high level, what's going on here is: you know, we talked about trees, right? And trees are super nice. The challenges with trees are that you have to keep them balanced, right? And so that could be really expensive. And even if you don't have to keep them balanced, putting something or finding something in a tree takes logarithmic time. And so that doesn't sound like a big deal, but when you start putting lots and lots of things into the database, it can actually become a really big problem. Right? So imagine log base two of a million is—oh geez, I kind of put myself on the spot here—is what, maybe six or something? Or their log base no, log base two of a million is what, like 14 or something. Anyways, it could easily end up taking like 14 times as long as just one. Oh, 20. Well, there you go. All right. That shows how well I could do a log in my head, but yeah. And so imagine, you know, like you have an app and now it takes 20 times as long to run. It could be, it could end up being a really big deal. And so the challenge with hashing is figuring out sort of the hash function, and what that means is figuring out some type of way to represent something really concisely or ultimately represented with just a number. And so there's been a bunch of work in this field. I mean, it would take a really long time for us to really dive deep into it, but at a high level, there's really two types of hash functions that are important. The first type is like cryptographically secure. And the second is not secure. Right? So for example, if you're trying to hash credit card numbers, well, maybe,

0:52:59.540 --> 0:54:02.140
<v B>like maybe someone, let's say someone has a person's name. They're trying to find their credit card number and maybe they have some access to the database. And so they have all these hashed credit card numbers. If you do something that's not cryptographically secure, then they can use various statistical tricks to try to reverse engineer that, or maybe they can narrow down. If they have a list of credit card numbers, they can narrow down which one it is. And so if you're storing something really sensitive, using a cryptographically secure one has some nice guarantees. Or if speed is not super critical. And so that's why something like Git, for example, Git will use SHA-256, which is cryptographically secure. Now you might not be storing passwords—and get in fact, you probably should never be storing passwords and get. But they do that because it's on almost all the computers, and that's not the thing that's going to slow you down. If you're using Git, like you're not blocked by the hash.

0:54:02.140 --> 0:55:02.460
<v A>Jason, there's one more point there too that I was kind of unaware of because I don't build these kinds of services. But another reason to make sure to use cryptographic hashes is if you have sort of a public service in some way, or an API that isn't only trusted users—I guess—that is backed by a hash map and the keys in some way are like basically user defined. So I'm creating a username or I'm creating something that I can kind of control. And if someone can deduce what hash function you're using and insert entries which all collide, all go to the same hash, then they can basically cause a denial of service. We'll talk about why in sort of a minute, but that's another reason why if you have a public API of some nature where you're going to back it by a hash, you want to be really careful that someone can't cause like force hash collisions to occur and thereby slow or denial of service your service.

0:55:03.120 --> 0:57:02.300
<v B>Yeah. Yeah. That makes sense. Yeah. I think yeah. So just using Git is a good example. Like, so let's say someone creates like 10 million Git commits that all have the same content in them. Right? Well, and you're running like a Git website, like you're hosting Git for other people as your job. Right? So you're probably going to write some rule. It says, look, if this person makes the same commit all these times, it all have the same content, that I'm going to block them or I'm going to block them and send an email saying, 'Your account's been compromised,' or what have you, or something bad has happened. Right? On the flip side, maybe someone is creating a whole bunch of different commits with different content because they are writing some script that's automatically converting all the tabs to spaces and all their files or something. And for whatever reason, it's creating a lot of commits. And so that might be normal. Right? And so getting to Patrick's point, like someone could actually, if it's not a cryptographically secure hash function, they could actually figure out a way to be making a lot of different changes, but they're all hashing to the same hash and creating all sorts of problems there. And so it'd be very hard to fix that. But you know, there are times—I mean, a good example of a time to use a hash that's not crypto secure is when you're doing these big data ETL things. So when you're doing like a MapReduce or Spark or one of these things. So just to not sidetrack too much, but the way MapReduce works is you have this enormous volume of data somewhere. And let's say you just want to build a histogram of it. So you want to count the number of times you see Patrick; you want to count the number of times you see the word Jason; you want to count the number of times you see the word programming throwdown. So the way MapReduce will do this is, you know, it will have a ton of different machines that are going to just take a small

0:57:02.300 --> 0:58:29.380
<v B>piece of this massive data set and count the Patricks and the Jasons and the programming throwdowns. And so then it's going to hash all of those names, right? So Patrick is going to hash to some kind of number. Jason's going to hash some kind of number. Program throwdown is going to hash to a number. And then it's going to, based on that number, send it to what's called a reducer. And so if you have, let's say 10 reducers, you might say, 'Well, all those numbers that end in a zero go to the first reducer. All those numbers that end in a one go to the second reducer.' I guess you'd need 11 reducers, but anyway. So right. So then you—the reducer is going to collect all that information. And so a single reducer knows it's going to have all the Jasons because Jason is always going to hash to the same thing. And so that's how MapReduce works. But for MapReduce, as I said, you're processing these massive data sets and it's not really a cryptography thing. Like there's not really any concern about that. And so MapReduce, at least back when I was working on a long time ago, used Murmur. Now it might be using XXHash, which has been proven to be a lot faster. But you know, that's something where actually saving that bit of time by using Murmur instead of SHA will actually really matter because the computation there.

0:58:29.620 --> 0:59:41.080
<v A>And so the hash and hash maps is needed because ultimately what you're trying to do is take some key—and we should mention, I guess, hash maps and hash sets are kind of interchangeable. Like it's just kind of the underlying fundamentals are the same as just what data type you use, whether it's just the key only or the key plus some data. And so what you're trying to do with the hash is take arbitrary data, mix it up, combine it, do something in some way to go from an arbitrary any input size of bytes. Imagine a string and you don't know the length of the string, right? It could be Bob, and it could be Sir Ferdinand the Great. I don't know, like something really big, and you want to combine it all down. And let's say you want only one byte to represent all of that data. How do you mix it up so that your keys are as evenly distributed as possible across your key space? Now, the other thing you have is you have the hash function, which goes from an arbitrary number of bytes—usually like for the ones Jason was mentioning—to, you know, four bytes or eight bytes for 64 bits or 256 bytes would be what? 16 bytes? No. Yeah, that's true.

0:59:42.620 --> 1:01:36.040
<v A>So you end up having, say, let's say four bytes, right? But that's still two to the 32. That's a lot of keys and getting constant time. You have something called a bucket, and a bucket is taking a key and having—you can think of it as an array of a size. So if you know 256 bit is 32 bytes. There we go. Thank you. That makes sense. And so you have these buckets, and the buckets are like slots in your array. So say I have I want to make my array small to begin with. So I have seven buckets, seven elements in my array. And I have a four byte hash result, right? So I need to get from four bytes down to seven. And the way you do that typically—I mean, there's other variation is a modulus. And if you do the modulus of, you know, two to the 32, whatever the value is, modulus seven, then it'll just keep wrapping around and you'll find which slot to put your item in. Now, there is interplay as well that we won't get into about how to choose that when you want more slots than seven. Like what do you choose as your next? Do you choose eight? Do you choose another prime number? Seven's prime. And there's some tradeoffs there. But ultimately, you're taking this hash function and fitting it into your buckets of some size. Now, the size is determined in part by one of the design factors that can end up sort of breaking the constant time assumption by something called the load factor. So the load factor is how many items you have stored in your hash map divided by your current number of buckets. So if you have buckets that are size seven and you have 14 items you tried to store in seven buckets, then clearly you're going to have at least some collisions and your load factor would be two.

1:01:37.680 --> 1:02:45.020
<v A>Now, when you have collisions—two things mapping to the same slot—there's a variety of ways of handling it. We'll talk about that in sort of a minute. But in all of the cases, the bigger your load factor gets, in some hash maps, they try to keep or must keep the load factor under one. In other cases, you could allow it to grow above one. But in both times, once the load factor gets too high, you start breaking your constant time assumption. You end up going to linear time, which is worse than logarithmic time. And so you have to be really careful with this load factor. Now, where the load factor game comes into play is that you end up using more memory because the smaller your load factor is, you're effectively wasting memory. So if I say, 'Oh, I'm just going to create a billion entry array and I'm just going to hash everything to it and I'm not going to worry about hash collisions.' Okay, cool. Except that billion element array is really big in memory and it's mostly sitting empty. So there's a tradeoff between memory usage and speed. Yeah.

1:02:45.020 --> 1:03:42.032
<v B>Yeah. So, I mean, what makes the hash table or hash map or hash set, what makes these things so fast is that hashing is turning some content into a number. And that number is then used as an index. And so if you have an array, getting an item from that array from its index is super fast. And so you're kind of turning like you're doing sort of an association, right? That's turning strings or whatever you want into indices and then just putting it into that spot. But yeah, as Patrick said, the problem is that only makes sense if the array has already been totally allocated in memory and you can go to spot five by doing some arithmetic. And so for that whole thing to work, there has to be something, even if it's just empty in spot four and spot three and spot two and spot one; like that space has to be occupied.

1:03:42.780 --> 1:05:01.920
<v A>So we were kind of getting at this load factor hashing about changing your data into a sort of number, modulusing that number by the number of buckets you have, and then looking in that slot. Now, what happens if two things map to the same slot? So it turns out there's roughly two strategies for dealing with it. The first one is called closed addressing. So an example of this is the C++ STL library for their unordered_map and unordered_set use closed addressing. And there's some variation and complexity about what they do. But roughly what ends up happening is if you have a collision, because you could have seven buckets and you insert your first item in index one, and then your second thing hashes and you also inserted in text one. So you have only two things, but they collided. And what would happen in the STL library with closed addressing is you would just make a linked list. So you would put them in the same bucket, but there would be a list. And so when you go to do a lookup, you get the bucket and you say, does my key match the key in the first at the head of the linked list? If not, go traverse the linked list until you either find the match or you find out that it's not in your set. So that's closed addressing.

1:05:01.920 --> 1:05:49.040
<v B>Yeah, actually, one thing I wanted to just mention there is, yeah, you have to keep the original key because when you hash something, you've kind of destroyed the original value. Like if I hash JSON, it's going to give me 13 or something like that. And so now JSON is gone, right? And so in the hash table, when you go to spot 13, you actually still need to store the key again. And that's one thing that kind of confuses a lot of new people when they see hash tables. And so, yeah, so that's to Patrick's point. Like if you're looking for JSON, just because you got to 13, it doesn't mean that you found JSON because it could have been something else hashed to 13. So that's where you would actually look through that list and say, 'OK, is there an actual JSON here?' And if that list gets really long, that's going to take a long time.

1:05:49.440 --> 1:06:30.220
<v A>Hot tip here, too, is I think every one of these things we're calling out, I've heard personally in an interview I've been in, done or listened to. So if you're going to do an interview for a job in Silicon Valley, like every one of these caveats I think we've mentioned so far has come up, at least in my experience. So the nuances here, if for no other reason than interviewing ability are important. But they do actually impact when you get into the subtleties of how your HashMap is performing. Because I do know a lot of people who just slap in a HashMap and assume it works and then move on. And they don't actually measure to see if it's an improvement or if they should tune it.

1:06:30.985 --> 1:07:49.099
<v B>Yeah, one of the things that I was really fascinated by, again, working—so you know, MapReduce—like working on MapReduce was definitely the time where I was really exposed to a lot of these things. Because at scale is when you'll really start to see all of the challenges get exposed. And MapReduce switched from using Quicksort to Merge Sort. The reason is because, you know, Quicksort and Merge Sort have the same runtime on average. But if you pick bad pivots, which could happen because the data is just structured a certain way and you're expecting totally random or arbitrarily distributed data, there's actually times where Quicksort would, you know, consistently for this one MapReduce, Quicksort would take almost linear time. And, you know, this is over, you know, like billions and billions of items. So it just—it would basically never finish. And so, and so we ended up switching everything to Merge Sort. And so I think, and so that's—that's one of these challenges with hash tables too, is, especially if you're doing something at scale, is you want to monitor the number of collisions and also something called the smearing, which is just a

1:07:50.871 --> 1:08:17.980
<v B>like another word for the entropy, really. But you want to measure the entropy of your hash table. So in other words, you want to see that a lot of the items in the hash table, a lot of the cells in the hash table are like these are either empty or filled with one, two, or three things. And yeah, just keep a constant eye on it. And you're right. It does come up a lot in interviews, trying to understand that whole—like understanding all of those dynamics.

1:08:18.540 --> 1:10:16.182
<v A>So if we gave the name closed addressing, it doesn't take much, I guess, to figure out the alternative is open addressing. So if you end up with a collision and you're using an open addressing HashMap, then you use some mechanism for finding another bucket, another slot in your array to go look at, to see if your key is there. The easiest one to think about is when inserting: if I insert and there's already something there, then I just do my bucket plus one. And then I look, is there something there? And if so, go bucket plus two, right? I just keep walking down, and you could do linear probe, quadratic probe, right? You're just basically looking and kind of iterating through all of the buckets, looking for one that's open. And then at accessing, you just do kind of like the opposite. You would go to your array. If that item—if the bucket is empty, you're done. But if the bucket has an item and it doesn't match your key, then you have to follow sort of the same probing as the insertion algorithm used. And there's a variety of these. And these actually, and I'll talk about one in a second, but there's Cuckoo Hashing, Robin Hood Hashing. So like in Robin Hood Hashing, you measure how far away from your original slot each element is. And you use that to decide whether to keep looking or to displace the elements that they're put yours in and then move that one further down. So that you're trying to get your keys as close to their original bucket as possible. And the reason why these end up mattering, and why this versus like the linked list approach from closed addressing matters is because again, algorithmically, these are constant time insertion and lookup on average. But in practice, you have problems with cache efficiency. In a linked list, if I don't pay attention, I go look up one key and then it's not correct.

1:10:16.960 --> 1:11:15.519
<v A>And so I have to traverse the linked list, but that item in memory could be at an entirely different place in RAM, just based on wherever I got it from my allocator off the heap. And I have to wait for the processor to go through all of its caches out to RAM, pull in that value, and access it. Right? So the cache efficiency there is very different than if I have two slots in an array, which will be consecutive in memory. And I just need to look at the first one and then the second one, because the way the processor works is it doesn't just fetch your value from RAM into cache. It fetches—it's called sort of a cache line. It fetches a bunch of memory all at once into the cache. And then so it expects that your next lookup is close to your first lookup when you're accessing memory. And so these open addressing ones try to leverage that realization to make much more cache efficient ways of accessing the hash buckets.

1:11:16.840 --> 1:11:23.080
<v B>So, yeah, one question: when you're doing the open addressing, how do you know when to stop? Like, let's say the hash table's full, right?

1:11:23.080 --> 1:12:05.420
<v A>Yep. So you stop when either you get to an empty bucket or when you have—if it's completely full and you've gone all the way around. But these are much more sensitive. Closed addressing, and I might—someone will tell me I'm wrong. That's fine. Closed addressing. You can have a load factor over one; open addressing, you could never have a load factor over one, right? It'll crash or something, right? Cause it just won't be able to insert. Like, yeah, you have no—you can't insert the last thing as soon as you go over one. And if you have one, then you're right. Any checking for any value not in the set will require you to iterate all buckets. Yeah. Yeah.

1:12:05.420 --> 1:12:17.420
<v B>Yeah. The only alternative would be, you'd have to also store the hash. So like in every bucket you'd have to store what the hash would have been if there were no collisions.

1:12:17.940 --> 1:12:34.962
<v A>Yes. There are. So there are also hybrid, hybrid hash maps. I think that kind of start to use a rehashing method. So rather than using a single hash, you use a different seed and you hash again, or multiple bucket lists. But yeah, so.

1:12:34.962 --> 1:13:19.540
<v B>I was saying something a little different. I was saying like, so let's say you're doing linear probing, right? And so but—but let's say in the hash table, along with the key, you're also storing the hash of the key, or I guess you could just do it on the fly. So like if you're doing the linear probing and you know you're looking for Apple and Apple hashes to two, and then you go to the second index and it's Dog, right? And so you go, you do linear probing. So you go to the next one. And that item, whatever that is, if it doesn't hash to two, then you know to stop, even if the hash table is full. But then like, you're either like doing a lot of hashes or you'd have to somehow like store the hash or something. Yeah. Does that make sense?

1:13:19.700 --> 1:13:30.260
<v A>Maybe I don't want to get into a design review of your algorithm. I feel something else could be hashed to three. So you could have some dog was hashed at three.

1:13:30.640 --> 1:13:50.815
<v B>Yeah. But I'm saying like, okay, so let's say the thing you're searching for your query hashes to two, right? And you go to that spot and there's something that hashes to two, but it's not your item. Right? So then you go to the next spot. And if that thing in that next spot doesn't hash to two, then you're done. Right? But I'm

1:13:51.270 --> 1:13:52.960
<v A>saying something else could have already been there.

1:13:53.200 --> 1:13:55.740
<v B>Yeah. Oh, and then you have to jump over it.

1:13:56.120 --> 1:13:56.440
<v A>Yes.

1:13:56.740 --> 1:14:41.980
<v B>Oh, and actually, actually, now I think about it. So this is, this is—yeah, this is bringing back a lot of memories. So actually when you, when you, if there's something that doesn't hash to two in that spot that you're in right now, it could be that Apple is still there. It just got there too late. Yes. And like someone else. Oh yeah. Okay. So yeah, you're right. You have to go through the entire hash table worst case. Yeah. See, I would totally fail. Actually, just, just to circle back something you said earlier, I've actually never had a hash table kind of question, but—but you could tell I would totally fail that. But I think it is super important. I think, you know, don't panic if like your background is in something else. I don't know if you'll get maybe these kinds of questions, but it's still really good to know.

1:14:42.340 --> 1:16:25.180
<v A>Okay. I've seen good interviews and bad interviews. I won't speak to bad interviews, but in good interviews, I think they're actually hoping you don't know the answer because they don't care. They want you to be able to like Jason just did, like, well, have this idea. Oh wait, this idea doesn't work. And then, you know, be able to make the progression to refining your idea or discovering something that's already in literature that maybe your interview already knows about. But they're letting you sort of do it from first principles and seeing how your brain unpacks the problems. Yeah, it's a good call. So, if you really, really want the cheat code, then there's something called the minimal perfect hash. So the idea here is if you know upfront all the items you're going to hash—say 397 of them—then you make exactly 397 buckets. And you find the hash function, which one-to-one maps all of your input keys to your bucket list with zero collisions. These are pretty cool because you have a perfectly space efficient answer. And the only problem is how do you search the space of hash functions to find such a perfect hash? And there's a class of ones that you can narrow in on and how to structure this problem. It's a very interesting, I guess, sort of research topic. I've never seen it used in practice, but it is a really cool idea that you could have the best of all worlds: a constant time lookup, no wasted space, you know, a load factor of one, and guarantee that you would instantly know if a key is in your set or not. Like, it's just, it's really awesome. The problem is it becomes very, very expensive to find this perfect hash.

1:16:25.900 --> 1:18:20.180
<v B>Yeah, that makes sense. Yeah, I mean, the only way I could think to do it as a person who has no experience would be to just try adding salt and just keep doing that until—but that's going to take forever. I mean, the odds that... You've just discovered Bitcoin, my name. Yeah, I guess so. Yeah, I think, I mean, the odds that you eventually hit that right hash are just taking... Oh, for people who don't know, a salt is very simple. It's something that you add to all of your keys that just make the hashing work differently. Oh, yeah, yeah. Okay. And the reason why—correct me if I'm wrong on this or feel free to fill in the holes here—but I think the reason why they use salt is not to try and find better hash functions, but it's to... The idea is the salt is something that you as the programmer know, but someone on the outside doesn't know. And so if someone, let's say, gets a hold of your database, but they don't know your salt because they don't have the source code, then there are certain tricks that they can't use. Like, for example, let's say someone has a database full of hashed passwords. Well, they know that a lot of people out there make their password the word 'password.' So they'll just run, like, the hash function. They'll look at all the popular hash functions and run them all on the word 'password' and see the numbers that come out of that, or the hash—let's say, that comes out of that—and just see, like, okay, which of these hashes is in your database a lot? Like, okay, it's this one; therefore you're using this type of hash function, and then knowing that allows them to do a bunch of other things. But if you've put a salt in, now you don't have a whole bunch of hashed words of 'password.' Now you have a bunch of hashes of, you know, my cool salt password, and my cool salt aba, and my cool salt Patrick, and whatever.

1:18:20.180 --> 1:20:19.420
<v B>And just like, you know, even though you added the same thing to every key, it's going to cause the hashes to be totally different. Yep, that's right. And so, yeah, I think, so getting back to Patrick's thing, like, you could just try adding, trying different salts until you get one that hashes these 300 things in the 300 unique integers after you've modded them. But that will take forever. Not forever—just a long time. Not literally forever. But yeah, really, really, really long time. Yeah, I mean, definitely, I mean, intractably long time. Like, not long as in come back in a week. Long as in like your whole lifetime. Like, more than that. Another thing that I've used hashing a lot for is, which is like very different from the traditional hashing but still really useful, is locality-sensitive hashing. And this is kind of the opposite of everything we just talked about for, like, goals for hashing. In locality-sensitive hashing, you actually want things that are similar to hash to the same number. Right? So imagine, like, imagine a map. Right? Like, a map of United States. Right? And you have a bunch of points on the map. And so, you know, maybe all the points represent different businesses or something. Right? And so, in this case, like, you want to hash the points that are close together to the same number. Because that number is going to represent, let's say, a file on disk that has all the names of the businesses. And so, you know, when you're looking on, like, Google Maps, you're probably looking at a whole area. And so you're probably looking at a bunch of businesses, but they're all close together spatially. You want to hash all of those to the same number so that all the names of the businesses come from the same file on disk. Right? And so that's locality-sensitive hashing. And so, you know, in that case, you're not worried about collisions.

1:20:19.420 --> 1:21:02.720
<v B>It's kind of a different use case. But you still get a lot of benefit. You get a lot of the order one type benefit. So imagine if you now have a bunch of these points from your map, or maybe even you have a region of points, right? And you can feed this through this locality-sensitive hash. Maybe feed the boundaries or Monte Carlo it or what have you. And it'll say, okay, the hashes are 3, 4, and 5. And then you can load those files, which might have, you know, businesses that are outside of the range, but they're all going to be kind of in that area because of the way you've done the hashing. And that's how, you know, a lot of these kind of spatial databases work. Awesome.

1:21:03.220 --> 1:21:05.200
<v A>Yeah, this is a really good episode. This is very fun.

1:21:06.713 --> 1:21:36.960
<v B>Yeah, I mean, hash tables and trees, you know, it's sort of like there's that saying that, you know, with a linear saw and a hammer, you can do just about anything. Like you build a whole house just with a linear saw and a hammer. I feel like trees and hash tables are kind of like that for us. Like with trees and hash tables, you know, you can build just about, you know, and I mean, I would like things like arrays and algebra. I mean, that's all primitives, right? But with those two data structures, you could build just about everything.

1:21:37.380 --> 1:21:38.680
<v A>And a 55-gallon drum of water.

1:21:39.460 --> 1:21:40.700
<v B>Yeah, that's right.

1:21:42.252 --> 1:21:53.204
<v B>You could pass the Computer Science GRE with a 55-gallon drum of water, a water computer, and trees and hash tables.

1:22:03.520 --> 1:22:08.880
<v A>Music by Eric Barmeller.

1:22:08.880 --> 1:22:35.900
<v B>Programming Throwdown is distributed under a Creative Commons Attribution ShareAlike 2.0 license. You're free to share, copy, distribute, transmit the work to remix and adapt the work, but you must provide an attribution to Patrick and I and share alike in kind. Does the

