mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Xprize update
Former-commit-id: d38919a897961e4d40da3b844057c3fb94fdb6d7
This commit is contained in:
42
pkg/obiutils/counter.go
Normal file
42
pkg/obiutils/counter.go
Normal file
@ -0,0 +1,42 @@
|
||||
package obiutils
|
||||
|
||||
import "sync"
|
||||
|
||||
type Counter struct {
|
||||
Inc func() int
|
||||
Dec func() int
|
||||
Value func() int
|
||||
}
|
||||
|
||||
func NewCounter(initial ...int) *Counter {
|
||||
value := 0
|
||||
lock := sync.Mutex{}
|
||||
|
||||
if len(initial) > 0 {
|
||||
value = initial[0]
|
||||
}
|
||||
|
||||
c := Counter{
|
||||
Inc: func() int {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
value++
|
||||
return value
|
||||
},
|
||||
|
||||
Dec: func() int {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
value--
|
||||
return value
|
||||
},
|
||||
|
||||
Value: func() int {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
return value
|
||||
},
|
||||
}
|
||||
|
||||
return &c
|
||||
}
|
12
pkg/obiutils/strings.go
Normal file
12
pkg/obiutils/strings.go
Normal file
@ -0,0 +1,12 @@
|
||||
package obiutils
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func UnsafeStringFreomBytes(data []byte) string {
|
||||
if len(data) > 0 {
|
||||
s := unsafe.String(unsafe.SliceData(data), len(data))
|
||||
return s
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
Reference in New Issue
Block a user