forked from platinasystems/vnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gentemplate_pool_hwif.go
95 lines (81 loc) · 1.76 KB
/
gentemplate_pool_hwif.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
91
92
93
94
95
// autogenerated: do not edit!
// generated from gentemplate [gentemplate -d Package=vnet -id HwIf -d PoolType=hwIferPool -d Type=HwInterfacer -d Data=elts github.com/platinasystems/elib/pool.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 hwIferPool struct {
elib.Pool
elts []HwInterfacer
}
func (p *hwIferPool) GetIndex() (i uint) {
l := uint(len(p.elts))
i = p.Pool.GetIndex(l)
if i >= l {
p.Validate(i)
}
return i
}
func (p *hwIferPool) PutIndex(i uint) (ok bool) {
return p.Pool.PutIndex(i)
}
func (p *hwIferPool) IsFree(i uint) (v bool) {
v = i >= uint(len(p.elts))
if !v {
v = p.Pool.IsFree(i)
}
return
}
func (p *hwIferPool) Resize(n uint) {
c := uint(cap(p.elts))
l := uint(len(p.elts) + int(n))
if l > c {
c = elib.NextResizeCap(l)
q := make([]HwInterfacer, l, c)
copy(q, p.elts)
p.elts = q
}
p.elts = p.elts[:l]
}
func (p *hwIferPool) Validate(i uint) {
c := uint(cap(p.elts))
l := uint(i) + 1
if l > c {
c = elib.NextResizeCap(l)
q := make([]HwInterfacer, l, c)
copy(q, p.elts)
p.elts = q
}
if l > uint(len(p.elts)) {
p.elts = p.elts[:l]
}
}
func (p *hwIferPool) Elts() uint {
return uint(len(p.elts)) - p.FreeLen()
}
func (p *hwIferPool) Len() uint {
return uint(len(p.elts))
}
func (p *hwIferPool) Foreach(f func(x HwInterfacer)) {
for i := range p.elts {
if !p.Pool.IsFree(uint(i)) {
f(p.elts[i])
}
}
}
func (p *hwIferPool) ForeachIndex(f func(i uint)) {
for i := range p.elts {
if !p.Pool.IsFree(uint(i)) {
f(uint(i))
}
}
}
func (p *hwIferPool) Reset() {
p.Pool.Reset()
if len(p.elts) > 0 {
p.elts = p.elts[:0]
}
}