(defvar *canonicalize-cycle-on-creation* t)
+(deftype cycle-element ()
+ "An element of a cycle."
(defstruct (cycle (:constructor %make-cycle)
(canonicalized nil :type boolean)
- (spec #() :type (vector
+ (spec #() :type (vector )))
(defun print-cycle (cycle stream depth)
"Ensure that the elements ELEMENTS are those of a valid cycle."
(assert (or (null elements)
+ (typep x 'cycle-element))
- "Elements of a cycle must be positive integers.")
+ "Elements of a cycle must be positive integers.")
;;; XXX: This can be done much more efficiently.
(assert (= (length elements)
"Create a new cycle with the elements ELEMENTS."
- ;; XXX: SBCL will say that dead code elimination is going on
- ;; here. This is because COERCE expands into (IF (VECTORP X) X ...),
- ;; and SBCL can infer that X is a list.
- ;; -- Robert Smith 5/24/2014
- (let ((cycle (%make-cycle :spec (coerce elements 'vector))))
+ (let ((cycle (%make-cycle :spec (make-array (length elements)
+ :element-type 'cycle-element
+ :initial-contents elements))))
"Compute the orbit of the element N in the permutation PERM. Return a cycle representing the orbit of N."
(loop :with len := (orbit-length n perm)
- :with spec := (make-array len :initial-element n)
+ :with spec := (make-array len :element-type 'cycle-element
:for i :from 1 :below len
:for k := (perm-eval perm n) :then (perm-eval perm k)