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 23:05:51 +00:00
|
|
|
var inst = 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") }
|
2018-04-21 23:05:51 +00:00
|
|
|
inst.win = win;
|
2018-04-21 14:08:08 +00:00
|
|
|
|
2018-04-21 14:39:24 +00:00
|
|
|
/* (2) Default values */
|
2018-04-21 23:05:51 +00:00
|
|
|
inst.min = DefaultMin
|
|
|
|
inst.thr = DefaultThr
|
|
|
|
inst.max = DefaultMax
|
2018-04-21 14:39:24 +00:00
|
|
|
|
|
|
|
/* (3) Optional 'min' */
|
|
|
|
if len(optional) > 0 {
|
|
|
|
|
2018-04-21 23:05:51 +00:00
|
|
|
if optional[0] < 0x0f {
|
|
|
|
return nil, errors.New("Minimum depth must be greater than 0x0f (decimal 15) for consistency issues")
|
|
|
|
}
|
|
|
|
inst.min = optional[0];
|
2018-04-21 14:39:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (4) Optional 'thr' */
|
|
|
|
if len(optional) > 1 {
|
2018-04-21 23:05:51 +00:00
|
|
|
inst.thr = optional[1];
|
2018-04-21 14:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* (5) Optional 'max' */
|
|
|
|
if len(optional) > 2 {
|
|
|
|
|
2018-04-21 23:05:51 +00:00
|
|
|
if optional[2] <= inst.min+inst.thr {
|
2018-04-21 14:39:24 +00:00
|
|
|
return nil, errors.New("Minimum depth must be greater than 0x0f (decimal 15) for consistency issues")
|
|
|
|
}
|
2018-04-21 23:05:51 +00:00
|
|
|
inst.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 23:05:51 +00:00
|
|
|
return inst, 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 }
|