[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/queue d7ee623 01/14: Added queue.el package
From: |
Stefan Monnier |
Subject: |
[elpa] externals/queue d7ee623 01/14: Added queue.el package |
Date: |
Mon, 14 Dec 2020 12:02:44 -0500 (EST) |
branch: externals/queue
commit d7ee62367bff71cd6a5e26d68caf5b2ff0d88ad3
Author: Toby Cubitt <toby-predictive@dr-qubit.org>
Commit: tsc25 <toby-predictive@dr-qubit.org>
Added queue.el package
---
queue.el | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 130 insertions(+)
diff --git a/queue.el b/queue.el
new file mode 100644
index 0000000..bad9a93
--- /dev/null
+++ b/queue.el
@@ -0,0 +1,130 @@
+;;; queue.el --- queue data structure
+
+;; Copyright (C) 1991-1995, 2008 Free Software Foundation
+
+;; Author: Inge Wallin <inge@lysator.liu.se>
+;; rewritten by Toby Cubitt <toby-predictive@dr-qubit.org>
+;; Keywords: extensions, lisp
+
+;; This file is part of the GNU Emacs lisp library, Elib.
+
+;; GNU Elib 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 2, or (at your option)
+;; any later version.
+;;
+;; GNU Elib 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 GNU Elib; see the file COPYING. If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA
+;;
+
+;;; Commentary:
+
+
+
+;;; Code:
+
+(eval-when-compile (require 'cl))
+
+
+(defstruct (queue
+ ;; A tagged list is the pre-defstruct representation.
+ ;; (:type list)
+ :named
+ (:constructor nil)
+ (:constructor queue-create ())
+ (:copier nil))
+ head tail)
+
+
+(defun queue-enqueue (queue element)
+ "Append an ELEMENT to the end of the QUEUE."
+ (if (queue-head queue)
+ (setcdr (queue-tail queue)
+ (setf (queue-tail queue) (cons element nil)))
+ (setf (queue-head queue)
+ (setf (queue-tail queue) (cons element nil)))))
+
+(defalias 'queue-append 'queue-enqueue)
+
+
+(defun queue-prepend (queue element)
+ "Prepend an ELEMENT to the front of the QUEUE."
+ (if (queue-head queue)
+ (push element (queue-head queue))
+ (setf (queue-head queue)
+ (setf (queue-tail queue) (cons element nil)))))
+
+
+(defun queue-dequeue (queue)
+ "Remove the first element of QUEUE and return it.
+Returns nil if the queue is empty."
+ (unless (cdr (queue-head queue)) (setf (queue-tail queue) nil))
+ (pop (queue-head queue)))
+
+
+(defmacro queue-empty (queue)
+ "Return t if QUEUE is empty, otherwise return nil."
+ (null (queue-head queue)))
+
+
+(defmacro queue-first (queue)
+ "Return the first element of QUEUE or nil if it is empty,
+without removing it from the QUEUE."
+ (car (queue-head queue)))
+
+
+(defun queue-nth (queue n)
+ "Return the nth element of a queue, without removing it.
+If the length of the queue is less than N, return nil. The first
+element in the queue has index 0."
+ (nth n (queue-head queue)))
+
+
+(defun queue-last (queue)
+ "Return the last element of QUEUE, without removing it.
+Returns nil if the QUEUE is empty."
+ (car (queue-tail queue)))
+
+
+(defun queue-all (queue)
+ "Return a list of all elements of QUEUE or nil if it is empty.
+The oldest element in the queue is the first in the list."
+ (queue-head queue))
+
+
+(defun queue-copy (queue)
+ "Return a copy of QUEUE.
+The new queue contains the elements of QUEUE in the same
+order. The elements themselves are *not* copied."
+ (let ((q (queue-create))
+ (list (queue-head queue)))
+ (when (queue-head queue)
+ (setf (queue-head q) (cons (car (queue-head queue)) nil)
+ (queue-tail q) (queue-head q))
+ (while (setq list (cdr list))
+ (setf (queue-tail q)
+ (setcdr (queue-tail q) (cons (car list) nil)))))
+ q))
+
+
+(defun queue-length (queue)
+ "Return the number of elements in QUEUE."
+ (length (queue-head queue)))
+
+
+(defun queue-clear (queue)
+ "Remove all elements from QUEUE."
+ (setf (queue-head queue) nil
+ (queue-tail queue) nil))
+
+
+(provide 'queue)
+
+;;; queue.el ends here
- [elpa] externals/queue 02a4454 03/14: Updated copywrite notice, (continued)
- [elpa] externals/queue 02a4454 03/14: Updated copywrite notice, Stefan Monnier, 2020/12/14
- [elpa] externals/queue 6d9b0c4 02/14: Bumped copyright year, Stefan Monnier, 2020/12/14
- [elpa] externals/queue 84b3d01 04/14: Re-filled to 72 chars/line, for mailing to gnu-emacs-sources list, Stefan Monnier, 2020/12/14
- [elpa] externals/queue b47d38f 05/14: Updated Package-Version, Package-Requires, and Keywords package headers., Stefan Monnier, 2020/12/14
- [elpa] externals/queue da5d38e 08/14: Trivial whitespace tidying., Stefan Monnier, 2020/12/14
- [elpa] externals/queue 82aa3ef 09/14: More minor whitespace and commentary changes., Stefan Monnier, 2020/12/14
- [elpa] externals/queue 2e53a45 10/14: Remove ChangeLogs from library headers., Stefan Monnier, 2020/12/14
- [elpa] externals/queue bbc4df9 12/14: Fix buggy queue-empty and queue-first definitions., Stefan Monnier, 2020/12/14
- [elpa] externals/queue f83d2b8 11/14: Enable lexical binding, and fix issues it picks up., Stefan Monnier, 2020/12/14
- [elpa] externals/queue c9ec2e3 14/14: Bump version numbers since we've added iterator generators., Stefan Monnier, 2020/12/14
- [elpa] externals/queue d7ee623 01/14: Added queue.el package,
Stefan Monnier <=
- [elpa] externals/queue 4427998 06/14: Added autoload cookies., Stefan Monnier, 2020/12/14
- [elpa] externals/queue 0b03d23 07/14: Updated copyright attribution and license (GPL2 -> GPL3)., Stefan Monnier, 2020/12/14
- [elpa] externals/queue 1c230d7 13/14: Implement iterator generators on collection data structures., Stefan Monnier, 2020/12/14