本文整理汇总了Golang中container/vector.Vector.Init方法的典型用法代码示例。如果您正苦于以下问题:Golang Vector.Init方法的具体用法?Golang Vector.Init怎么用?Golang Vector.Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类container/vector.Vector
的用法示例。
在下文中一共展示了Vector.Init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseExpression
func (p *parser) parseExpression() expr {
var list vector.Vector
list.Init(0)
for {
x := p.parseSequence()
if x != nil {
list.Push(x)
}
if p.tok != token.OR {
break
}
p.next()
}
// no need for an alternatives if list.Len() < 2
switch list.Len() {
case 0:
return nil
case 1:
return list.At(0).(expr)
}
// convert list into a alternatives
alt := make(alternatives, list.Len())
for i := 0; i < list.Len(); i++ {
alt[i] = list.At(i).(expr)
}
return alt
}
示例2: parseLiteral
func (p *parser) parseLiteral() literal {
s := strings.Bytes(p.parseString())
// A string literal may contain %-format specifiers. To simplify
// and speed up printing of the literal, split it into segments
// that start with "%" possibly followed by a last segment that
// starts with some other character.
var list vector.Vector
list.Init(0)
i0 := 0
for i := 0; i < len(s); i++ {
if s[i] == '%' && i+1 < len(s) {
// the next segment starts with a % format
if i0 < i {
// the current segment is not empty, split it off
list.Push(s[i0:i])
i0 = i
}
i++ // skip %; let loop skip over char after %
}
}
// the final segment may start with any character
// (it is empty iff the string is empty)
list.Push(s[i0:len(s)])
// convert list into a literal
lit := make(literal, list.Len())
for i := 0; i < list.Len(); i++ {
lit[i] = list.At(i).([]byte)
}
return lit
}
示例3: parseSequence
func (p *parser) parseSequence() expr {
var list vector.Vector
list.Init(0)
for x := p.parseOperand(); x != nil; x = p.parseOperand() {
list.Push(x)
}
// no need for a sequence if list.Len() < 2
switch list.Len() {
case 0:
return nil
case 1:
return list.At(0).(expr)
}
// convert list into a sequence
seq := make(sequence, list.Len())
for i := 0; i < list.Len(); i++ {
seq[i] = list.At(i).(expr)
}
return seq
}