| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package main
- import (
- "time"
- )
- const (
- addAction = 0
- removeAction = 1
- moveUpAction = 2
- moveDownAction = 3
- )
- type Update struct {
- Song *Song
- Action uint
- Timestamp int64
- Next *Update
- }
- var headUpdates map[int]*Update
- var tailUpdates map[int]*Update
- func init() {
- headUpdates = make(map[int]*Update)
- tailUpdates = make(map[int]*Update)
- }
- func addUpdate(pid int, action uint, song *Song) {
- update := new(Update)
- update.Song = song
- update.Action = action
- update.Timestamp = time.Nanoseconds()
- pup, ok := tailUpdates[pid]
- if ok {
- pup.Next = update
- } else {
- headUpdates[pid] = update
- }
- tailUpdates[pid] = update
- }
- func getUpdates(pid int, timestamp int64) *Update {
- pup, ok := headUpdates[pid]
- if !ok {
- return nil
- }
- for pup != nil {
- if pup.Timestamp > timestamp {
- return pup
- }
- pup = pup.Next
- }
- return nil
- }
|