Advertisement
cwchen

[Go] Queue generated by genny

Nov 21st, 2017
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.41 KB | None | 0 0
  1. // This file was automatically generated by genny.
  2. // Any changes will be lost if this file is regenerated.
  3. // see https://github.com/cheekybits/genny
  4.  
  5. package example
  6.  
  7. // StringQueue represents a queue of string types.
  8. type StringQueue struct {
  9.     items []string
  10. }
  11.  
  12. // NewStringQueue makes a new empty string queue.
  13. func NewStringQueue() *StringQueue {
  14.     return &StringQueue{items: make([]string, 0)}
  15. }
  16.  
  17. // Enq adds an item to the queue.
  18. func (q *StringQueue) Enq(obj string) *StringQueue {
  19.     q.items = append(q.items, obj)
  20.     return q
  21. }
  22.  
  23. // Deq removes and returns the next item in the queue.
  24. func (q *StringQueue) Deq() string {
  25.     obj := q.items[0]
  26.     q.items = q.items[1:]
  27.     return obj
  28. }
  29.  
  30. // Len gets the current number of string items in the queue.
  31. func (q *StringQueue) Len() int {
  32.     return len(q.items)
  33. }
  34.  
  35. // IntQueue represents a queue of int types.
  36. type IntQueue struct {
  37.     items []int
  38. }
  39.  
  40. // NewIntQueue makes a new empty int queue.
  41. func NewIntQueue() *IntQueue {
  42.     return &IntQueue{items: make([]int, 0)}
  43. }
  44.  
  45. // Enq adds an item to the queue.
  46. func (q *IntQueue) Enq(obj int) *IntQueue {
  47.     q.items = append(q.items, obj)
  48.     return q
  49. }
  50.  
  51. // Deq removes and returns the next item in the queue.
  52. func (q *IntQueue) Deq() int {
  53.     obj := q.items[0]
  54.     q.items = q.items[1:]
  55.     return obj
  56. }
  57.  
  58. // Len gets the current number of int items in the queue.
  59. func (q *IntQueue) Len() int {
  60.     return len(q.items)
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement