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


Golang list.Element類代碼示例

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


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

示例1: peekToken

// peekToken performs lookahead of the given count on the token stream.
func (l *peekableLexer) peekToken(count int) lexeme {
	if count < 1 {
		panic(fmt.Sprintf("Expected count > 1, received: %v", count))
	}

	// Ensure that the readTokens has at least the requested number of tokens.
	if l.readTokens.Len() < count {
		for {
			l.readTokens.PushBack(l.lex.nextToken())

			if l.readTokens.Len() == count {
				break
			}
		}
	}

	// Retrieve the count-th token from the list.
	var element *list.Element
	element = l.readTokens.Front()

	for i := 1; i < count; i++ {
		element = element.Next()
	}

	return element.Value.(lexeme)
}
開發者ID:Serulian,項目名稱:compiler,代碼行數:27,代碼來源:peekable_lex.go

示例2: listen

// listen is run in a goroutine. It reads new pull lists from its
// input queue until the queue is closed.
// listen takes ownership of the list that is passed to it.
//
// Note that the routine does not ever need to access the list
// itself once the current_item has been initialized, so we do
// not bother to keep a pointer to the list. Because it is a
// doubly linked list, holding on to the current item will keep
// it from garbage collection.
//
func (b *WorkQueue) listen() {
	var current_item *list.Element

	// When we're done, close the output channel to shut down any
	// workers.
	defer close(b.NextItem)

	for {
		// If the current list is empty, wait for a new list before
		// even checking if workers are ready.
		if current_item == nil {
			if p, ok := <-b.newlist; ok {
				current_item = p.Front()
			} else {
				// The channel was closed; shut down.
				return
			}
		}
		select {
		case p, ok := <-b.newlist:
			if ok {
				current_item = p.Front()
			} else {
				// The input channel is closed; time to shut down
				return
			}
		case b.NextItem <- current_item.Value:
			current_item = current_item.Next()
		}
	}
}
開發者ID:WangZhenfei,項目名稱:arvados,代碼行數:41,代碼來源:work_queue.go

示例3: SetAsync

// SetAsync 設置是否異步輸出,僅當之前為非異步並且設置為異步時,logList和mu有效
func (this *SimpleLogWriter) SetAsync(async bool, logList *list.List, mu *sync.Mutex) {
	if !this.async && async {
		if logList == nil || mu == nil {
			panic(ErrorLogWriterInvalidParam)
		}
		this.logList = logList
		this.logmu = mu
		go func() {
			var counter = atomic.AddInt32(&this.counter, 1)
			for this.async && counter == this.counter && !this.closed {
				if this.logList.Len() > 0 {
					var start *list.Element
					var length = 0
					this.logmu.Lock()
					if this.logList.Len() > 0 {
						start = this.logList.Front()
						length = this.logList.Len()
						this.logList.Init()
					}
					this.logmu.Unlock()
					for i := 0; i < length; i++ {
						var v, ok = start.Value.(string)
						if ok {
							this.writer.Write(v)
						}
						start = start.Next()
					}
				} else {
					time.Sleep(50 * time.Millisecond)
				}
			}
		}()
	}
	this.async = async
}
開發者ID:kdada,項目名稱:tinygo,代碼行數:36,代碼來源:writer.go

示例4: TimeEvict

// this time eviction is called by a scheduler for background, periodic evictions
func TimeEvict(lru *LRUCache, now time.Time, ttl time.Duration) {
	lru.mu.Lock()
	defer lru.mu.Unlock()

	if lru.list.Len() < 1 {
		return
	}

	var n *entry
	var el *list.Element
	hasEvictCallback := lru.EvictCallback != nil

	el = lru.list.Back()

	for {
		if el == nil {
			break
		}
		n = el.Value.(*entry)
		if now.Sub(n.time_accessed) > ttl {
			// the Difference is greater than max TTL so we need to evict this entry
			// first grab the next entry (as this is about to dissappear)
			el = el.Prev()
			lru.remove(n.key)
			if hasEvictCallback {
				lru.EvictCallback(n.key, n.value)
			}
		} else {
			// since they are stored in time order, as soon as we find
			// first item newer than ttl window, we are safe to bail
			break
		}
	}
	lru.last_ttl_check = time.Now()
}
開發者ID:zj8487,項目名稱:lruttl,代碼行數:36,代碼來源:lru_cache.go

示例5: AsyncWrite

// AsyncWrite 異步寫入日誌
func (this *ConsoleLogWriter) AsyncWrite(logList *list.List, mu *sync.Mutex) {
	this.logList = logList
	this.logmu = mu
	go func() {
		for !this.closed {
			if this.logList.Len() > 0 {
				var start *list.Element
				var length = 0
				this.logmu.Lock()
				start = this.logList.Front()
				length = this.logList.Len()
				this.logList.Init()
				this.logmu.Unlock()
				for i := 0; i < length; i++ {
					var v, ok = start.Value.(string)
					if ok {
						this.Write(v)
					}
					start = start.Next()
				}
			} else {
				//暫停15毫秒
				time.Sleep(15 * time.Millisecond)
				//runtime.Gosched()
			}
		}
	}()
}
開發者ID:kdada,項目名稱:tinylogger,代碼行數:29,代碼來源:console.go

