Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. (defstruct (fifo (:conc-name q) (:constructor make-fifo))
  2. head (length 0) tail)
  3.  
  4. (defun fifo-length (self)
  5. (qlength self))
  6.  
  7. (defun fifo-peek (self)
  8. "Returns first item from SELF"
  9. (first (qhead self)))
  10.  
  11. (defun fifo-pop (self)
  12. "Removes first item from SELF"
  13. (when-let (it (pop (qhead self)))
  14. (unless (qhead self)
  15. (setf (qtail self) nil))
  16. (decf (qlength self))
  17. it))
  18.  
  19. (defun fifo-push (self it)
  20. "Adds IT to end of SELF"
  21. (if (null (qhead self))
  22. (setf (qtail self) (setf (qhead self) (list it)))
  23. (setf (rest (qtail self)) (list it)
  24. (qtail self) (rest (qtail self))))
  25. (incf (qlength self))
  26. it)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement