patch the Taxid method

This commit is contained in:
2022-08-23 11:06:51 +02:00
parent 1e58c92086
commit 62968aaa26
2 changed files with 54 additions and 10 deletions

View File

@ -1,9 +1,14 @@
package obiseq
import (
log "github.com/sirupsen/logrus"
"sync"
)
// BioSequenceSlice represents a collection or a set of BioSequence.
//
// BioSequenceSlice is used to define BioSequenceBatch
// a memory pool of BioSequenceSlice is managed to limit allocations.
type BioSequenceSlice []*BioSequence
var _BioSequenceSlicePool = sync.Pool{
@ -13,32 +18,54 @@ var _BioSequenceSlicePool = sync.Pool{
},
}
// > This function returns a pointer to a new `BioSequenceSlice` object
func NewBioSequenceSlice() *BioSequenceSlice {
return _BioSequenceSlicePool.Get().(*BioSequenceSlice)
}
// `MakeBioSequenceSlice()` returns a pointer to a new `BioSequenceSlice` struct
func MakeBioSequenceSlice() BioSequenceSlice {
return *NewBioSequenceSlice()
}
func (s *BioSequenceSlice) Recycle() {
// if s == nil {
// log.Panicln("Trying too recycle a nil pointer")
// }
if s == nil {
log.Panicln("Trying too recycle a nil pointer")
}
// // Code added to potentially limit memory leaks
// for i := range *s {
// (*s)[i] = nil
// }
// Code added to potentially limit memory leaks
for i := range *s {
(*s)[i] = nil
}
// *s = (*s)[:0]
// _BioSequenceSlicePool.Put(s)
*s = (*s)[:0]
_BioSequenceSlicePool.Put(s)
}
// Making sure that the slice has enough capacity to hold the number of elements that are being added
// to it.
func (s *BioSequenceSlice) InsureCapacity(capacity int) *BioSequenceSlice {
var c int
if s != nil {
c = cap(*s)
} else {
c = 0
}
if c < capacity {
sl := make(BioSequenceSlice, 0,capacity)
s = &sl
}
return s
}
// Appending the sequence to the slice.
func (s *BioSequenceSlice) Push(sequence *BioSequence) {
*s = append(*s, sequence)
}
// Returning the last element of the slice and removing it from the slice.
func (s *BioSequenceSlice) Pop() *BioSequence {
_s := (*s)[len(*s)-1]
(*s)[len(*s)-1] = nil
@ -46,6 +73,7 @@ func (s *BioSequenceSlice) Pop() *BioSequence {
return _s
}
// Returning the first element of the slice and removing it from the slice.
func (s *BioSequenceSlice) Pop0() *BioSequence {
_s := (*s)[0]
(*s)[0] = nil
@ -53,6 +81,7 @@ func (s *BioSequenceSlice) Pop0() *BioSequence {
return _s
}
// Test that a slice of sequences contains at least a sequence.
func (s BioSequenceSlice) NotEmpty() bool {
return len(s) > 0
}