diff options
author | Robert Griesemer <gri@golang.org> | 2009-11-24 13:43:18 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2009-11-24 13:43:18 -0800 |
commit | 974bc55c8721b53b0c2c07baad59b86c08d07104 (patch) | |
tree | 2ae85bbcdecedd2a311365a9586e24a4e7cab1ba /src/pkg/container/vector/stringvector.go | |
parent | 3dd6b9b693f7580651de03546db8fd1805aa0cdf (diff) | |
download | golang-974bc55c8721b53b0c2c07baad59b86c08d07104.tar.gz |
Change to container/vector interface:
- removed New(len int) in favor of new(Vector).Resize(len, cap)
- removed Init(len int) in favor of Resize(len, cap)
- runs all.bash
Fixes issue 294.
R=rsc, r, r1
http://codereview.appspot.com/157143
Diffstat (limited to 'src/pkg/container/vector/stringvector.go')
-rw-r--r-- | src/pkg/container/vector/stringvector.go | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/pkg/container/vector/stringvector.go b/src/pkg/container/vector/stringvector.go index 0178f6be2..93a4197a5 100644 --- a/src/pkg/container/vector/stringvector.go +++ b/src/pkg/container/vector/stringvector.go @@ -10,19 +10,21 @@ type StringVector struct { } -// Init initializes a new or resized vector. The initial length may be <= 0 to -// request a default length. If initial_len is shorter than the current -// length of the StringVector, trailing elements of the StringVector will be cleared. -func (p *StringVector) Init(len int) *StringVector { - p.Vector.Init(len); +// Resize changes the length and capacity of a vector. +// If the new length is shorter than the current length, Resize discards +// trailing elements. If the new length is longer than the current length, +// Resize adds "" elements. The capacity parameter is ignored unless the +// new length or capacity is longer that the current capacity. +func (p *StringVector) Resize(length, capacity int) *StringVector { + i := p.Len(); + p.Vector.Resize(length, capacity); + for a := p.a; i < len(a); i++ { + a[i] = "" + } return p; } -// NewStringVector returns an initialized new StringVector with length at least len. -func NewStringVector(len int) *StringVector { return new(StringVector).Init(len) } - - // At returns the i'th element of the vector. func (p *StringVector) At(i int) string { return p.Vector.At(i).(string) } |