summaryrefslogtreecommitdiffstats
path: root/updates.go
diff options
context:
space:
mode:
authorraylu <raylu@mixpanel.com>2011-08-06 19:55:57 -0700
committerraylu <raylu@mixpanel.com>2011-08-06 19:55:57 -0700
commit8f85f1a74cb9f8796638a00c5b78541d027b9845 (patch)
tree709f50a0d15106ed62e0d2aa7be64d95b7646fc8 /updates.go
parent082514b9ed2071f21e75a735830741d3f319cf50 (diff)
downloadaudioaxis-8f85f1a74cb9f8796638a00c5b78541d027b9845.tar.xz
other users' adds will show up; temp crappy internet fixes
Diffstat (limited to 'updates.go')
-rw-r--r--updates.go51
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
+}