Files
obitools4/pkg/obiseq/pool.go

85 lines
1.5 KiB
Go
Raw Normal View History

2022-01-13 23:27:39 +01:00
package obiseq
import (
"sync"
2022-01-16 00:21:42 +01:00
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
2022-01-13 23:27:39 +01:00
)
2022-01-16 00:21:42 +01:00
var _BioSequenceByteSlicePool = sync.Pool{
2022-01-13 23:27:39 +01:00
New: func() interface{} {
2022-01-16 00:21:42 +01:00
bs := make([]byte, 0, 300)
2022-01-13 23:27:39 +01:00
return &bs
},
}
2022-01-16 00:21:42 +01:00
func RecycleSlice(s []byte) {
s0 := s[:0]
_BioSequenceByteSlicePool.Put(&s0)
}
func GetSlice(values ...byte) []byte {
s := *(_BioSequenceByteSlicePool.Get().(*[]byte))
if len(values) > 0 {
s = append(s, values...)
}
return s
}
var BioSequenceAnnotationPool = sync.Pool{
New: func() interface{} {
bs := make(Annotation, 100)
return &bs
},
2022-01-13 23:27:39 +01:00
}
2022-01-16 00:21:42 +01:00
func RecycleAnnotation(a Annotation) {
2022-02-01 17:31:28 +01:00
if a != nil {
for k := range a {
delete(a, k)
}
BioSequenceAnnotationPool.Put(&(a))
2022-01-16 00:21:42 +01:00
}
2022-01-13 23:27:39 +01:00
}
2022-01-16 00:21:42 +01:00
func GetAnnotation(values ...Annotation) Annotation {
a := *(BioSequenceAnnotationPool.Get().(*Annotation))
if len(values) > 0 {
goutils.CopyMap(a, values[0])
}
return a
2022-01-13 23:27:39 +01:00
}
2022-01-16 00:21:42 +01:00
// var __bioseq__pool__ = sync.Pool{
// New: func() interface{} {
// var bs _BioSequence
// bs.annotations = make(Annotation, 50)
// return &bs
// },
// }
// func MakeEmptyBioSequence() BioSequence {
// bs := BioSequence{__bioseq__pool__.Get().(*_BioSequence)}
// return bs
// }
// func MakeBioSequence(id string,
// sequence []byte,
// definition string) BioSequence {
// bs := MakeEmptyBioSequence()
// bs.SetId(id)
// bs.Write(sequence)
// bs.SetDefinition(definition)
// return bs
// }
// func (sequence *BioSequence) Recycle() {
// sequence.Reset()
// __bioseq__pool__.Put(sequence.sequence)
// sequence.sequence = nil
// }