schastsp/src/git.xdrm.io/schastsp/context/context.go

80 lines
1.8 KiB
Go
Raw Normal View History

package context
import (
"errors"
)
/* (1) Definitions
---------------------------------------------------------*/
/* (1) Default values */
const DefaultMin = 0x00f0
const DefaultMax = 0x0fff
const DefaultThr = 0x000a
/* (2) Struct attributes */
type T struct {
win float64; // 'timeid' window size
min uint16; // minimum scha depth
max uint16; // maximum scha depth
thr uint16; // scha depth threshold
}
/* (3) Constructor
*
* @win<float64> Window size for 'timeid' package
* @min<uint16> [OPT] Minimum scha depth
* @thr<uint16> [OPT] scha depth threshold before renewal
* @max<uint16> [OPT] Maximum scha depth
*
* @return outName<outType> outDesc
*
---------------------------------------------------------*/
func Create(win float64, optional... uint16) (*T, error) {
var instance = new(T);
/* (1) Window size error */
if win < 0 { return nil, errors.New("Window size must be positive and is negative") }
instance.win = win;
/* (2) Default values */
instance.min = DefaultMin
instance.thr = DefaultThr
instance.max = DefaultMax
/* (3) Optional 'min' */
if len(optional) > 0 {
if optional[0] < 0x0f { return nil, errors.New("Minimum depth must be greater than 0x0f (decimal 15) for consistency issues") }
instance.min = optional[0];
}
/* (4) Optional 'thr' */
if len(optional) > 1 {
instance.thr = optional[1];
}
/* (5) Optional 'max' */
if len(optional) > 2 {
if optional[2] <= instance.min+instance.thr {
return nil, errors.New("Minimum depth must be greater than 0x0f (decimal 15) for consistency issues")
}
instance.max = optional[2];
}
return instance, nil
}
/* (4) Getters */
func (c T) Window() float64 { return c.win }
func (c T) MinDepth() uint16 { return c.min }
func (c T) MaxDepth() uint16 { return c.max }
func (c T) DepthThreshold() uint16 { return c.thr }