From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.devel Subject: Re: [GNU ELPA] New package: tam Date: Mon, 18 Sep 2023 17:02:40 +0000 Message-ID: <87led39zyn.fsf@posteo.net> References: <87a5tjyg83.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10895"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: Lynn Winebarger Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Sep 18 19:03:47 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qiHf0-0002XU-NK for ged-emacs-devel@m.gmane-mx.org; Mon, 18 Sep 2023 19:03:46 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiHeA-0000C4-Fk; Mon, 18 Sep 2023 13:02:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiHe5-0000Bp-DQ for emacs-devel@gnu.org; Mon, 18 Sep 2023 13:02:50 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiHdz-0007nv-Ks for emacs-devel@gnu.org; Mon, 18 Sep 2023 13:02:48 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 84AB1240027 for ; Mon, 18 Sep 2023 19:02:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1695056561; bh=d7c3pR67KSzbVIlrVZFo6W26HkqqWJ8GEUXq+3qvA/k=; h=From:To:Cc:Subject:Autocrypt:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=lqi0HwMEN4v4oC+1nxod/zNYk4I7g8SBdmulNr4hTsFn5s5AxmpSd/IPSgL9AHFU1 DMh4p8V+T+lYmmb56N3Y8ckcE0LVv6Tkx7fYthkPYMOKSC9qByi75cfxgBp3UtxbCf Pz0EHbOaNUsvpMpFNWE+BUK9fbkKNEUNn/JZX0beRbJMdm5rM1gf9H6wX9F6VCEwot ZKLTPcEnnhKaxYo3rsNZ7B5fx8cXdiJqyRYVYl1NBqosdJq52z7vCwEH5Zd5n7RraN ycYntN2MgfWVzZPtzSeTPa0dEgE4Pyzt3w6ziRgLBl0d+zRFAxD11Ep598dPBfMGZ1 1UjYOgbtx7ySQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RqB1Y1dJfz6txJ; Mon, 18 Sep 2023 19:02:41 +0200 (CEST) In-Reply-To: (Lynn Winebarger's message of "Mon, 18 Sep 2023 12:22:59 -0400") X-Hashcash: 1:20:230918:owinebar@gmail.com::QxlWJ/iwhpTT8oIO:2gIK X-Hashcash: 1:20:230918:emacs-devel@gnu.org::n0y8RhDVx24tBM3W:6Uwd Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:310710 Archived-At: Lynn Winebarger writes: > On Mon, Sep 18, 2023 at 5:37=E2=80=AFAM Philip Kaludercic wrote: >> >> Lynn Winebarger writes: >> >> > I'd like to submit "tam" (table allocation manager) for inclusion in >> > GNU ELPA. The source is available at >> > https://github.com/owinebar/emacs-table-allocation-manager >> >> Here are a few comments: > Thanks for taking a look. > >> >> diff --git a/table-allocation-manager.el b/table-allocation-manager.el >> index 59a5718..286c9a2 100644 >> --- a/table-allocation-manager.el >> +++ b/table-allocation-manager.el >> @@ -3,6 +3,10 @@ >> ;; Copyright (C) 2023 Onnie Lynn Winebarger >> >> ;; Author: Onnie Lynn Winebarger >> +;; Maintainer: Onnie Lynn Winebarger >> +;; URL: https://github.com/owinebar/emacs-table-allocation-manager >> +;; Package-Requires: ((emacs "24.4") (queue "0.2")) >> + > > Apologies, I renamed the library to tam.el and failed to note the > changes I made to the renamed file did not get committed and pushed. So what does that mean? >> ;; Keywords: lisp, tools >> >> ;; This program is free software; you can redistribute it and/or modify >> @@ -24,7 +28,9 @@ >> ;; table. All allocation is done during initialization to avoid trigge= ring >> ;; garbage collection during allocation/free operations. >> >> -;; API: >> +;; API: (is it necessary to document the API here? This has to be >> +;; kept up to date, while a M-x apropos-function tam- RET could avoid >> +;; the issue.) > > I thought it would be helpful to summarize the functionality for review. That is true, but I wouldn't bother with maintaining this in the long term. Encouraging the usage of apropos commands is good anyway. >> ;; >> ;; (tam-create-table N) =3D> table of size N >> ;; (tam-table-fullp TABLE) =3D> nil unless TABLE is full >> @@ -43,13 +49,12 @@ >> ;; (tam-table-free-list TABLE) =3D> list of free indices in TABLE >> ;; (tam-table-live-list TABLE) =3D> list of in-use indices in TABLE >> >> - >> ;;; Code: >> >> (eval-when-compile >> (require 'cl-lib)) >> >> -(require 'queue) >> +(require 'queue) ;is this even necessary? see be= low. > > If it's a big deal, then no. Since queue is a GNU package, I > preferred to not repeat code. I am the kind of person who thinks twice about installing a package when it has dependencies. But if you prefer to use a package available on ELPA, then that is of course OK as well. >> >> (cl-defstruct (tam--table (:constructor tam--table-create (size)) >> (:copier tam--copy-table)) >> @@ -66,16 +71,15 @@ >> (table index in-use next previous= )) >> (:copier tam--copy-slot)) >> "Slot in TAM table" >> - table ;; table containing this slot >> - index ;; index of slot in table >> - in-use ;; flag indicating if contents are "live" >> - next ;; next on list of used/free >> - previous ;; previous on list of used/free >> - contents ;; contents of slot >> - ) >> + (table :documentation "table containing this slot") >> + (index :documentation "index of slot in table") >> + (in-use :documentation "flag indicating if contents are live") >> + (next :documentation "next on list of used/free") >> + (previous :documentation "previous on list of used/free") >> + (contents :documentation "contents of slot")) >> >> (defun tam-create-table (N) >> - "Make a tam table of size N." >> + "Make a tam table of size N." ;"tam table" might not b= e clear. >> (let ((tbl (tam--table-create N)) >> (v (make-vector N nil)) >> (N-1 (- N 1)) >> @@ -98,8 +102,6 @@ >> (setf (tam--table-last-free tbl) (aref v N-1)) >> tbl)) >> >> - >> - >> (defun tam-table-fullp (tbl) >> "Test if TBL is full." >> (<=3D (tam--table-size tbl) (tam--table-used tbl))) >> @@ -108,22 +110,20 @@ >> "Test if TBL is empty." >> (=3D (tam--table-used tbl) 0)) >> >> -(defsubst tam-table-size (tbl) >> +(defsubst tam-table-size (tbl) ;why not `defalias' > > I tried defalias first, but got a byte-compiler error about a void > variable. Which I found confusing, since it should be looking for a > function definition, not a variable. I'm using 28.3. > Some of the following should have already been fixed from when I ran chec= kdoc. What did you do? That sounds like something was misquoted: (defalias 'tam-table-size #'tam--table-size) ? >> "Number of slots in TBL." >> (tam--table-size tbl)) >> >> - >> (defsubst tam-table-used (tbl) >> "Number of slots of TBL in use." >> (tam--table-used tbl)) >> >> (defun tam--table-get-slot (tbl idx) >> - "Get slot IDX of TBL" >> + "Get slot IDX of TBL." >> (aref (tam--table-slots tbl) idx)) >> >> - >> (defun tam-table-get (tbl idx) >> - "Get contents of slot IDX of TBL" >> + "Get contents of slot IDX of TBL." >> (tam--slot-contents (aref (tam--table-slots tbl) idx))) >> >> (defun tam-allocate (tbl obj) >> @@ -133,9 +133,14 @@ Returns index or nil if table is full." >> next idx) >> (when (not (tam-table-fullp tbl)) >> (setf (tam--slot-previous s) (tam--table-last-used tbl)) >> - (if (tam-table-emptyp tbl) >> - (setf (tam--table-first-used tbl) s) >> - (setf (tam--slot-next (tam--table-last-used tbl)) s)) >> + (setf (if (tam-table-emptyp tbl) >> + (tam--table-first-used tbl) >> + (tam--slot-next (tam--table-last-used tbl))) >> + s) > > Is this a personal stylistic preference, or a requirement?=20=20 Nothing I say is a requirement, I should have made that explicit. More of a "look what you could also do, in case you are interested". > I'll > change it if required, but I find computing the place inside a set > form to be disconcerting if it's not required. For example, I > wouldn't use a set form like > (set (if P 'A 'B) some-value) > in place of > (if P (setq A some-value) (setq B some-value)) In that case, is there a reason you are using setf? > where I might be amenable to > (set (opaque-function-call args ...) some-value) > >> + (setf (if (tam-table-emptyp tbl) >> + (tam--table-first-used tbl) >> + (tam--slot-next (tam--table-last-used tbl))) >> + s) > I'm assuming this is a typo. Probably. >> (setf (tam--table-last-used tbl) s) >> (setq next (tam--slot-next s)) >> (setf (tam--table-first-free tbl) next) >> @@ -151,8 +156,9 @@ Returns index or nil if table is full." >> idx)) >> >> (defun tam-free (tbl idx) >> - "Free slot at IDX in TBL. Returns contents of slot IDX. >> -Signals an error if IDX is not in use." >> + "Free slot at IDX in TBL. >> +Returns contents of slot IDX. Signals an error if IDX is not in >> +use." >> (let ((s (tam--table-get-slot tbl idx)) >> (last-free (tam--table-last-free tbl)) >> prev next obj) >> @@ -185,17 +191,19 @@ Signals an error if IDX is not in use." >> (cl-decf (tam--table-used tbl)) >> obj)) >> >> +;; you appear to only use the queue to track a list of objects, right? >> +;; Why not this then: >> (defun tam-table-free-list (tbl) >> - "Return list of free indices in TBL" >> + "Return list of free indices in TBL." >> (let ((s (tam--table-first-free tbl)) >> - (q (queue-create))) >> + (q '())) >> (while s >> - (queue-enqueue q (tam--slot-index s)) >> + (push (tam--slot-index s) q) >> (setq s (tam--slot-next s))) >> - (queue-all q))) >> + (nreverse q))) ;iff even necessary > > I do want to return lists reflecting the ordering of the slots. I am > not a fan of constructing an ordered structure only to reverse it. FWIW this is standard practice, and what a cl-loop with collect would also expand to. And if I am not mistaken, this is more efficient, than accumulating a linked list in the right order to begin with (it is a difference of O(n) vs O(n^2), I believe). > I can rewrite this to append to the tail using let-bound head and tail > variables, but it seems excessive to avoid a single allocation of a > queue structure. > That said, these functions are primarily intended for debugging. Wouldn't that kind of a convenience be an argument against adding an extra dependency? >> >> (defun tam-table-live-list (tbl) >> - "Return list of live indices in TBL" >> + "Return list of live indices in TBL." >> (let ((s (tam--table-first-used tbl)) >> (q (queue-create))) >> (while s >> >> -- >> Philip Kaludercic --=20 Philip Kaludercic