You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: deque/README.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,6 +38,27 @@ let dq : Deque[Int] = Deque::new()
38
38
dq.is_empty() // true
39
39
```
40
40
41
+
You can use `reserve_capacity` to reserve capacity, ensures that it can hold at least the number of elements
42
+
specified by the `capacity` argument.
43
+
44
+
```moonbit
45
+
let dq = Deque::[1]
46
+
dq.reserve_capacity(10)
47
+
println(dq.capacity()) // 10
48
+
```
49
+
50
+
Also, you can use `shrink_to_fit` to shrink the capacity of the deque.
51
+
52
+
```moonbit
53
+
let dq = Deque::with_capacity(10)
54
+
dq.push_back(1)
55
+
dq.push_back(2)
56
+
dq.push_back(3)
57
+
println(dq.capacity()) // 10
58
+
dq.shrink_to_fit()
59
+
println(dq.capacity()) // 3
60
+
```
61
+
41
62
### Front & Back & Get
42
63
43
64
You can use `front()` and `back()` to get the head and tail elements of the queue, respectively. Since the queue may be empty, their return values are both `Option`, or `None` if the queue is empty.
0 commit comments