Add a first version of obitag the successor of ecotag

This commit is contained in:
2022-10-26 13:16:56 +02:00
parent e17d1fbca6
commit 8aa323dad5
17 changed files with 884 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
"os"
"reflect"
@@ -12,6 +13,15 @@ import (
"github.com/barkimedes/go-deepcopy"
)
// InterfaceToInt converts a interface{} to an integer value if possible.
// If not a "NotAnInteger" error is returned via the err
// return value and val is set to 0.
func InterfaceToString(i interface{}) (val string, err error) {
err = nil
val = fmt.Sprintf("%V", i)
return
}
// NotAnInteger defines a new type of Error : "NotAnInteger"
type NotAnInteger struct {
message string

29
pkg/goutils/minmax.go Normal file
View File

@@ -0,0 +1,29 @@
package goutils
func MinInt(x, y int) int {
if x < y {
return x
}
return y
}
func MaxInt(x, y int) int {
if x < y {
return y
}
return x
}
func MinUInt16(x, y uint16) uint16 {
if x < y {
return x
}
return y
}
func MaxUInt16(x, y uint16) uint16 {
if x < y {
return y
}
return x
}

33
pkg/goutils/ranks.go Normal file
View File

@@ -0,0 +1,33 @@
package goutils
import "sort"
// intRanker is a helper type for the rank function.
type intRanker struct {
x []int // Data to be ranked.
r []int // A list of indexes into f that reflects rank order after sorting.
}
// ranker satisfies the sort.Interface without mutating the reference slice, f.
func (r intRanker) Len() int { return len(r.x) }
func (r intRanker) Less(i, j int) bool { return r.x[r.r[i]] < r.x[r.r[j]] }
func (r intRanker) Swap(i, j int) { r.r[i], r.r[j] = r.r[j], r.r[i] }
func IntOrder(data []int) []int {
if len(data) == 0 {
return nil
}
rk := intRanker{
x: data,
r: make([]int, len(data)),
}
for i := 0; i < len(data); i++ {
rk.r[i] = i
}
sort.Sort(rk)
return rk.r
}