branch: externals/pam commit d2dd6a9796c313e353818ab8e9543c40bc03e36e Author: Onnie Lynn Winebarger <owine...@gmail.com> Commit: Onnie Lynn Winebarger <owine...@gmail.com>
Add functions to report free and live index lists --- table-allocation-manager.el | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/table-allocation-manager.el b/table-allocation-manager.el index 6c49ba6466..c608083432 100644 --- a/table-allocation-manager.el +++ b/table-allocation-manager.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2023 Onnie Lynn Winebarger -;; Author: Onnie Lynn Winebarger <owinebar@> +;; Author: Onnie Lynn Winebarger <owine...@gmail.com> ;; Keywords: lisp, tools ;; This program is free software; you can redistribute it and/or modify @@ -30,6 +30,8 @@ (eval-when-compile (require 'cl-lib)) +(require 'queue) + (cl-defstruct (tam--table (:constructor tam--table-create (size)) (:copier tam--copy-table)) "Table with explicitly managed allocation" @@ -93,8 +95,9 @@ "Get slot IDX of TBL" (tam--slot-contents (aref (tam--table-slots tbl) idx))) -(defun tam-store (tbl obj) - "Store OBJ in TBL. Returns index or nil if table is full." +(defun tam-allocate (tbl obj) + "Allocate slot in TBL with contents OBJ. +Returns index or nil if table is full." (let ((slot (tam--table-first-free tbl)) idx) (when (not (tam-table-full tbl)) @@ -143,6 +146,24 @@ Signals an error if IDX is not in use." (setf (tam--slot-contents slot) nil) obj)) +(defun tam-table-free-list (tbl) + "Return list of free indices in TBL" + (let ((s (tam--table-first-free tbl)) + (q (queue-create))) + (while s + (queue-enqueue q (tam--slot-index s)) + (setq s (tam--slot-next s))) + (queue-all q))) + +(defun tam-table-live-list (tbl) + "Return list of live indices in TBL" + (let ((s (tam--table-first-used tbl)) + (q (queue-create))) + (while s + (queue-enqueue q (tam--slot-index s)) + (setq s (tam--slot-next s))) + (queue-all q))) + (provide 'table-allocation-manager) ;;; table-allocation-manager.el ends here