mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Add a second way to merge several batch iterators using the pool method.
This commit is contained in:
@ -34,7 +34,6 @@ type IBioSequenceBatch struct {
|
|||||||
//
|
//
|
||||||
// NilIBioSequenceBatch is the nil instance for the
|
// NilIBioSequenceBatch is the nil instance for the
|
||||||
// IBioSequenceBatch type.
|
// IBioSequenceBatch type.
|
||||||
//
|
|
||||||
var NilIBioSequenceBatch = IBioSequenceBatch{pointer: nil}
|
var NilIBioSequenceBatch = IBioSequenceBatch{pointer: nil}
|
||||||
|
|
||||||
func MakeIBioSequenceBatch(sizes ...int) IBioSequenceBatch {
|
func MakeIBioSequenceBatch(sizes ...int) IBioSequenceBatch {
|
||||||
@ -329,8 +328,7 @@ func (iterator IBioSequenceBatch) Concat(iterators ...IBioSequenceBatch) IBioSeq
|
|||||||
newIter.Add(1)
|
newIter.Add(1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
newIter.Wait()
|
newIter.WaitAndClose()
|
||||||
close(newIter.Channel())
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -363,6 +361,52 @@ func (iterator IBioSequenceBatch) Concat(iterators ...IBioSequenceBatch) IBioSeq
|
|||||||
return newIter
|
return newIter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (iterator IBioSequenceBatch) Pool(iterators ...IBioSequenceBatch) IBioSequenceBatch {
|
||||||
|
|
||||||
|
niterator := len(iterators) + 1
|
||||||
|
|
||||||
|
if niterator == 1 {
|
||||||
|
return iterator
|
||||||
|
}
|
||||||
|
|
||||||
|
counterMutex := sync.Mutex{}
|
||||||
|
counter := 0
|
||||||
|
|
||||||
|
nextCounter := func() int {
|
||||||
|
counterMutex.Lock()
|
||||||
|
defer counterMutex.Unlock()
|
||||||
|
|
||||||
|
counter++
|
||||||
|
|
||||||
|
return counter
|
||||||
|
}
|
||||||
|
|
||||||
|
buffsize := iterator.BufferSize()
|
||||||
|
newIter := MakeIBioSequenceBatch(buffsize)
|
||||||
|
|
||||||
|
newIter.Add(niterator)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
newIter.WaitAndClose()
|
||||||
|
}()
|
||||||
|
|
||||||
|
ff := func(iterator IBioSequenceBatch) {
|
||||||
|
|
||||||
|
for iterator.Next() {
|
||||||
|
s := iterator.Get()
|
||||||
|
newIter.Push(s.Reorder(nextCounter()))
|
||||||
|
}
|
||||||
|
newIter.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
go ff(iterator)
|
||||||
|
for _, i := range iterators {
|
||||||
|
go ff(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
return newIter
|
||||||
|
}
|
||||||
|
|
||||||
// Redistributes sequences from a IBioSequenceBatch into a new
|
// Redistributes sequences from a IBioSequenceBatch into a new
|
||||||
// IBioSequenceBatch with every batches having the same size
|
// IBioSequenceBatch with every batches having the same size
|
||||||
// indicated in parameter. Rebatching implies to sort the
|
// indicated in parameter. Rebatching implies to sort the
|
||||||
|
Reference in New Issue
Block a user