From 974bc55c8721b53b0c2c07baad59b86c08d07104 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 24 Nov 2009 13:43:18 -0800 Subject: 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 --- src/pkg/container/vector/stringvector.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/pkg/container/vector/stringvector.go') 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) } -- cgit v1.2.3