Golang Tutorial #15 - Maps

  Рет қаралды 37,716

Tech With Tim

Tech With Tim

Күн бұрын

Пікірлер: 43
@joshlakenan3676
@joshlakenan3676 Жыл бұрын
Just want to throw it out there that I don't think any of us watching just assume that you're lying about something until you prove otherwise. Thanks for the videos! :)
@tomdraper3588
@tomdraper3588 4 жыл бұрын
These tutorials are fantastic, thank you so much
@lucianodesa1
@lucianodesa1 4 жыл бұрын
Great videos! Just a small correction. The access time of any element within an array is also constant time O(1), in fact, being very simplistic, the underlying structure of a map is actually an array where its indexes are calculated using a hash algorithm and the "order" of the elements in a map is the ordering of its indexes generated by the hash algorithm.
@AXYGaming
@AXYGaming 4 жыл бұрын
Yes, infact maps are slower because of the hashing algorithm
@tylermorton2057
@tylermorton2057 4 жыл бұрын
+1 to this explanation :) To add to this, the way it was explained to me in college... Accessing an array element is O(1) because the entire array is stored in the same contiguous block of memory. If we know the memory address of the first element and we know the size of the array's element type, we can simply access the memory location of any index by multiplying that index by the data size and adding that value to the first element's memory address. For example, imagine we have an int array that contains 5 elements and the memory address of the pointer to the first element is at address 64. The size of each element in the array is 4 bytes (32 bit int). So to access the 4th element (index 3) in the array, we take "address + ( size * index)"... or 64 + ( 4 * 3 ) = 76. The 4th element's memory address is 76. This is an oversimplification and not exactly how memory addresses are stored and handled under the hood, but I hope it helps get the point across. Again, this is only able to be done because the array's memory is one contiguous block. This also explains why we must create new arrays when we want to add elements-- the memory block needs to be moved somewhere where there is space to facilitate the new elements being added in order to remain contiguous.
@mukhammadaminabdullaev4768
@mukhammadaminabdullaev4768 3 жыл бұрын
@@tylermorton2057 Good Explanation Bro!
@FeedFall8
@FeedFall8 4 жыл бұрын
Tim is best
@clyn465
@clyn465 Жыл бұрын
Tim is always great, thanks dude
@simonmarchant5520
@simonmarchant5520 3 жыл бұрын
Clear and concise, good vid
@rahamoosavi4368
@rahamoosavi4368 3 сағат бұрын
Thank you sooooo much Keep going🫶🏻
@MaximRovinsky
@MaximRovinsky 4 жыл бұрын
Super. Thank you!
@malu_1
@malu_1 Ай бұрын
nice vid !
@2cmarx
@2cmarx 2 жыл бұрын
Great video. Really enjoying your videos
@FPChris
@FPChris 2 жыл бұрын
Great videos. How do you loop through a map? Also the declaration seems unnecessarily long. Why do they require repeating map[string]int twice?
@Sergey_Latyshev
@Sergey_Latyshev 4 жыл бұрын
3:02 - it seems the words are in alphabetical order.
@erik.andri12
@erik.andri12 Жыл бұрын
Is it the same as python dictionary. But ia there any special function to call if the key exists for if else statement, like in python will be: if apple in mp. How to write this kind if else statement in GoLang?
@marupakanagaharshita6323
@marupakanagaharshita6323 4 жыл бұрын
It would be really helpful if you teach how to deal with nested data types in maps.
@mesayshemsu2134
@mesayshemsu2134 2 жыл бұрын
Nice Tutorial! Can you make tutorial for MapReduce?
@bedroomdevs3743
@bedroomdevs3743 2 жыл бұрын
did mine like so; // iterating with the range keyword numbers := []int{1,2,3,4,5,6,1,4, 7, 7} // print out duplicates in the above array for i, item := range numbers { set := numbers[i+1:] for _, element := range set { if item == element { fmt.Println(element) } } }
@jhonatanmaia5652
@jhonatanmaia5652 3 жыл бұрын
Fantastic video
@CSSuccessGamer
@CSSuccessGamer 4 жыл бұрын
nice video! what is golang useful for? I have already dedicated my life to python and dart and nothing else.
@RandomShowerThoughts
@RandomShowerThoughts 4 жыл бұрын
i started with Python, but Go is exceptional for rest servers, microservices, working with databases, caches, gRPC. I work at a company and we've made the transition to Go from python and we use it for our backend. It does authentication, rate limiting, routing, etc. We also use it for alot of dns stuff
@Jeppelelle
@Jeppelelle 4 жыл бұрын
What if one would want a mixed content map with both [string]string & [string]int in the same map for something like (pseudocode) var product { "product_id": 2934, "product_description": "Blekrj ekjreroe" } Is that possible?
@kilianvounckx9904
@kilianvounckx9904 4 жыл бұрын
There are 2 options I can think of. The first is using structs. Structs are the closed analog golang has to classes and objects if you are coming from an OOP language like python. You could make a struct which contains an integer and a string: type product struct { id int description string } This creates a new type named product which you can later use like any other type (int, string, float654, ...): p1 := product {id: 2934, description: "Blekrj ekjreroe"} The second method is using interface{}. When you use interface{} it basically means you can use any type you want. If you use a map with strings as keys and interfaces as values, you can get what you want: product := make(map[string]interface{}) product["id"] = 2934 product["description"] = "Blekrj ekjreroe" There are probably other solutions but these I can think of. Which you use will depend on your use case. I'm sure there will be more in depth tutorials about structs and interfaces in this series. They are pretty common in golang.
@GerardJonesYT
@GerardJonesYT 3 жыл бұрын
is possible with var p map[string]interface{} where interface{} could be any type
@abhishek7969
@abhishek7969 4 жыл бұрын
👍
@eyadali3637
@eyadali3637 4 жыл бұрын
What's the name of the vscode theme?
@din-paz
@din-paz 4 жыл бұрын
how to iterate all key and values in the map that your missing...
@senzanome8379
@senzanome8379 2 жыл бұрын
Geat video
@vasusubbannavar5789
@vasusubbannavar5789 4 жыл бұрын
Is Go an object oriented programming language?
@RandomShowerThoughts
@RandomShowerThoughts 4 жыл бұрын
somewhat, it has structs which can be thought of like classes. But there is no inheritance. That being said there are interfaces which you can use for polymorphism (duck typing) which is pretty awesome. Once a struct satisfies an interface with a set of functions we can use similar structs in functions. Obviously not the most in depth but wanted to chime in
@SSSNIPD
@SSSNIPD 4 жыл бұрын
Is this the same as a python dictionary?
@marcuslee678
@marcuslee678 4 жыл бұрын
Ya, it's somewhat similar
@ashafloki
@ashafloki 3 жыл бұрын
Noice
@buddybob5502
@buddybob5502 4 жыл бұрын
Guess what I am not first
@hououinkyouma5372
@hououinkyouma5372 3 жыл бұрын
So basically it's a hash map
@unperrier
@unperrier 2 жыл бұрын
Your "low-level" details are confusing because you mix two concepts, key/index and value: - You say that maps are fast because we can randomly access any data - And that arrays are slow because we may need to go through a bunch of data to get he one we want. The confusion is that you access maps by using a key, which fast (although not the fastest) and you access arrays using the value, not the index. But when using the index, arrays are much faster than maps because they're instantly and randomly accessible, it's just a simple arithmetic operation, whereas maps need to calculate a hash, and often handle hash collisions using a linked list which then need to be browsed element-by-element to find the right element. What you were supposed to say instead is that a map is much faster than a SORTED array.
@TrungNguyen-cc1ik
@TrungNguyen-cc1ik 3 жыл бұрын
the sound is not good I am quite disappointed
@crazycat2969
@crazycat2969 4 жыл бұрын
nice
@harshgandhi8049
@harshgandhi8049 4 жыл бұрын
How to deploy kivy app into android
@crazycat2969
@crazycat2969 4 жыл бұрын
noice
@crazycat2969
@crazycat2969 4 жыл бұрын
nice
Golang Tutorial #16 - Functions
14:29
Tech With Tim
Рет қаралды 32 М.
Golang Tutorial #22 - Interfaces
12:19
Tech With Tim
Рет қаралды 107 М.
I Sent a Subscriber to Disneyland
0:27
MrBeast
Рет қаралды 104 МЛН
Ozoda - Alamlar (Official Video 2023)
6:22
Ozoda Official
Рет қаралды 10 МЛН
Understanding Contexts in Go in 5(-ish?) Minutes
15:14
TutorialEdge
Рет қаралды 67 М.
Advanced Golang: Generics Explained
13:37
Code With Ryan
Рет қаралды 72 М.
Golang Tutorial #20 - Structs and Custom Types
18:49
Tech With Tim
Рет қаралды 52 М.
Go (Golang) Tutorial #12 - Maps
6:49
Net Ninja
Рет қаралды 37 М.
This is your last video about Golang Structs!
15:57
Flo Woelki
Рет қаралды 14 М.
Go Programming - JSON Encoding & Decoding in Golang
25:04
BugBytes
Рет қаралды 11 М.
The secret to making Golang error handling a breeze
13:46
Earthly
Рет қаралды 14 М.
I Sent a Subscriber to Disneyland
0:27
MrBeast
Рет қаралды 104 МЛН