示例6: cleaner

func (c *Cache) cleaner(limit int) {
	for _ = range c.clean {
		var item *list.Element
		for {
			c.lock.Lock() // X1+
			if len(c.m) < limit {
				c.lock.Unlock() // X1-
				break
			}

			if item == nil {
				item = c.lru.Front()
			}
			if p := item.Value.(*cachepage); !p.dirty {
				delete(c.m, p.pi)
				c.lru.Remove(item)
				c.Purge++
			}
			item = item.Next()
			c.lock.Unlock() // X1-
		}
		atomic.AddInt32(&c.cleaning, -1)
	}
	c.close <- true
}
開發者ID:matomesc,項目名稱:rkt,代碼行數:25,代碼來源:cache.go

示例7: listXmpl

func listXmpl() {
	fmt.Println("Teste Liste")
	myList := list.New()
	// einige Elemente einfügen
	myList.PushFront(element2{"a", 1})
	myList.PushFront(element2{"b", 2})
	myList.PushFront(element2{"c", 3})
	myList.PushFront(element2{"d", 4})
	myList.PushFront(element2{"e", 5})
	myList.PushFront(element2{"f", 6})

	for e := myList.Front(); e != nil; e = e.Next() {
		fmt.Println(e.Value)
	}

	// Ein Element umsortieren
	fmt.Println("Gehe zum zweiten Element")
	// erstmal den Anfang holen
	var e *list.Element = myList.Front()
	// einen Schritt weiter, zum e gehen
	e = e.Next()
	// Ausgeben zum Test
	fmt.Println("aktuell:", e.Value)
	fmt.Println("Verschiebe Element ans Listenende")
	// und e/5 ans Ende verbannen
	myList.MoveToBack(e)

	// nochmal mittels Iterator Elemente auslesen
	for e := myList.Front(); e != nil; e = e.Next() {
		fmt.Println(e.Value)
	}

}
開發者ID:SnertSnert,項目名稱:turbulentflyer,代碼行數:33,代碼來源:05_09_liste.go

示例8: Next

// Returns the item after e or nil it is the last item or nil.
// The item is a *list.Element from the 'container/list' package.
// Even though it is possible to call e.Next() directly, don't. This behavior
// may not be supported moving forward.
func (q Queue) Next(e *list.Element) *list.Element {
	if e == nil {
		return e
	}

	return e.Next()
}
開發者ID:jasocox,項目名稱:figo,代碼行數:11,代碼來源:figo.go

示例9: TestInsertBefore

func TestInsertBefore(t *testing.T) {
	var e *list.Element
	l := list.New()

	for i := 0; i < 5; i++ {
		if i == 3 {
			e = l.PushFront(i)
		} else {
			l.PushFront(i)
		}
	}

	l.InsertBefore(5, e)

	if l.Len() != 6 {
		t.Errorf("length = %d", l.Len())
	}

	e = l.Front()
	for i := 0; i < 6; i++ {
		t.Logf("e = %d", e.Value)

		e = e.Next()
	}
}
開發者ID:qt-luigi,項目名稱:golangcafe,代碼行數:25,代碼來源:listsample_test.go

示例10: Update

// C & U
func (node Node) Update(cmp *RemoteNode) {
	bucketID := node.ID.DistanceTo(cmp.ID).GetBucketID()
	bucket := node.RoutingTable[bucketID]

	var found bool = false
	var foundElement *list.Element

	for elem := bucket.Front(); elem != nil; elem = elem.Next() {
		e, ok := elem.Value.(*RemoteNode)
		if !ok {
			continue // if it's not a NodeID, wtf is it doing in the list?? Probably should error out
		}
		if e.ID.EqualsTo(cmp.ID) || e.ID.EqualsTo(node.ID) {
			found = true
			foundElement = elem
			break
		}
	}
	if !found {
		if bucket.Len() <= BUCKET_SIZE {
			bucket.PushFront(cmp)
		}
	} else {
		foundElement.Value = cmp // update the  foundElement value
		bucket.MoveToFront(foundElement)
	}
}
開發者ID:sameer2800,項目名稱:nanjingtaxi,代碼行數:28,代碼來源:node.go

示例11: incrElement

func (s *Summary) incrElement(el *list.Element) {
	counter := el.Value.(*Counter)
	counter.count++

	// This element already has the largest count so it won't get moved.
	if s.list.Front() == el {
		return
	}

	// Starting at the previous element, move this element behind the first
	// element we find which has a higher count.
	moved := false
	for currEl := el.Prev(); currEl != nil; currEl = currEl.Prev() {
		if currEl.Value.(*Counter).count > counter.count {
			s.list.MoveAfter(el, currEl)
			moved = true
			break
		}
	}

	// If we didn't find an element with a higher count then this element must
	// have the highest count.  Move it to the front.
	if !moved {
		s.list.MoveToFront(el)
	}
}
開發者ID:jmptrader,項目名稱:stream-1,代碼行數:26,代碼來源:stream.go

