Skip to content

Commit f66b0b1

Browse files
committed
Book Updates
-add chapter 5.3
1 parent 590e675 commit f66b0b1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

book/chapter5.3.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: "Chapter 5.3"
3+
---
4+
5+
# Chapter 5.3: Unique Collections
6+
7+
GLang provides a unique collection in its standard library, [`std_hashmap`](/docs/modules/std_hashmap).
8+
9+
The `std_hashmap` module isn’t built in by default, so you’ll need to import it using the `fetch` keyword. We’ll cover `fetch` in more detail later, but for now, just add it to the top of your file.
10+
11+
```
12+
fetch std_hashmap;
13+
14+
obj my_hashmap = hashmap();
15+
hashmap_set(my_hashmap, "name", "Bob");
16+
hashmap_set(my_hashmap, "favorite-color", "Green");
17+
````
18+
19+
A hashmap is a collection of key–value pairs, think of it like a small, efficient lookup table.
20+
21+
| Key | Value |
22+
| ---------------- | ------- |
23+
| `name` | `Bob` |
24+
| `favorite-color` | `Green` |
25+
26+
You can **set** new entries by providing a key and value, or **get** existing values by their corresponding keys.
27+
28+
```
29+
fetch std_hashmap;
30+
31+
obj my_hashmap = hashmap();
32+
hashmap_set(my_hashmap, "name", "Bob");
33+
34+
obj name = hashmap_get(my_hashmap, "name"); # 'Bob'
35+
```

0 commit comments

Comments
 (0)