當前位置: 首頁>>代碼示例>>Golang>>正文


Golang list.List類代碼示例

本文整理匯總了Golang中container/list.List的典型用法代碼示例。如果您正苦於以下問題:Golang List類的具體用法?Golang List怎麽用?Golang List使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了List類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: fetchMoves

func fetchMoves(curr_state string, moves *list.List, steps int) {
	if len(curr_state) <= steps-1 {
		return
	}

	val := []byte(curr_state)

	for i, _ := range val {
		if i+steps-1 < len(val) {
			success := true
			for k := 0; k < steps; k++ {
				if val[i+k] == '0' {
					success = false
				}
			}
			if success {
				for k := 0; k < steps; k++ {
					val[i+k] = '0'
				}

				moves.PushBack(string(val))

				for k := 0; k < steps; k++ {
					val[i+k] = '1'
				}
			}
		}
	}
}
開發者ID:rimpo,項目名稱:DontBeLast,代碼行數:29,代碼來源:DontBeLast.go

示例2: doStructMembers

func doStructMembers(fields []*ast.Field, pkg string, importer Importer, fn func(*ast.Object), q *list.List) {
	// Go Spec: For a value x of type T or *T where T is not an interface type, x.f
	// denotes the field or method at the shallowest depth in T where there
	// is such an f.
	// Thus we traverse shallower fields first, pushing anonymous fields
	// onto the queue for later.

	for _, f := range fields {
		if len(f.Names) > 0 {
			for _, fname := range f.Names {
				fn(fname.Obj)
			}
		} else {
			m := unnamedFieldName(f.Type)
			fn(m.Obj)
			// The unnamed field's Decl points to the
			// original type declaration.
			_, typeNode := splitDecl(m.Obj, nil)
			obj, typ := exprType(typeNode, false, pkg, importer)
			if typ.Kind == ast.Typ {
				q.PushBack(typ)
			} else {
				debugp("unnamed field kind %v (obj %v) not a type; %v", typ.Kind, obj, typ.Node)
			}
		}
	}
}
開發者ID:grncdr,項目名稱:godef,代碼行數:27,代碼來源:types.go

示例3: checkWorker

// Workers report back how many RPCs they have processed in the Shutdown reply.
// Check that they processed at least 1 RPC.
func checkWorker(t *testing.T, l *list.List) {
	for e := l.Front(); e != nil; e = e.Next() {
		if e.Value == 0 {
			t.Fatalf("Some worker didn't do any work\n")
		}
	}
}
開發者ID:micanzhang,項目名稱:6.824,代碼行數:9,代碼來源:test_test.go

示例4: main

func main() {
	var list list.List
	scanner := bufio.NewScanner(os.Stdin)
	p := getNumber(scanner)
	q := getNumber(scanner)
	for i := p; i <= q; i++ {
		square := i * i
		squareStr := strconv.Itoa(square)
		mid := len(squareStr) / 2
		power := float64(len(squareStr) - mid)
		rem := square % int(math.Pow(10, power))
		quo := square / int(math.Pow(10, power))
		sum := rem + quo
		if sum == i {
			list.PushBack(i)
		}
	}
	if list.Len() <= 0 {
		fmt.Println("INVALID RANGE")
	} else {
		for e := list.Front(); e != nil; e = e.Next() {
			fmt.Printf("%d ", e.Value)
		}
	}
}
開發者ID:unloadedroe,項目名稱:hackerrank,代碼行數:25,代碼來源:kaprekar.go

示例5: List2Array

func List2Array(l *list.List) []interface{} {
	output := make([]interface{}, 0)
	for i := l.Front(); i != nil; i = i.Next() {
		output = append(output, i.Value)
	}
	return output
}
開發者ID:payfriendz,項目名稱:go-freeling,代碼行數:7,代碼來源:utils.go

示例6: fillCSRTables

func (this *CSRKB) fillCSRTables(nv int, rels *list.List) {
	tmpA := List2IntPairsArray(rels)
	sort.Sort(IntPairsArray(tmpA))
	rels = IntPairsArray2List(tmpA)

	this.edges = make([]int, rels.Len())
	this.firstEdge = make([]int, nv)
	this.numEdges = make([]int, nv)
	this.outCoef = make([]float64, nv)

	n := 0
	r := 0

	p := rels.Front()
	for p != nil && n < nv {
		this.firstEdge[n] = r
		for p != nil && p.Value.(IntPair).first == n {
			this.edges[r] = p.Value.(IntPair).second
			r++
			p = p.Next()
		}
		this.numEdges[n] = r - this.firstEdge[n]
		this.outCoef[n] = 1 / float64(this.numEdges[n])
		n++
	}
}
開發者ID:payfriendz,項目名稱:go-freeling,代碼行數:26,代碼來源:csrkb.go

示例7: 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
}
開發者ID:pierrre,項目名稱:imageserver,代碼行數:7,代碼來源:graphicsmagick.go

示例8: GetMinTime

func GetMinTime(L *list.List) Time {
	if L.Len() == 0 {
		return NOTIME
	}
	front := L.Front()
	return front.Value.(Elem).GetTime()
}
開發者ID:jeffallen,項目名稱:go-warp,代碼行數:7,代碼來源:DT.go

示例9: filterPixel

func (s *Surface) filterPixel(p Coord2D, used, unUsed *list.List) {
	if s.IsUsed(p.X, p.Y) {
		used.PushBack(p)
	} else {
		unUsed.PushBack(p)
	}
}
開發者ID:nordsoyv,項目名稱:colorDrawer,代碼行數:7,代碼來源:workSurface.go

示例10: ParseTokens

