-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_map.casa
More file actions
59 lines (58 loc) · 1.04 KB
/
hash_map.casa
File metadata and controls
59 lines (58 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import "std"
# Create a Map[str int]
Map::new(Map[str int]) = m
# Set some key-value pairs
# fn set[K: Hashable, V] self:Map[K V] key:K value:V -> Map[K V]
1 "one" m.set = m
2 "two" m.set = m
3 "three" m.set = m
# Get values
"one" m.get.unwrap print
"\n" print
"two" m.get.unwrap print
"\n" print
"three" m.get.unwrap print
"\n" print
# Check length
m.length print
"\n" print
# Check has
"one" m.has print
"\n" print
"four" m.has print
"\n" print
# Update existing key
42 "one" m.set = m
"one" m.get.unwrap print
"\n" print
# Delete a key
"two" m.delete = m
m.length print
"\n" print
"two" m.has print
"\n" print
# Create a Map[int str]
Map::new(Map[int str]) = m2
"hello" 1 m2.set = m2
"world" 2 m2.set = m2
1 m2.get.unwrap print
"\n" print
2 m2.get.unwrap print
"\n" print
# Create a Set[str]
Set::new(Set[str]) = s
"apple" s.add = s
"banana" s.add = s
"cherry" s.add = s
s.length print
"\n" print
"apple" s.has print
"\n" print
"grape" s.has print
"\n" print
# Remove from set
"banana" s.remove = s
s.length print
"\n" print
"banana" s.has print
"\n" print