diff options
Diffstat (limited to 'updates.go')
-rw-r--r-- | updates.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/updates.go b/updates.go new file mode 100644 index 0000000..c36bda8 --- /dev/null +++ b/updates.go @@ -0,0 +1,51 @@ +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 +} |