本文整理匯總了Golang中container/vector.Vector.Data方法的典型用法代碼示例。如果您正苦於以下問題:Golang Vector.Data方法的具體用法?Golang Vector.Data怎麽用?Golang Vector.Data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類container/vector.Vector
的用法示例。
在下文中一共展示了Vector.Data方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Data
// Data returns a slice containing the elements of iter.
func Data(iter Iterable) []interface{} {
vec := new(vector.Vector)
for e := range iter.Iter() {
vec.Push(e)
}
return vec.Data()
}
示例2: TestDecodeFlushElem
func TestDecodeFlushElem(t *testing.T) {
testVec := new(vector.Vector).Resize(2, 2)
nb := newDecoder(testVec, 1)
nb.Float64(3.14159)
nb.Flush()
assertResult(t, testVec.Data(), []interface{}{nil, float64(3.14159)})
}
示例3: TestGroupBy
func TestGroupBy(t *testing.T) {
in := IntArray{1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5}
exp := [][]int{[]int{1}, []int{2, 2}, []int{3, 3, 3}, []int{4, 4, 4, 4}, []int{5, 5, 5, 5, 5}}
i := 0
for x := range GroupBy(in, intkey{}).Iter() {
gr := x.(Group)
if gr.Key.(int) != i+1 {
t.Fatal("group key wrong; expected", i+1, "but got", gr.Key.(int))
}
vals := Data(gr.Vals)
assertArraysAreEqual(t, vals, exp[i])
i++
}
if i != 5 {
t.Fatal("did not return expected number of groups")
}
// test 0 length Iterable
for _ = range GroupBy(IntArray([]int{}), &intkey{}).Iter() {
t.Fatal("iterator should be empty")
}
// test case with only uniques
var out vector.Vector
for x := range GroupBy(elevenToTwenty, intkey{}).Iter() {
out.Push(x.(Group).Key)
}
assertArraysAreEqual(t, out.Data(), elevenToTwenty)
}
示例4: Respond
func Respond(query types.DNSquery) (result types.DNSresponse) {
result.Responsecode = types.SERVFAIL
qname := strings.ToLower(query.Qname)
var asection, nssection vector.Vector
if query.Qclass == types.IN {
if as112Domain.MatchString(qname) {
result.Responsecode = types.NOERROR
if types.QMatches(query.Qtype, types.NS) {
nsRecords(query.Qname, &asection)
}
if types.QMatches(query.Qtype, types.SOA) {
asection.Push(soaRecord(query.Qname, as112soa))
}
}
matches := as112SubDomain.MatchStrings(qname)
if len(matches) > 0 {
result.Responsecode = types.NXDOMAIN
nssection.Push(soaRecord(matches[1], as112soa))
}
if qname == "hostname.as112.net" {
result.Responsecode = types.NOERROR
if types.QMatches(query.Qtype, types.TXT) {
for i := 0; i < len(hostnameAnswers); i++ {
asection.Push(types.RR{
Name: query.Qname,
TTL: defaultTTL,
Type: types.TXT,
Class: types.IN,
Data: types.ToTXT(hostnameAnswers[i]),
})
}
}
if types.QMatches(query.Qtype, types.NS) {
nsRecords(query.Qname, &asection)
}
if types.QMatches(query.Qtype, types.SOA) {
asection.Push(soaRecord(query.Qname, hostnamesoa))
}
}
}
data := asection.Data()
result.Asection = make([]types.RR, len(data))
for i := 0; i < len(data); i++ {
result.Asection[i] = data[i].(types.RR)
}
data = nssection.Data()
result.Nssection = make([]types.RR, len(data))
for i := 0; i < len(data); i++ {
result.Nssection[i] = data[i].(types.RR)
}
return
}
示例5: Match
func (self *quantifiedExpr) Match(m Position) (Position, interface{}) {
var item interface{}
cur := m
res := new(vector.Vector)
// guaranteed minimum
for i := 0; i < self.min; i++ {
cur, item = self.e.Match(cur)
if cur.Failed() {
return cur, nil
}
res.Push(item)
}
last := cur
// optional (up to a maximum)
for i := self.min; self.max == -1 || i < self.max; i++ {
cur, item = self.e.Match(last)
if cur.Failed() {
return last, res.Data()
}
res.Push(item)
last = cur
}
return cur, res.Data()
}