event_queue.go 331 B

1234567891011121314151617181920
  1. package store
  2. type eventQueue struct {
  3. Events []*Event
  4. Size int
  5. Front int
  6. Back int
  7. Capacity int
  8. }
  9. func (eq *eventQueue) insert(e *Event) {
  10. eq.Events[eq.Back] = e
  11. eq.Back = (eq.Back + 1) % eq.Capacity
  12. if eq.Size == eq.Capacity { //dequeue
  13. eq.Front = (eq.Front + 1) % eq.Capacity
  14. } else {
  15. eq.Size++
  16. }
  17. }