Skip to content

Commit

Permalink
Update with new function name
Browse files Browse the repository at this point in the history
  • Loading branch information
Symbolics committed Jul 16, 2023
1 parent a26cb0e commit 82f84b3
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/text/stem-and-leaf.lisp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
;;; -*- Mode: Lisp; Package: PLOT/TEXT; Syntax: ANSI-Common-Lisp; -*-
;;; Copyright (c) 2021-2022 by Symbolics Pte. Ltd. All rights reserved.
;;; Copyright (c) 2021-2023 by Symbolics Pte. Ltd. All rights reserved.
;;; SPDX-License-identifier: MS-PL

(in-package #:plot/text)

(defun leaf-strings (all-stems all-leaves sort-order)
"Returns a hashtable where the key represents the stem, and the value
represents the leaves as a string."
(let ((max-stem (sequence-maximum all-stems))
(let ((max-stem (seq-max all-stems))
(strings (make-hash-table :size 1000)))
(loop for s from (sequence-minimum all-stems) to max-stem
(loop for s from (seq-min all-stems) to max-stem
for stems = (which all-stems :predicate #'(lambda (x) (= x s)))
for leaves = (if (= (length stems) 0)
nil
Expand All @@ -28,9 +30,9 @@
(check-type x vector)
(let* ((all-stems (efloor (e/ x (if split-stems (/ stem-size 2) stem-size))))
(all-leaves (emod x stem-size))
(stem-fmt (format nil "~~~AD |" (length (format nil "~A" (sequence-maximum all-stems)))))
(stem-fmt (format nil "~~~AD |" (length (format nil "~A" (seq-max all-stems)))))
(leaf-strings-vector (leaf-strings all-stems all-leaves #'<)))
(loop for s from (sequence-minimum all-stems) to (sequence-maximum all-stems)
(loop for s from (seq-min all-stems) to (seq-max all-stems)
do (progn (format t stem-fmt (if split-stems (floor (/ s 2)) s))
(format t "~A~%" (gethash s leaf-strings-vector))))))

Expand All @@ -52,11 +54,11 @@
(combined-stems (concatenate 'vector left-stems right-stems))
(left-leaves (emod x stem-size))
(right-leaves (emod y stem-size))
(stem-fmt (format nil " | ~~~AD |" (length (format nil "~A" (sequence-maximum combined-stems)))))
(stem-fmt (format nil " | ~~~AD |" (length (format nil "~A" (seq-max combined-stems)))))
(left-strings (leaf-strings left-stems left-leaves #'>))
(right-strings (leaf-strings right-stems right-leaves #'<))
(left-min-col (sequence-maximum (loop for leaf being each hash-value of left-strings collect (length leaf)))))
(loop for s from (sequence-minimum combined-stems) to (sequence-maximum combined-stems)
(left-min-col (seq-max (loop for leaf being each hash-value of left-strings collect (length leaf)))))
(loop for s from (seq-min combined-stems) to (seq-max combined-stems)
do (progn (format t "~v@A" left-min-col (gethash s left-strings ""))
(format t stem-fmt s)
(format t "~A~%" (gethash s right-strings ""))))))

0 comments on commit 82f84b3

Please sign in to comment.