示例12: Manage_magnet

/* Create tree ball list with id random. If Ball is already taked, a first ball next is taked */
func (Data *Data) Manage_magnet(requete *list.Element, Tab_wd *owm.All_data) {
	rqt := requete.Value.(*protocol.Request)
	var tab [3]int64
	list_tmp := list.New()
	var ifball Posball
	user := Data.User.Value.(*users.User)
	var answer []byte
	var eball *list.Element

	if user.MagnetisValid() == true {
		if Data.Lst_ball.Id_max > 0 {
			for i := 0; i < 3; i++ {
				tab[i] = rand.Int63n(Data.Lst_ball.Id_max)
			}
			list_tmp_2 := Data.Lst_ball.Get_ballbyid_tomagnet(tab, Data.User)
			eball = list_tmp_2.Front()
		}
		for eball != nil {
			ball := eball.Value.(*list.Element).Value.(*ballon.Ball)
			ifball.id = ball.Id_ball
			ifball.title = ball.Title
			ifball.FlagPoss = 0
			ifball.lon = ball.Coord.Value.(ballon.Checkpoint).Coord.Lon
			ifball.lat = ball.Coord.Value.(ballon.Checkpoint).Coord.Lat
			ifball.wins = ball.Wind.Speed
			ifball.wind = ball.Wind.Degress
			list_tmp.PushBack(ifball)
			eball = eball.Next()
		}
		answer = Write_nearby(requete, list_tmp, MAGNET, user)
	} else {
		answer = Data.Manage_ack(rqt.Rtype, 0, 0)
	}
	Data.Lst_asw.PushBack(answer)
}
開發者ID:42MrPiou42,項目名稱:Wibo_OpenProject,代碼行數:36,代碼來源:answer.go

示例13: findRefKClosestTo

func findRefKClosestTo(kadems []*Kademlia, portrange int, searchID ID, KConst int) *list.List {
	var retList *list.List = list.New()
	for i := 0; i < len(kadems); i++ {
		var newNodeID ID
		var newNodeIDDist int
		newNodeID = CopyID(kadems[i].ContactInfo.NodeID)
		newNodeIDDist = newNodeID.Distance(searchID)
		var e *list.Element = retList.Front()
		for ; e != nil; e = e.Next() {
			var dist int
			dist = e.Value.(ID).Distance(searchID)
			//if responseNode is closer than node in ShortList, add it
			if newNodeIDDist < dist {
				retList.InsertBefore(newNodeID, e)
				//node inserted! getout
				break
			}
		}
		if e == nil {
			//node is farthest yet
			retList.PushBack(newNodeID)
		}
	}
	return retList
}
開發者ID:johhud1,項目名稱:KademliaMixNetwork,代碼行數:25,代碼來源:dbg.go

示例14: compareClosestContacts

func compareClosestContacts(fn []FoundNode, kadems []*Kademlia, portrange int, searchID ID) {
	var closestList *list.List = findRefKClosestTo(kadems, portrange, searchID, KConst)
	/*
		var pE *list.Element = closestList.Front()
		for ; pE != nil; pE = pE.Next(){
			log.Printf("Sorted? %s %d\n", pE.Value.(ID).AsString(), pE.Value.(ID).Distance(searchID))
		}*/
	var e *list.Element = closestList.Front()
	var overlap int = 0
	//log.Printf("searching for:%s\n", searchID.AsString())
	//log.Printf("reference List: \t\t\t\t\t iterativeFound List:\n")
	for i := 0; i < len(fn); i++ {
		var id ID = e.Value.(ID)
		//log.Printf("[%d]:%s %d\t%s %d", i, id.AsString(), id.Distance(searchID), fn[i].NodeID.AsString(), fn[i].NodeID.Distance(searchID))
		if id.Equals(fn[i].NodeID) {
			overlap++
		} else {
			for k := closestList.Front(); k != nil; k = k.Next() {
				if k.Value.(ID).Equals(fn[i].NodeID) {
					overlap++
				}
			}
		}
		e = e.Next()
	}
	if overlap < 5 {
		log.Printf("overlap of %d. Out of %d total nodes\n", overlap, portrange)
		panic(1)
	}
	//return retContacts
}
開發者ID:johhud1,項目名稱:KademliaMixNetwork,代碼行數:31,代碼來源:dbg.go

示例15: defSetup

func defSetup(e *list.Element, s *env.Scope) (*parse.Atom, error) {
	name := e.Next().Value.(*parse.Atom).Value.(string)
	val, err := eval(e.Next().Next().Value, s)
	if err != nil {
		return nil, err
	}
	return Def(name, val, s), nil
}
開發者ID:nanderson94,項目名稱:gosp,代碼行數:8,代碼來源:builtins.go


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