本文整理匯總了Golang中container/list.Element.Value方法的典型用法代碼示例。如果您正苦於以下問題:Golang Element.Value方法的具體用法?Golang Element.Value怎麽用?Golang Element.Value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類container/list.Element
的用法示例。
在下文中一共展示了Element.Value方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
}
示例2: updateInplace
func (c *LRUCache) updateInplace(e *list.Element, v interface{}) {
e.Value = v
c.moveToFront(e)
c.checkCapacity()
}
示例3: snakeServer
func snakeServer(wsch chan *websocket.Conn, comch chan *Command, msgch chan string) {
sockets := list.New()
wsm := make(map[*websocket.Conn]*Snake)
timer := time.NewTicker(200 * time.Millisecond)
food := [...]int{rand.Intn(size), rand.Intn(size)}
for {
select {
case com := <-comch:
log.Println("receive:", com.C)
switch com.C {
case "enter":
sockets.PushBack(com.W)
case "ready":
snake := &Snake{Pos: Up, Nodes: list.New(), Alive: true}
snake.Nodes.PushBack([...]int{size / 2, size / 2})
snake.Nodes.PushBack([...]int{size / 2, size/2 + 1})
wsm[com.W] = snake
case "quit":
log.Println("quit")
e := new(list.Element)
e.Value = com.W
sockets.Remove(e)
delete(wsm, com.W)
case "up": //1
snake := wsm[com.W]
if snake != nil && snake.Pos != Down {
snake.Pos = Up
}
case "down": //2
snake := wsm[com.W]
if snake != nil && snake.Pos != Up {
snake.Pos = Down
}
case "left": //3
snake := wsm[com.W]
if snake != nil && snake.Pos != Right {
snake.Pos = Left
}
case "right": //4
snake := wsm[com.W]
if snake != nil && snake.Pos != Left {
snake.Pos = Right
}
default:
//ignore
}
case <-timer.C:
v := make([][]int, size)
for i := 0; i < size; i++ {
v[i] = make([]int, size)
for j := 0; j < size; j++ {
v[i][j] = 0
}
}
for _, s := range wsm {
if s.Alive {
ft := (s.Nodes.Front().Value).([2]int)
npw := ft[0] + s.Pos[0]
nph := ft[1] + s.Pos[1]
if npw >= 0 && npw < 20 && nph >= 0 && nph < 20 {
if food[0] == npw && food[1] == nph {
food = [...]int{rand.Intn(size), rand.Intn(size)}
} else {
s.Nodes.Remove(s.Nodes.Back())
}
s.Nodes.PushFront([...]int{npw, nph})
}
for e := s.Nodes.Front(); e != nil; e = e.Next() {
ee := (e.Value).([2]int)
v[ee[0]][ee[1]] = 1
}
}
}
v[food[0]][food[1]] = 2
SendMessage(sockets, v)
case msg := <-msgch:
SendMessage(sockets, msg)
}
}
}