-
Notifications
You must be signed in to change notification settings - Fork 6
/
gentemplate_vec_countersvec.go
90 lines (77 loc) · 2.01 KB
/
gentemplate_vec_countersvec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// autogenerated: do not edit!
// generated from gentemplate [gentemplate -d Package=vnet -id countersVec -d VecType=CountersVec -d Type=Counters github.com/platinasystems/elib/vec.tmpl]
// Copyright 2016 Platina Systems, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vnet
import (
"github.com/platinasystems/elib"
)
type CountersVec []Counters
func (p *CountersVec) Resize(n uint) {
old_cap := uint(cap(*p))
new_len := uint(len(*p)) + n
if new_len > old_cap {
new_cap := elib.NextResizeCap(new_len)
q := make([]Counters, new_len, new_cap)
copy(q, *p)
*p = q
}
*p = (*p)[:new_len]
}
func (p *CountersVec) validate(new_len uint, zero Counters) *Counters {
old_cap := uint(cap(*p))
old_len := uint(len(*p))
if new_len <= old_cap {
// Need to reslice to larger length?
if new_len > old_len {
*p = (*p)[:new_len]
for i := old_len; i < new_len; i++ {
(*p)[i] = zero
}
}
return &(*p)[new_len-1]
}
return p.validateSlowPath(zero, old_cap, new_len, old_len)
}
func (p *CountersVec) validateSlowPath(zero Counters, old_cap, new_len, old_len uint) *Counters {
if new_len > old_cap {
new_cap := elib.NextResizeCap(new_len)
q := make([]Counters, new_cap, new_cap)
copy(q, *p)
for i := old_len; i < new_cap; i++ {
q[i] = zero
}
*p = q[:new_len]
}
if new_len > old_len {
*p = (*p)[:new_len]
}
return &(*p)[new_len-1]
}
func (p *CountersVec) Validate(i uint) *Counters {
var zero Counters
return p.validate(i+1, zero)
}
func (p *CountersVec) ValidateInit(i uint, zero Counters) *Counters {
return p.validate(i+1, zero)
}
func (p *CountersVec) ValidateLen(l uint) (v *Counters) {
if l > 0 {
var zero Counters
v = p.validate(l, zero)
}
return
}
func (p *CountersVec) ValidateLenInit(l uint, zero Counters) (v *Counters) {
if l > 0 {
v = p.validate(l, zero)
}
return
}
func (p *CountersVec) ResetLen() {
if *p != nil {
*p = (*p)[:0]
}
}
func (p CountersVec) Len() uint { return uint(len(p)) }