iamolegga / wildcard

Go wildcard

Home Page:https://pkg.go.dev/github.com/iamolegga/wildcard

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wildcard

GoDoc Maintainability Test Coverage Go Report Card

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 and ~ 3.37 times faster (76.0ns/22.5ns) then standard filepath.Match.

Example

package main

import (
  "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:

$ 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

About

Go wildcard

https://pkg.go.dev/github.com/iamolegga/wildcard

License:MIT License


Languages

Language:Go 100.0%