github.com/niubaoshu/goutils@v0.0.0-20180828035119-e8e576f66c2b/week52.go (about) 1 package goutils 2 3 type Week52 struct { 4 store []float64 5 high uint32 6 low uint32 7 start uint32 8 mode uint32 9 length uint32 10 } 11 12 func NewWeek52(cap int) *Week52 { 13 length := minQuantity(uint32(cap)) 14 return &Week52{ 15 store: make([]float64, length), 16 high: length - 1, 17 low: 0, 18 start: 0, 19 mode: length - 1, 20 length: length, 21 } 22 23 } 24 25 // round 到最近的2的倍数 26 func minQuantity(v uint32) uint32 { 27 v-- 28 v |= v >> 1 29 v |= v >> 2 30 v |= v >> 4 31 v |= v >> 8 32 v |= v >> 16 33 v++ 34 return v 35 }