https://github.com/iamolegga/wildcard
Go wildcard
https://github.com/iamolegga/wildcard
Last synced: 7 months ago
JSON representation
Go wildcard
- Host: GitHub
- URL: https://github.com/iamolegga/wildcard
- Owner: iamolegga
- License: mit
- Created: 2020-05-18T19:27:01.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-12T03:26:10.000Z (over 2 years ago)
- Last Synced: 2025-01-14T00:32:39.305Z (9 months ago)
- Language: Go
- Homepage: https://pkg.go.dev/github.com/iamolegga/wildcard
- Size: 9.77 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wildcard
[](https://godoc.org/github.com/iamolegga/wildcard)
[](https://codeclimate.com/github/iamolegga/wildcard/maintainability)
[](https://codeclimate.com/github/iamolegga/wildcard/test_coverage)
[](https://goreportcard.com/report/github.com/iamolegga/wildcard)Package `wildcard` provides utils for working with a classic wildcard matching (only `?` and `*` are supported).
`Match` function is a golang's adaptation of [Java's O(1) space solution](https://www.programcreek.com/2014/06/leetcode-wildcard-matching-java/) and ~ 3.37 times faster (76.0ns/22.5ns) then standard `filepath.Match`.
## Example
```go
package mainimport (
"fmt""github.com/iamolegga/wildcard"
)func main() {
fmt.Println(wildcard.Match("value", "v?l*"))
fmt.Println(wildcard.IsPattern("v?l*"))
}
```## Performance
It was compared with `filepath.Match` function with several runs:
```sh
$ for i in {1..10}; do go test -run=NONE -bench=. ./... >> old.txt; done
$ # change implementation to `filepath.Match`
$ for i in {1..10}; do go test -run=NONE -bench=. ./... >> new.txt; done
$
$ benchstat old.txt new.txt
name old time/op new time/op delta
Match-4 22.5ns ± 2% 76.0ns ±19% +238.01% (p=0.000 n=10+10)
````old` - current implementation
`new` - utilize `filepath.Match`