2018-04-20 22:03:18 +00:00
|
|
|
package context
|
|
|
|
|
2018-04-21 14:08:08 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2018-04-21 14:39:24 +00:00
|
|
|
/* (1) Definitions
|
2018-04-20 22:03:18 +00:00
|
|
|
---------------------------------------------------------*/
|
2018-04-21 14:39:24 +00:00
|
|
|
/* (1) Default values */
|
|
|
|
const DefaultMin = 0x00f0
|
|
|
|
const DefaultMax = 0x0fff
|
|
|
|
const DefaultThr = 0x000a
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Struct attributes */
|
2018-04-21 16:33:20 +00:00
|
|
|
type T struct {
|
2018-04-21 14:39:24 +00:00
|
|
|
win float64; // 'timeid' window size
|
|
|
|
min uint16; // minimum scha depth
|
|
|
|
max uint16; // maximum scha depth
|
|
|
|
thr uint16; // scha depth threshold
|
2018-04-20 22:03:18 +00:00
|
|
|
}
|
|
|
|
|
2018-04-21 14:39:24 +00:00
|
|
|
/* (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
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
|
2018-04-21 16:33:20 +00:00
|
|
|
func Create(win float64, optional... uint16) (*T, error) {
|
2018-04-21 14:39:24 +00:00
|
|
|
|
2018-04-21 16:33:20 +00:00
|
|
|
var instance = new(T);
|
2018-04-20 22:03:18 +00:00
|
|
|
|
2018-04-21 14:08:08 +00:00
|
|
|
/* (1) Window size error */
|
|
|
|
if win < 0 { return nil, errors.New("Window size must be positive and is negative") }
|
|
|
|
instance.win = win;
|
|
|
|
|
2018-04-21 14:39:24 +00:00
|
|
|
/* (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];
|
2018-04-21 14:08:08 +00:00
|
|
|
|
2018-04-21 14:39:24 +00:00
|
|
|
}
|
2018-04-20 22:03:18 +00:00
|
|
|
|
2018-04-21 14:08:08 +00:00
|
|
|
return instance, nil
|
2018-04-20 22:03:18 +00:00
|
|
|
}
|
|
|
|
|
2018-04-21 14:39:24 +00:00
|
|
|
/* (4) Getters */
|
2018-04-21 16:33:20 +00:00
|
|
|
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 }
|