List: add cap (#51)

Cap return cap of the inner data
This commit is contained in:
donutloop
2022-07-25 14:50:31 +02:00
committed by GitHub
parent 3d7600a9e4
commit c1b7500bcb
3 changed files with 48 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ import (
- [Clone](#Clone)
- [Merge](#Merge)
- [Size](#Size)
- [Cap](#Cap)
- [Swap](#Swap)
- [Reverse](#Reverse)
- [Unique](#Unique)
@@ -651,6 +652,36 @@ func main() {
### <span id="Cap">Cap</span>
<p>Cap return cap of the inner data</p>
<b>Signature:</b>
```go
func (l *List[T]) Cap() int
```
<b>Example:</b>
```go
package main
import (
"fmt"
list "github.com/duke-git/lancet/v2/datastructure/list"
)
func main() {
data := make([]int, 0, 100)
li := list.NewList(data)
fmt.Println(li.Cap()) // 100
}
```
### <span id="Swap">Swap</span>
<p>Swap the value at two index in list</p>