本文整理匯總了Golang中container/list.List.Len方法的典型用法代碼示例。如果您正苦於以下問題:Golang List.Len方法的具體用法?Golang List.Len怎麽用?Golang List.Len使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類container/list.List
的用法示例。
在下文中一共展示了List.Len方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: printList
func printList(l *list.List) {
elements := make([]interface{}, 0, l.Len())
Do(l, func(i interface{}) {
elements = append(elements, i)
})
log.Printf("%v", elements)
}
示例2: Commits
func Commits(ctx *middleware.Context, params martini.Params) {
userName := params["username"]
repoName := params["reponame"]
branchName := params["branchname"]
brs, err := models.GetBranches(userName, repoName)
if err != nil {
ctx.Handle(200, "repo.Commits", err)
return
} else if len(brs) == 0 {
ctx.Handle(404, "repo.Commits", nil)
return
}
var commits *list.List
if models.IsBranchExist(userName, repoName, branchName) {
commits, err = models.GetCommitsByBranch(userName, repoName, branchName)
} else {
commits, err = models.GetCommitsByCommitId(userName, repoName, branchName)
}
if err != nil {
ctx.Handle(404, "repo.Commits", err)
return
}
ctx.Data["Username"] = userName
ctx.Data["Reponame"] = repoName
ctx.Data["CommitCount"] = commits.Len()
ctx.Data["Commits"] = commits
ctx.Data["IsRepoToolbarCommits"] = true
ctx.HTML(200, "repo/commits")
}
示例3: drain_pending
func drain_pending(p *list.List) int {
var ret int
for p.Len() > 0 {
ret = wait_pending_front(p)
}
return ret
}
示例4: addResponseNodesToSL
//add Nodes we here about in the reply to the shortList, only if that node is not in the sentList
func addResponseNodesToSL(fnodes []FoundNode, shortList *list.List, sentMap map[ID]bool, targetID ID) {
for i := 0; i < len(fnodes); i++ {
foundNode := &fnodes[i]
_, inSentList := sentMap[foundNode.NodeID]
//if the foundNode is already in sentList, dont add it to shortList
if inSentList {
continue
}
for e := shortList.Front(); e != nil; e = e.Next() {
if e.Value.(*FoundNode).NodeID.Equals(foundNode.NodeID) {
break
}
dist := e.Value.(*FoundNode).NodeID.Distance(targetID)
foundNodeDist := foundNode.NodeID.Distance(targetID)
//if responseNode is closer than node in ShortList, add it
if foundNodeDist < dist {
shortList.InsertBefore(foundNode, e)
//keep the shortList length < Kconst
if shortList.Len() > KConst {
shortList.Remove(shortList.Back())
}
//node inserted! getout
break
}
}
}
}
示例5: Eval
func (frame *Frame) Eval(interp *Interp, script string) string {
var ok bool
var words *list.List
retval := ""
for len(script) != 0 {
ok, _, script = ParseComment(script)
if ok {
continue
}
_, words, script = ParseWords(script)
if len(script) == 0 || script[0] == '\n' || script[0] == ';' {
if len(script) != 0 {
script = script[1:]
}
if words.Len() == 0 {
continue
}
retval = interp.EvalWords(words)
}
}
return retval
}
示例6: BindArguments
func (frame *Frame) BindArguments(cmd Command, words *list.List) bool {
len := len(cmd.args)
for i, arg := range cmd.args {
name := arg.GetName()
value := arg.GetValue()
if i == (len-1) && name == "args" {
tmp := []string{}
for words.Len() != 0 {
word := words.Remove(words.Front()).(Word).String()
tmp = append(tmp, word)
}
value = StringToValueP(strings.Join(tmp, " "))
} else {
if words.Len() != 0 {
word := Value(words.Remove(words.Front()).(Word).String())
value = &word
}
}
frame.SetValue(name, value)
}
return true
}
示例7: StackSpec
func StackSpec(c Context) {
stack := new(list.List)
c.Specify("An empty stack", func() {
c.Specify("contains no elements", func() {
c.Expect(stack.Len()).Equals(0)
})
})
c.Specify("When elements are pushed onto a stack", func() {
stack.PushFront("pushed first")
stack.PushFront("pushed last")
c.Specify("then it contains some elements", func() {
c.Expect(stack.Len()).NotEquals(0)
})
c.Specify("the element pushed last is popped first", func() {
poppedFirst := stack.Remove(stack.Front())
c.Expect(poppedFirst).Equals("pushed last")
})
c.Specify("the element pushed first is popped last", func() {
stack.Remove(stack.Front())
poppedLast := stack.Remove(stack.Front())
c.Expect(poppedLast).Equals("pushed first")
})
})
}
示例8: makeDrawPriorityList
func makeDrawPriorityList(li *list.List) DrawPriorityList {
l := make([](*ConcreteElement), li.Len())
for o, i := li.Front(), 0; o != nil; o, i = o.Next(), i+1 {
l[i] = o.Value.(*ConcreteElement)
}
return DrawPriorityList(l)
}
示例9: makeAbstraction
func makeAbstraction(idents *list.List, body Expression) Expression {
for idents.Len() > 0 {
ident,_ := listPopFront(idents).(string);
body = Abstraction{ident, body};
}
return body;
}
示例10: RunPattern
// Run Pattern
func (network *Network) RunPattern(input *list.List) (output *list.List, err error) {
network.debug("resetting network\n")
// send reset
ch := make(chan string)
for _, v := range network.command {
v <- message{message: Reset, reply: ch}
// wait for response
_ = <-ch
}
// make sure pattern is same size as inputs
if input.Len() != network.inputs.Len() {
return nil, errors.New("invalid argument")
}
network.info("Run pattern to network: ")
PrintList(input)
i := uint(0)
for v := input.Front(); v != nil; v = v.Next() {
network.trace("\tsending %v to input %v\n", v, i)
network.inputs[i].c <- v.Value.(Data) * network.inputs[i].weight
i++
}
// get output
output = new(list.List)
for i := 0; i < network.outputs.Len(); i++ {
o := <-network.outputs[i].c
output.PushBack(o)
}
network.info(" \\- output is: ")
PrintList(output)
return output, err
}
示例11: bootstrapStores
// bootstrapStores bootstraps uninitialized stores once the cluster
// and node IDs have been established for this node. Store IDs are
// allocated via a sequence id generator stored at a system key per
// node.
func (n *Node) bootstrapStores(bootstraps *list.List, stopper *stop.Stopper) {
log.Infof("bootstrapping %d store(s)", bootstraps.Len())
if n.ClusterID == "" {
panic("ClusterID missing during store bootstrap of auxiliary store")
}
// Bootstrap all waiting stores by allocating a new store id for
// each and invoking store.Bootstrap() to persist.
inc := int64(bootstraps.Len())
firstID, err := allocateStoreIDs(n.Descriptor.NodeID, inc, n.ctx.DB)
if err != nil {
log.Fatal(err)
}
sIdent := roachpb.StoreIdent{
ClusterID: n.ClusterID,
NodeID: n.Descriptor.NodeID,
StoreID: firstID,
}
for e := bootstraps.Front(); e != nil; e = e.Next() {
s := e.Value.(*storage.Store)
if err := s.Bootstrap(sIdent, stopper); err != nil {
log.Fatal(err)
}
if err := s.Start(stopper); err != nil {
log.Fatal(err)
}
n.stores.AddStore(s)
sIdent.StoreID++
log.Infof("bootstrapped store %s", s)
// Done regularly in Node.startGossip, but this cuts down the time
// until this store is used for range allocations.
s.GossipStore()
}
}
示例12: addIfHigh
// Adds the given story id and bayes factor to the given list if it
// is higher than at least one of the ones already in the list
func addIfHigh(scores *list.List, length int, storyid int64, k float64) {
s := score{storyid: storyid, score: k}
// Add the score if the list is empty
last := scores.Back()
if last == nil {
scores.PushBack(s)
return
}
if scores.Len() < length {
insertScore(scores, length, s)
return
}
// Add the score to the list if it is high enough
lowest, ok := last.Value.(score)
if !ok {
log.Fatal("Could not extract score from sorted list")
}
if k < lowest.score {
return
}
// If this point is reached, we insert the score
insertScore(scores, length, s)
}
示例13: outOfOrder
func outOfOrder(l *list.List) {
iTotal := 25
if iTotal > l.Len() {
iTotal = l.Len()
}
ll := make([]*list.List, iTotal)
for i := 0; i < iTotal; i++ {
ll[i] = list.New()
}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for e := l.Front(); e != nil; e = e.Next() {
fpath, ok := e.Value.(string)
if !ok {
panic("The path is invalid string")
}
if rand.Int()%2 == 0 {
ll[r.Intn(iTotal)].PushFront(fpath)
} else {
ll[r.Intn(iTotal)].PushBack(fpath)
}
}
r0 := rand.New(rand.NewSource(time.Now().UnixNano()))
l.Init()
for i := 0; i < iTotal; i++ {
if r0.Intn(2) == 0 {
l.PushBackList(ll[i])
} else {
l.PushFrontList(ll[i])
}
ll[i].Init()
}
}
示例14: List2IntPairsArray
func List2IntPairsArray(ls *list.List) []IntPair {
out := make([]IntPair, ls.Len())
for i, l := 0, ls.Front(); i < ls.Len() && l != nil; i, l = i+1, l.Next() {
out[i] = l.Value.(IntPair)
}
return out
}
示例15: convertArgumentsToSlice
func convertArgumentsToSlice(arguments *list.List) []string {
argumentSlice := make([]string, 0, arguments.Len())
for e := arguments.Front(); e != nil; e = e.Next() {
argumentSlice = append(argumentSlice, e.Value.(string))
}
return argumentSlice
}