You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.0 KiB

  1. package v2
  2. import (
  3. "github.com/Workiva/go-datastructures/queue"
  4. )
  5. type Event queue.Item
  6. type priority interface {
  7. Compare(other queue.Item) int
  8. Priority() int
  9. }
  10. type priorityLow struct{}
  11. type priorityNormal struct{}
  12. type priorityHigh struct{}
  13. func (p priorityLow) Priority() int {
  14. return 1
  15. }
  16. func (p priorityNormal) Priority() int {
  17. return 2
  18. }
  19. func (p priorityHigh) Priority() int {
  20. return 3
  21. }
  22. func (p priorityLow) Compare(other queue.Item) int {
  23. op := other.(priority)
  24. if p.Priority() > op.Priority() {
  25. return 1
  26. } else if p.Priority() == op.Priority() {
  27. return 0
  28. }
  29. return -1
  30. }
  31. func (p priorityNormal) Compare(other queue.Item) int {
  32. op := other.(priority)
  33. if p.Priority() > op.Priority() {
  34. return 1
  35. } else if p.Priority() == op.Priority() {
  36. return 0
  37. }
  38. return -1
  39. }
  40. func (p priorityHigh) Compare(other queue.Item) int {
  41. op := other.(priority)
  42. if p.Priority() > op.Priority() {
  43. return 1
  44. } else if p.Priority() == op.Priority() {
  45. return 0
  46. }
  47. return -1
  48. }
  49. type noOpEvent struct {
  50. priorityLow
  51. }
  52. var noOp = noOpEvent{}