mirror of
https://github.com/duke-git/lancet.git
synced 2026-03-01 00:35:28 +08:00
Compare commits
5 Commits
4eeeabb227
...
v2.1.5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1acf977b24 | ||
|
|
5c878d0873 | ||
|
|
ab0716a472 | ||
|
|
3c2e0ca5b3 | ||
|
|
551e66ba29 |
@@ -4,7 +4,7 @@
|
|||||||
<br/>
|
<br/>
|
||||||
|
|
||||||

|

|
||||||
[](https://github.com/duke-git/lancet/releases)
|
[](https://github.com/duke-git/lancet/releases)
|
||||||
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
||||||
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
||||||
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
||||||
@@ -50,7 +50,7 @@ import "github.com/duke-git/lancet/v2/strutil"
|
|||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
Here takes the string function ReverseStr (reverse order string) as an example, and the strutil package needs to be imported.
|
Here takes the string function Reverse (reverse order string) as an example, and the strutil package needs to be imported.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -62,7 +62,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := "hello"
|
s := "hello"
|
||||||
rs := strutil.ReverseStr(s)
|
rs := strutil.Reverse(s)
|
||||||
fmt.Println(rs) //olleh
|
fmt.Println(rs) //olleh
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -435,7 +435,7 @@ import "github.com/duke-git/lancet/v2/strutil"
|
|||||||
- [UpperFirst](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#UpperFirst)
|
- [UpperFirst](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#UpperFirst)
|
||||||
- [PadEnd](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#PadEnd)
|
- [PadEnd](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#PadEnd)
|
||||||
- [PadStart](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#PadStart)
|
- [PadStart](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#PadStart)
|
||||||
- [ReverseStr](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#ReverseStr)
|
- [Reverse](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#Reverse)
|
||||||
- [SnakeCase](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#SnakeCase)
|
- [SnakeCase](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#SnakeCase)
|
||||||
- [SplitEx](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#SplitEx)
|
- [SplitEx](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#SplitEx)
|
||||||
- [Wrap](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#Wrap)
|
- [Wrap](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#Wrap)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<br/>
|
<br/>
|
||||||
|
|
||||||

|

|
||||||
[](https://github.com/duke-git/lancet/releases)
|
[](https://github.com/duke-git/lancet/releases)
|
||||||
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
||||||
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
||||||
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
||||||
@@ -50,7 +50,7 @@ import "github.com/duke-git/lancet/v2/strutil"
|
|||||||
|
|
||||||
## 例子
|
## 例子
|
||||||
|
|
||||||
此处以字符串工具函数ReverseStr(逆序字符串)为例,需要导入strutil包:
|
此处以字符串工具函数Reverse(逆序字符串)为例,需要导入strutil包:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -62,7 +62,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
s := "hello"
|
s := "hello"
|
||||||
rs := strutil.ReverseStr(s)
|
rs := strutil.Reverse(s)
|
||||||
fmt.Println(rs) //olleh
|
fmt.Println(rs) //olleh
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -431,7 +431,7 @@ import "github.com/duke-git/lancet/v2/strutil"
|
|||||||
- [UpperFirst](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#UpperFirst)
|
- [UpperFirst](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#UpperFirst)
|
||||||
- [PadEnd](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#PadEnd)
|
- [PadEnd](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#PadEnd)
|
||||||
- [PadStart](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#PadStart)
|
- [PadStart](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#PadStart)
|
||||||
- [ReverseStr](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#ReverseStr)
|
- [Reverse](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#Reverse)
|
||||||
- [SnakeCase](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#SnakeCase)
|
- [SnakeCase](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#SnakeCase)
|
||||||
- [SplitEx](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#SplitEx)
|
- [SplitEx](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#SplitEx)
|
||||||
- [Wrap](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#Wrap)
|
- [Wrap](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#Wrap)
|
||||||
|
|||||||
@@ -53,11 +53,11 @@ func (hm *HashMap) Get(key any) any {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Put new key value in hashmap
|
// Put new key value in hashmap
|
||||||
func (hm *HashMap) Put(key any, value any) any {
|
func (hm *HashMap) Put(key any, value any) {
|
||||||
return hm.putValue(hm.hash(key), key, value)
|
hm.putValue(hm.hash(key), key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hm *HashMap) putValue(hash uint64, key, value any) any {
|
func (hm *HashMap) putValue(hash uint64, key, value any) {
|
||||||
if hm.capacity == 0 {
|
if hm.capacity == 0 {
|
||||||
hm.capacity = defaultMapCapacity
|
hm.capacity = defaultMapCapacity
|
||||||
hm.table = make([]*mapNode, defaultMapCapacity)
|
hm.table = make([]*mapNode, defaultMapCapacity)
|
||||||
@@ -68,14 +68,11 @@ func (hm *HashMap) putValue(hash uint64, key, value any) any {
|
|||||||
hm.table[hash] = newMapNode(key, value)
|
hm.table[hash] = newMapNode(key, value)
|
||||||
} else if node.key == key {
|
} else if node.key == key {
|
||||||
hm.table[hash] = newMapNodeWithNext(key, value, node)
|
hm.table[hash] = newMapNodeWithNext(key, value, node)
|
||||||
return value
|
|
||||||
} else {
|
} else {
|
||||||
hm.resize()
|
hm.resize()
|
||||||
return hm.putValue(hash, value, value)
|
hm.putValue(hash, value, value)
|
||||||
}
|
}
|
||||||
hm.size++
|
hm.size++
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete item by given key in hashmap
|
// Delete item by given key in hashmap
|
||||||
|
|||||||
208
docs/datastructure/hashmap.md
Normal file
208
docs/datastructure/hashmap.md
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
# HashMap
|
||||||
|
|
||||||
|
HashMap is a key value map data structure.
|
||||||
|
|
||||||
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
- [https://github.com/duke-git/lancet/blob/main/datastructure/hashmap/hashmap.go](https://github.com/duke-git/lancet/blob/main/datastructure/hashmap/hashmap.go)
|
||||||
|
|
||||||
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
## Index
|
||||||
|
|
||||||
|
- [NewHashMap](#NewHashMap)
|
||||||
|
- [NewHashMapWithCapacity](#NewHashMapWithCapacity)
|
||||||
|
- [Get](#Get)
|
||||||
|
- [Put](#Put)
|
||||||
|
- [Delete](#Delete)
|
||||||
|
- [Contains](#Contains)
|
||||||
|
|
||||||
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
### <span id="NewHashMap">NewHashMap</span>
|
||||||
|
|
||||||
|
<p>Make a HashMap instance with default capacity is 1 << 10.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func NewHashMap() *HashMap
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hm := heap.NewHashMap()
|
||||||
|
fmt.Println(hm)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="NewHashMap">NewHashMap</span>
|
||||||
|
|
||||||
|
<p>Make a HashMap instance with given size and capacity.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func NewHashMapWithCapacity(size, capacity uint64) *HashMap
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hm := heap.NewHashMapWithCapacity(uint64(100), uint64(1000))
|
||||||
|
fmt.Println(hm)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="Get">Get</span>
|
||||||
|
|
||||||
|
<p>Get the value of given key in hashmap</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (hm *HashMap) Get(key any) any
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hm := heap.NewHashMap()
|
||||||
|
val := hm.Get("a")
|
||||||
|
|
||||||
|
fmt.Println(val) //nil
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="Put">Put</span>
|
||||||
|
|
||||||
|
<p>Put new key value in hashmap, then return value</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (hm *HashMap) Put(key any, value any) any
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hm := heap.NewHashMap()
|
||||||
|
hm.Put("a", 1)
|
||||||
|
|
||||||
|
val := hm.Get("a")
|
||||||
|
fmt.Println(val) //1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="Delete">Delete</span>
|
||||||
|
|
||||||
|
<p>Delete key-value item by given key in hashmap.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (hm *HashMap) Delete(key any)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hm := heap.NewHashMap()
|
||||||
|
hm.Put("a", 1)
|
||||||
|
val := hm.Get("a")
|
||||||
|
fmt.Println(val) //1
|
||||||
|
|
||||||
|
hm.Delete("a")
|
||||||
|
val = hm.Get("a")
|
||||||
|
fmt.Println(val) //nil
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="Contains">Contains</span>
|
||||||
|
|
||||||
|
<p>Checks if given key is in hashmap or not.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (hm *HashMap) Contains(key any) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hm := heap.NewHashMap()
|
||||||
|
hm.Put("a", 1)
|
||||||
|
|
||||||
|
fmt.Println(hm.Contains("a")) //true
|
||||||
|
fmt.Println(hm.Contains("b")) //false
|
||||||
|
}
|
||||||
|
```
|
||||||
209
docs/datastructure/hashmap_zh-CN.md
Normal file
209
docs/datastructure/hashmap_zh-CN.md
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
# HashMap
|
||||||
|
|
||||||
|
HashMap 数据结构实现
|
||||||
|
|
||||||
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
## 源码
|
||||||
|
|
||||||
|
- [https://github.com/duke-git/lancet/blob/main/datastructure/hashmap/hashmap.go](https://github.com/duke-git/lancet/blob/main/datastructure/hashmap/hashmap.go)
|
||||||
|
|
||||||
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
## 用法
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
## 目录
|
||||||
|
|
||||||
|
- [HashMap](#hashmap)
|
||||||
|
- [源码](#源码)
|
||||||
|
- [用法](#用法)
|
||||||
|
- [目录](#目录)
|
||||||
|
- [API 文档](#api-文档)
|
||||||
|
- [<span id="NewHashMap">NewHashMap</span>](#newhashmap)
|
||||||
|
- [<span id="NewHashMapWithCapacity">NewHashMapWithCapacity</span>](#newhashmapwithcapacity)
|
||||||
|
- [<span id="Get">Get</span>](#get)
|
||||||
|
- [<span id="Put">Put</span>](#put)
|
||||||
|
- [<span id="Delete">Delete</span>](#delete)
|
||||||
|
- [<span id="Contains">Contains</span>](#contains)
|
||||||
|
|
||||||
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
## API 文档
|
||||||
|
|
||||||
|
### <span id="NewHashMap">NewHashMap</span>
|
||||||
|
|
||||||
|
<p>新建默认容量(1 << 10)的HashMap指针实例</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func NewHashMap() *HashMap
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>例子:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hm := heap.NewHashMap()
|
||||||
|
fmt.Println(hm)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="NewHashMapWithCapacity">NewHashMapWithCapacity</span>
|
||||||
|
|
||||||
|
<p>新建指定容量和长度的HashMap指针实例.</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func NewHashMapWithCapacity(size, capacity uint64) *HashMap
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>例子:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hm := heap.NewHashMapWithCapacity(uint64(100), uint64(1000))
|
||||||
|
fmt.Println(hm)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="Get">Get</span>
|
||||||
|
|
||||||
|
<p>在hashmap中根据key获取值</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (hm *HashMap) Get(key any) any
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>例子:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hm := heap.NewHashMap()
|
||||||
|
val := hm.Get("a")
|
||||||
|
|
||||||
|
fmt.Println(val) //nil
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="Put">Put</span>
|
||||||
|
|
||||||
|
<p>将key-value放入hashmap中</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (hm *HashMap) Put(key any, value any) any
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>例子:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hm := heap.NewHashMap()
|
||||||
|
hm.Put("a", 1)
|
||||||
|
|
||||||
|
val := hm.Get("a")
|
||||||
|
fmt.Println(val) //1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="Delete">Delete</span>
|
||||||
|
|
||||||
|
<p>将指定的key从hashmap中删除</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (hm *HashMap) Delete(key any)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>例子:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hm := heap.NewHashMap()
|
||||||
|
hm.Put("a", 1)
|
||||||
|
val := hm.Get("a")
|
||||||
|
fmt.Println(val) //1
|
||||||
|
|
||||||
|
hm.Delete("a")
|
||||||
|
val = hm.Get("a")
|
||||||
|
fmt.Println(val) //nil
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="Contains">Contains</span>
|
||||||
|
|
||||||
|
<p>判断hashmap中是否包含指定的key</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (hm *HashMap) Contains(key any) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>例子:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hm := heap.NewHashMap()
|
||||||
|
hm.Put("a", 1)
|
||||||
|
|
||||||
|
fmt.Println(hm.Contains("a")) //true
|
||||||
|
fmt.Println(hm.Contains("b")) //false
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -32,7 +32,7 @@ import (
|
|||||||
- [UpperFirst](#UpperFirst)
|
- [UpperFirst](#UpperFirst)
|
||||||
- [PadEnd](#PadEnd)
|
- [PadEnd](#PadEnd)
|
||||||
- [PadStart](#PadStart)
|
- [PadStart](#PadStart)
|
||||||
- [ReverseStr](#ReverseStr)
|
- [Reverse](#Reverse)
|
||||||
- [SnakeCase](#SnakeCase)
|
- [SnakeCase](#SnakeCase)
|
||||||
- [SplitEx](#SplitEx)
|
- [SplitEx](#SplitEx)
|
||||||
- [Wrap](#Wrap)
|
- [Wrap](#Wrap)
|
||||||
@@ -430,13 +430,13 @@ func main() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
### <span id="ReverseStr">ReverseStr</span>
|
### <span id="Reverse">Reverse</span>
|
||||||
<p>Return string whose char order is reversed to the given string.</p>
|
<p>Return string whose char order is reversed to the given string.</p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func ReverseStr(s string) string
|
func Reverse(s string) string
|
||||||
```
|
```
|
||||||
<b>Example:</b>
|
<b>Example:</b>
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import (
|
|||||||
- [UpperFirst](#UpperFirst)
|
- [UpperFirst](#UpperFirst)
|
||||||
- [PadEnd](#PadEnd)
|
- [PadEnd](#PadEnd)
|
||||||
- [PadStart](#PadStart)
|
- [PadStart](#PadStart)
|
||||||
- [ReverseStr](#ReverseStr)
|
- [Reverse](#Reverse)
|
||||||
- [SnakeCase](#SnakeCase)
|
- [SnakeCase](#SnakeCase)
|
||||||
- [SplitEx](#SplitEx)
|
- [SplitEx](#SplitEx)
|
||||||
- [Wrap](#Wrap)
|
- [Wrap](#Wrap)
|
||||||
@@ -431,13 +431,13 @@ func main() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
### <span id="ReverseStr">ReverseStr</span>
|
### <span id="Reverse">Reverse</span>
|
||||||
<p>返回字符顺序与给定字符串相反的字符串</p>
|
<p>返回字符顺序与给定字符串相反的字符串</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func ReverseStr(s string) string
|
func Reverse(s string) string
|
||||||
```
|
```
|
||||||
<b>例子:</b>
|
<b>例子:</b>
|
||||||
|
|
||||||
|
|||||||
@@ -208,8 +208,8 @@ func IsString(v any) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReverseStr return string whose char order is reversed to the given string
|
// Reverse return string whose char order is reversed to the given string
|
||||||
func ReverseStr(s string) string {
|
func Reverse(s string) string {
|
||||||
r := []rune(s)
|
r := []rune(s)
|
||||||
for i, j := 0, len(r)-1; i < j; i, j = i+1, j-1 {
|
for i, j := 0, len(r)-1; i < j; i, j = i+1, j-1 {
|
||||||
r[i], r[j] = r[j], r[i]
|
r[i], r[j] = r[j], r[i]
|
||||||
|
|||||||
@@ -143,11 +143,11 @@ func TestIsString(t *testing.T) {
|
|||||||
assert.Equal(false, IsString([]string{}))
|
assert.Equal(false, IsString([]string{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReverseStr(t *testing.T) {
|
func TestReverse(t *testing.T) {
|
||||||
assert := internal.NewAssert(t, "TestReverseStr")
|
assert := internal.NewAssert(t, "TestReverse")
|
||||||
|
|
||||||
assert.Equal("cba", ReverseStr("abc"))
|
assert.Equal("cba", Reverse("abc"))
|
||||||
assert.Equal("54321", ReverseStr("12345"))
|
assert.Equal("54321", Reverse("12345"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWrap(t *testing.T) {
|
func TestWrap(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user