func ParseTokens(t []string) *list.List {
	tokens := new(list.List)
	for i := range t {
		tokens.PushBack(t[i])
	}
	n := 0
	s, o := new(list.List), new(list.List)
	for e := tokens.Front(); e != nil; e = e.Next() {
		if e.Value.(string) == "(" {
			n++
			listAppend(s, new(list.List))
			listAppend(o, s)
			s = s.Back().Value.(*list.List)
		} else if e.Value.(string) == ")" {
			n--
			s = o.Back().Value.(*list.List)
			listPop(o)
		} else {
			listAppend(s, e.Value.(string))
		}
	}
	if n != 0 {
		Error("unbalanced parantheses")
	}
	return s
}
開發者ID:sfstpala,項目名稱:nil,代碼行數:26,代碼來源:test.go

示例11: removeUnacceptedChanges

func (p *Pipeline) removeUnacceptedChanges(l *list.List, allowAdd, allowDelete, allowUpdate bool) *list.List {
	if allowAdd && allowDelete && allowUpdate {
		return l
	}
	n := list.New()
	for iter := l.Front(); iter != nil; iter = iter.Next() {
		if iter.Value == nil {
			continue
		}
		ch, _ := iter.Value.(*dm.Change)
		if ch == nil {
			continue
		}
		if !allowAdd && ch.ChangeType == dm.CHANGE_TYPE_ADD {
			fmt.Printf("[PIPELINE]: Removing add change for path of %#v\n", ch.Path)
		} else if !allowDelete && ch.ChangeType == dm.CHANGE_TYPE_DELETE {
			fmt.Printf("[PIPELINE]: Removing delete change for path of %#v\n", ch.Path)
		} else if !allowUpdate && ch.ChangeType == dm.CHANGE_TYPE_UPDATE {
			if !allowAdd || ch.Path == nil || len(ch.Path) <= 1 {
				fmt.Printf("[PIPELINE]: Removing update for path of %#v and allowAdd %v\n", ch.Path, allowAdd)
			} else {
				fmt.Printf("[PIPELINE]: Changing update to add for path of %#v and allowAdd %v\n", ch.Path, allowAdd)
				ch.ChangeType = dm.CHANGE_TYPE_ADD
				ch.OriginalValue = nil
				n.PushBack(ch)
			}
		} else {
			n.PushBack(ch)
		}
	}
	return n
}
開發者ID:pombredanne,項目名稱:dsocial.go,代碼行數:32,代碼來源:pipeline.go

示例12: buildArgumentsFlop

func (server *Server) buildArgumentsFlop(arguments *list.List, params imageserver.Params) error {
	flop, _ := params.GetBool("flop")
	if flop {
		arguments.PushBack("-flop")
	}
	return nil
}
開發者ID:phamhongviet,項目名稱:imageserver,代碼行數:7,代碼來源:graphicsmagick.go

示例13: buildArgumentsMonochrome

func (server *Server) buildArgumentsMonochrome(arguments *list.List, params imageserver.Params) error {
	monochrome, _ := params.GetBool("monochrome")
	if monochrome {
		arguments.PushBack("-monochrome")
	}
	return nil
}
開發者ID:phamhongviet,項目名稱:imageserver,代碼行數:7,代碼來源:graphicsmagick.go

示例14: buildArgumentsGravity

func (server *Server) buildArgumentsGravity(arguments *list.List, params imageserver.Params) error {
	gravity, _ := params.GetString("gravity")
	var translatedGravity string
	if gravity != "" {
		switch {
		case gravity == "n":
			translatedGravity = "North"
		case gravity == "s":
			translatedGravity = "South"
		case gravity == "e":
			translatedGravity = "East"
		case gravity == "w":
			translatedGravity = "West"
		case gravity == "ne":
			translatedGravity = "NorthEast"
		case gravity == "se":
			translatedGravity = "SouthEast"
		case gravity == "nw":
			translatedGravity = "NorthWest"
		case gravity == "sw":
			translatedGravity = "SouthWest"
		}
		if translatedGravity == "" {
			return &imageserver.ParamError{Param: "gravity", Message: "gravity should n, s, e, w, ne, se, nw or sw"}
		}
	} else {
		// Default gravity is center.
		translatedGravity = "Center"
	}

	arguments.PushBack("-gravity")
	arguments.PushBack(fmt.Sprintf("%s", translatedGravity))
	return nil
}
開發者ID:phamhongviet,項目名稱:imageserver,代碼行數:34,代碼來源:graphicsmagick.go

示例15: DecomposeRecordLayer

func DecomposeRecordLayer(tlsPayload []byte) list.List {
	if len(tlsPayload) < 5 {
		return list.List{}
	}
	log.Println("Parsing one packet......")
	var tlsLayerlist list.List
	total := uint16(len(tlsPayload))
	var offset uint16 = 0

	for offset < total {
		var p TLSHandshakeDecoder.TLSRecordLayer
		p.ContentType = uint8(tlsPayload[0+offset])
		p.Version = uint16(tlsPayload[1+offset])<<8 | uint16(tlsPayload[2+offset])
		p.Length = uint16(tlsPayload[3+offset])<<8 | uint16(tlsPayload[4+offset])
		p.Fragment = make([]byte, p.Length)
		l := copy(p.Fragment, tlsPayload[5+offset:5+p.Length+offset])
		tlsLayerlist.PushBack(p)
		log.Println("Length: ", p.Length, "Type: ", p.ContentType)
		offset += 5 + p.Length
		if l < int(p.Length) {
			fmt.Errorf("Payload to short: copied %d, expected %d.", l, p.Length)
		}
	}
	return tlsLayerlist
}
開發者ID:rahulsom,項目名稱:tlsdr,代碼行數:25,代碼來源:ParserUtil.go


注:本文中的container/list.List類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。