mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00

modified: cmd/obitools/obitag/main.go modified: cmd/obitools/obitag2/main.go modified: go.mod modified: go.sum modified: pkg/obiformats/ncbitaxdump/read.go modified: pkg/obioptions/version.go modified: pkg/obiseq/attributes.go modified: pkg/obiseq/taxonomy_lca.go modified: pkg/obiseq/taxonomy_methods.go modified: pkg/obiseq/taxonomy_predicate.go modified: pkg/obitax/inner.go modified: pkg/obitax/lca.go new file: pkg/obitax/taxid.go modified: pkg/obitax/taxon.go modified: pkg/obitax/taxonomy.go modified: pkg/obitax/taxonslice.go modified: pkg/obitools/obicleandb/obicleandb.go modified: pkg/obitools/obigrep/options.go modified: pkg/obitools/obilandmark/obilandmark.go modified: pkg/obitools/obilandmark/options.go modified: pkg/obitools/obirefidx/famlilyindexing.go modified: pkg/obitools/obirefidx/geomindexing.go modified: pkg/obitools/obirefidx/obirefidx.go modified: pkg/obitools/obirefidx/options.go modified: pkg/obitools/obitag/obigeomtag.go modified: pkg/obitools/obitag/obitag.go modified: pkg/obitools/obitag/options.go modified: pkg/obiutils/strings.go
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package obitax
|
|
|
|
import (
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
// InnerString is a struct that holds a map of strings and a read-write lock for concurrent access.
|
|
// The index map is used to store key-value pairs of strings.
|
|
type InnerString struct {
|
|
index map[string]*string // Map to store string values
|
|
lock sync.RWMutex // Read-write lock for concurrent access
|
|
}
|
|
|
|
// NewInnerString creates a new instance of InnerString.
|
|
// It initializes the index map and prepares the lock for use.
|
|
func NewInnerString() *InnerString {
|
|
return &InnerString{
|
|
index: make(map[string]*string),
|
|
}
|
|
}
|
|
|
|
// Innerize stores the given value in the index map if it is not already present.
|
|
// It returns the pointer to the string associated with the key, which is either the newly stored value
|
|
// or the existing value if it was already present in the map.
|
|
//
|
|
// Parameters:
|
|
// - value: The string value to be stored in the index map.
|
|
//
|
|
// Returns:
|
|
// - A pointer to the string value associated with the key.
|
|
func (i *InnerString) Innerize(value string) *string {
|
|
i.lock.Lock()
|
|
defer i.lock.Unlock()
|
|
s, ok := i.index[value]
|
|
if !ok {
|
|
value = strings.Clone(value)
|
|
s = &value
|
|
i.index[value] = s
|
|
}
|
|
return s
|
|
}
|
|
|
|
// Slice returns a slice of strings containing all the values stored in the index map.
|
|
func (i *InnerString) Slice() []string {
|
|
rep := make([]string, len(i.index))
|
|
j := 0
|
|
for _, v := range i.index {
|
|
rep[j] = *v
|
|
j++
|
|
}
|
|
return rep
|
|
}
|