package main import ( "time" ) const ( addAction = 0 removeAction = 1 ) type Update struct { Song *Song Action uint8 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 uint8, 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 }