diff options
| author | Luke Hoersten <[email protected]> | 2015-09-16 16:53:07 -0500 |
|---|---|---|
| committer | Luke Hoersten <[email protected]> | 2015-09-16 16:53:07 -0500 |
| commit | d8de169ba342dae7adf8b85316be2e9791bf7077 (patch) | |
| tree | 1dbd66ec2f5ceee49eb80cb10832a05d3a1d1802 /elisp/stack-mode/fifo.el | |
| parent | c38d91d3fc9581565634fee839df463bd3df977f (diff) | |
Trying stack-ide-mode.
Diffstat (limited to 'elisp/stack-mode/fifo.el')
| -rw-r--r-- | elisp/stack-mode/fifo.el | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/elisp/stack-mode/fifo.el b/elisp/stack-mode/fifo.el new file mode 100644 index 0000000..60efc64 --- /dev/null +++ b/elisp/stack-mode/fifo.el @@ -0,0 +1,55 @@ +;;; fifo.el --- FIFO queue. + +;; Copyright (c) 2015 Chris Done. + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Code: + +(require 'cl-lib) + +(defun fifo-make () + "Make a fifo queue." + (cons 0 nil)) + +(defun fifo-push (q a) + "Push a new item onto the queue." + (cl-assert (consp q) nil "Must be a queue.") + (setcar q (1+ (car q))) + (let ((next q) + (continue t)) + (while (not (null (cdr next))) + (setq next (cdr next))) + (setcdr next (cons a nil))) + q) + +(defun fifo-pop (q) + "Pop the next item on the queue." + (cl-assert (consp q) nil "Must be a queue.") + (cl-assert (consp (cdr q)) nil "No items to pop from queue.") + (setcar q (1- (car q))) + (let ((a (car (cdr q)))) + (setcdr q (cdr (cdr q))) + a)) + +(defun fifo-size (q) + "Get the size of the queue." + (cl-assert (consp q) nil "Must be a queue.") + (car q)) + +(defun fifo-null-p (q) + "Is the queue empty?" + (= (fifo-size q) 0)) + +(provide 'fifo) |
