Change the annotation locker to a pointer to mutex to avoid coying mutex

Former-commit-id: d179d8753b593183312bd11184e5d8ebb301138a
This commit is contained in:
2023-08-27 16:00:35 +02:00
parent 7b7128196a
commit 18d3eec24a
4 changed files with 101 additions and 100 deletions

View File

@ -59,7 +59,7 @@ type BioSequence struct {
feature []byte feature []byte
paired *BioSequence // A pointer to the paired sequence paired *BioSequence // A pointer to the paired sequence
annotations Annotation annotations Annotation
annot_lock sync.Mutex annot_lock *sync.Mutex
} }
// MakeEmptyBioSequence() creates a new BioSequence object with no data // MakeEmptyBioSequence() creates a new BioSequence object with no data
@ -81,7 +81,7 @@ func MakeEmptyBioSequence(preallocate int) BioSequence {
feature: nil, feature: nil,
paired: nil, paired: nil,
annotations: nil, annotations: nil,
annot_lock: sync.Mutex{}, annot_lock: &sync.Mutex{},
} }
} }
@ -99,6 +99,7 @@ func MakeBioSequence(id string,
bs.SetId(id) bs.SetId(id)
bs.SetSequence(sequence) bs.SetSequence(sequence)
bs.SetDefinition(definition) bs.SetDefinition(definition)
bs.AnnotationsUnlock()
return bs return bs
} }

View File

@ -262,7 +262,7 @@ func SequenceClassifier() *BioSequenceClassifier {
defer locke.RUnlock() defer locke.RUnlock()
if k >= maxcode { if k >= maxcode {
log.Fatalf("value %d not register") log.Fatalf("value %d not register", k)
} }
return decode[k] return decode[k]
} }

View File

@ -10,117 +10,117 @@ import (
"github.com/PaesslerAG/gval" "github.com/PaesslerAG/gval"
) )
func maxIntVector(values []int) float64 { // func maxIntVector(values []int) float64 {
m := values[0] // m := values[0]
for _, v := range values { // for _, v := range values {
if v > m { // if v > m {
m = v // m = v
} // }
} // }
return float64(m) // return float64(m)
} // }
func maxIntMap(values map[string]int) float64 { // func maxIntMap(values map[string]int) float64 {
var m int // var m int
first := true // first := true
for _, v := range values { // for _, v := range values {
if first { // if first {
first = false // first = false
m = v // m = v
} else { // } else {
if v > m { // if v > m {
m = v // m = v
} // }
} // }
} // }
return float64(m) // return float64(m)
} // }
func minIntVector(values []int) float64 { // func minIntVector(values []int) float64 {
m := values[0] // m := values[0]
for _, v := range values { // for _, v := range values {
if v < m { // if v < m {
m = v // m = v
} // }
} // }
return float64(m) // return float64(m)
} // }
func minIntMap(values map[string]int) float64 { // func minIntMap(values map[string]int) float64 {
var m int // var m int
first := true // first := true
for _, v := range values { // for _, v := range values {
if first { // if first {
first = false // first = false
m = v // m = v
} else { // } else {
if v < m { // if v < m {
m = v // m = v
} // }
} // }
} // }
return float64(m) // return float64(m)
} // }
func maxFloatVector(values []float64) float64 { // func maxFloatVector(values []float64) float64 {
m := values[0] // m := values[0]
for _, v := range values { // for _, v := range values {
if v > m { // if v > m {
m = v // m = v
} // }
} // }
return m // return m
} // }
func maxFloatMap(values map[string]float64) float64 { // func maxFloatMap(values map[string]float64) float64 {
var m float64 // var m float64
first := true // first := true
for _, v := range values { // for _, v := range values {
if first { // if first {
first = false // first = false
m = v // m = v
} else { // } else {
if v > m { // if v > m {
m = v // m = v
} // }
} // }
} // }
return m // return m
} // }
func minFloatVector(values []float64) float64 { // func minFloatVector(values []float64) float64 {
m := values[0] // m := values[0]
for _, v := range values { // for _, v := range values {
if v < m { // if v < m {
m = v // m = v
} // }
} // }
return m // return m
} // }
func minFloatMap(values map[string]float64) float64 { // func minFloatMap(values map[string]float64) float64 {
var m float64 // var m float64
first := true // first := true
for _, v := range values { // for _, v := range values {
if first { // if first {
first = false // first = false
m = v // m = v
} else { // } else {
if v < m { // if v < m {
m = v // m = v
} // }
} // }
} // }
return m // return m
} // }
// func maxNumeric(args ...interface{}) (interface{}, error) { // func maxNumeric(args ...interface{}) (interface{}, error) {
// var m float64 // var m float64

View File

@ -43,7 +43,7 @@ func (taxonomy *Taxonomy) TaxonomicDistribution(sequence *obiseq.BioSequence) ma
t, et := taxonomy.Taxon(taxid) t, et := taxonomy.Taxon(taxid)
if et != nil { if et != nil {
log.Panicf("Taxid %d not defined in taxonomy : %v", k, et) log.Panicf("Taxid %d not defined in taxonomy : %v", taxid, et)
} }
taxons[t] = v taxons[t] = v
} }