[latex3-commits] [git/LaTeX3-latex3-latex3] l3bitset: make index 1-based instead of zero-based (90ce6e540)

Ulrike Fischer fischer at troubleshooting-tex.de
Thu Dec 17 11:34:45 CET 2020


Repository : https://github.com/latex3/latex3
On branch  : l3bitset
Link       : https://github.com/latex3/latex3/commit/90ce6e5400ab0f7649c88bf8c0cadc564725c348

>---------------------------------------------------------------

commit 90ce6e5400ab0f7649c88bf8c0cadc564725c348
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Thu Dec 17 11:34:45 2020 +0100

    make index 1-based instead of zero-based


>---------------------------------------------------------------

90ce6e5400ab0f7649c88bf8c0cadc564725c348
 l3kernel/l3bitset.dtx              |  79 +++++++++++++++--------------
 l3kernel/testfiles/m3bitset001.lvt | 100 ++++++++++++++++++-------------------
 l3kernel/testfiles/m3bitset002.lvt |  40 +++++++--------
 3 files changed, 109 insertions(+), 110 deletions(-)

diff --git a/l3kernel/l3bitset.dtx b/l3kernel/l3bitset.dtx
index bc2f28bea..f6b0cb21f 100644
--- a/l3kernel/l3bitset.dtx
+++ b/l3kernel/l3bitset.dtx
@@ -50,8 +50,7 @@
 % This package defines and implements the data type \texttt{bitset}, a vector of
 % bits. The size of the vector may grow dynamically.
 % Individual bits can be set and unset by index and by name.
-% The index is unlike other indices in expl3 modules \emph{zero based} as this
-% is the standard for bitset data types.
+% The index is like all other indices in expl3 modules \emph{1-based}.
 % A \texttt{bitset} can be output as binary number or---as needed e.g. in a
 % PDF dictionary---as decimal (arabic) number.
 % Currently only a small subset of the functions provided by the \pkg{bitset}
@@ -75,7 +74,7 @@
 %
 %  Bitsets are implemented as string variables consisting of
 %  \texttt{1}'s and \texttt{0}'s.
-%  The rightmost number is the index position 0, so
+%  The rightmost number is the index position 1, so
 %  the string variable can be viewed directly as the binary number.
 %
 % \end{function}
@@ -99,7 +98,7 @@
 %     \cs{bitset_gset_true:Nn}  \meta{bitset var}  \Arg{integer expression}
 %   \end{syntax}
 % Evaluates the \meta{integer expression} and sets the bit of the
-% index position it represents to 1. Index position are zero based and set from
+% index position it represents to 1. Index position are 1-based and set from
 % right to left (so one can view the bitset as a binary number).
 % If needed the length of the bit vector is enlarged.
 % If the \meta{integer expression} evaluates to a negative number, nothing happens.
@@ -113,7 +112,7 @@
 %   \end{syntax}
 % Evaluates the \meta{integer expression} and unsets the bit of the
 % index position it represents (sets it to 0).
-% The index is zero based. If the \meta{integer expression} evaluates to a
+% The index is 1-based. If the \meta{integer expression} evaluates to a
 % negative number or is larger than the current length of the bit vector
 % nothing happens. If the leading (left most) bit is unset,
 % zeros are not trimmed but stay in the bit vector.
@@ -180,19 +179,19 @@
 %  \prop_new:N   \l_pdfannot_F_bitset_prop
 %  \prop_set_from_keyval:Nn \l_pdfannot_F_bitset_prop
 %    {
-%      Invisible      = 0,
-%      Hidden         = 1,
-%      Print          = 2,
-%      NoZoom         = 3,
-%      NoRotate       = 4,
-%      NoView         = 5,
-%      ReadOnly       = 6,
-%      Locked         = 7,
-%      ToggleNoView   = 8,
-%      LockedContents = 9
+%      Invisible      = 1,
+%      Hidden         = 2,
+%      Print          = 3,
+%      NoZoom         = 4,
+%      NoRotate       = 5,
+%      NoView         = 6,
+%      ReadOnly       = 7,
+%      Locked         = 8,
+%      ToggleNoView   = 9,
+%      LockedContents = 10
 %    }
 %  \end{verbatim}
-%  it is possible to set bit 2 by using
+%  it is possible to set bit 3 by using
 %  |\bitset_set_key:Nn \l_pdfannot_F_bitset {Print}|
 %  If a key is unknown a warning is issued.
 %  It is not needed to give  all index positions a name.
@@ -273,15 +272,15 @@
 % A bit is set by either extending the string or by splitting it and
 % then inserting an 1. It is not checked if the value was already 1.
 %    \begin{macrocode}
-% #1 name, #2 index (integer expression,zero based)
+% #1 name, #2 index (integer expression, 1-based)
 \cs_new_protected:Npn \bitset_set_true:Nn #1 #2
   {
-    \int_compare:nNnT {#2 } > { -1 }
+    \int_compare:nNnT {#2 } > { 0 }
       {
-        \int_compare:nNnTF {\str_count:N #1 } < { #2 + 1 }
+        \int_compare:nNnTF {\str_count:N #1 } < { #2  }
           {
             %extend the str
-            \int_step_inline:nn { #2 - \str_count:N #1 }
+            \int_step_inline:nn { #2 - \str_count:N #1 -1 }
               {
                 \str_put_left:Nn #1 { 0 }
               }
@@ -291,23 +290,23 @@
             %replace value
             \str_set:Nx #1
               {
-                \str_range:Nnn #1 {1}{-2 - (#2)}
+                \str_range:Nnn #1 {1}{-1 - (#2)}
                 1
-                \str_range:Nnn #1 {0 -(#2)}{-1}
+                \str_range:Nnn #1 {1 -(#2)}{-1}
              }
           }
       }
   }
 
-%#1 name, #2 index (integer expression,zero based)
+%#1 name, #2 index (integer expression,1-based)
 \cs_new_protected:Npn \bitset_gset_true:Nn #1 #2
   {
-    \int_compare:nNnT {#2 } > { -1 }
+    \int_compare:nNnT {#2 } > { 0 }
       {
-        \int_compare:nNnTF {\str_count:N #1 } < { #2 + 1 }
+        \int_compare:nNnTF {\str_count:N #1 } < { #2  }
           {
             %extend the str
-            \int_step_inline:nn { #2 - \str_count:N #1 }
+            \int_step_inline:nn { #2 - \str_count:N #1 -1}
               {
                 \str_gput_left:Nn #1 { 0 }
               }
@@ -317,9 +316,9 @@
             % replace the value
             \str_gset:Nx #1
               {
-                \str_range:Nnn #1 {1}{-2 -(#2)}
+                \str_range:Nnn #1 {1}{-1 -(#2)}
                 1
-                \str_range:Nnn #1 {0 -(#2)}{-1}
+                \str_range:Nnn #1 {1 -(#2)}{-1}
               }
           }
       }
@@ -336,35 +335,35 @@
 %   }
 % Unsetting a bit has only to do something if the string is longer than then index.
 %    \begin{macrocode}
-\cs_new_protected:Npn \bitset_set_false:Nn #1 #2  %#1 name, #2 index (zero based)
+\cs_new_protected:Npn \bitset_set_false:Nn #1 #2  %#1 name, #2 index (1-based)
  {
-   \int_compare:nNnT {#2 } > { -1 }
+   \int_compare:nNnT {#2 } > { 0 }
      {
-       \int_compare:nNnT {\str_count:N #1 } > { #2 }
+       \int_compare:nNnT {\str_count:N #1 } > { #2 -1 }
          {
            % need to replace the str
            \str_set:Nx #1
              {
-               \str_range:Nnn #1 {1}{-2 - (#2)}
+               \str_range:Nnn #1 {1}{-1 - (#2)}
                 0
-               \str_range:Nnn #1 { 0 - (#2)}{-1}
+               \str_range:Nnn #1 { 1 - (#2)}{-1}
              }
          }
      }
  }
 
-\cs_new_protected:Npn \bitset_gset_false:Nn #1 #2  %#1 name, #2 index (zero based)
+\cs_new_protected:Npn \bitset_gset_false:Nn #1 #2  %#1 name, #2 index (1-based)
  {
-   \int_compare:nNnT {#2 } > { -1 }
+   \int_compare:nNnT {#2 } > { 0 }
      {
-       \int_compare:nNnT {\str_count:N #1 } > { #2 }
+       \int_compare:nNnT {\str_count:N #1 } > { #2 -1 }
          {
            % need to replace the str
            \str_gset:Nx #1
              {
-               \str_range:Nnn #1 {1}{-2 -(#2)}
+               \str_range:Nnn #1 {1}{-1 -(#2)}
                 0
-               \str_range:Nnn #1 {0 - (#2)}{-1}
+               \str_range:Nnn #1 {1 - (#2)}{-1}
              }
          }
      }
@@ -404,7 +403,7 @@
 %    \begin{macrocode}
 \cs_new:Npn \bitset_index:Nn #1 #2
  {
-   \int_eval:n { \str_item:Nn #1 { -1 - (#2)} +0 }
+   \int_eval:n { \str_item:Nn #1 { 0 - (#2)} + 0 }
  }
 \cs_generate_variant:Nn \bitset_index:Nn {cn}
 %    \end{macrocode}
@@ -532,7 +531,7 @@
         \int_eval:n
           {
             \str_item:Nn #1
-              { -1 -(\prop_item:cn{\cs_to_str:N #1_prop}{#2}) }
+              { 0 -(\prop_item:cn{\cs_to_str:N #1_prop}{#2}) }
             +0
           }
      }
diff --git a/l3kernel/testfiles/m3bitset001.lvt b/l3kernel/testfiles/m3bitset001.lvt
index 54058f0b4..6dae57e19 100644
--- a/l3kernel/testfiles/m3bitset001.lvt
+++ b/l3kernel/testfiles/m3bitset001.lvt
@@ -16,77 +16,77 @@
 empty\par
 bin:~\bitset_to_bin:N \l_my_test_bitset\par
 arabic:~\bitset_to_arabic:N \l_my_test_bitset\par
-\bitset_index:Nn \l_my_test_bitset {0}\par
-\bitset_set_true:Nn \l_my_test_bitset{0}
+\bitset_index:Nn \l_my_test_bitset {1}\par
+\bitset_set_true:Nn \l_my_test_bitset{1}
 
 0:~ \bitset_to_bin:N \l_my_test_bitset\par
-\bitset_index:Nn \l_my_test_bitset {0}\par
+\bitset_index:Nn \l_my_test_bitset {1}\par
 
 \bitset_set_true:Nn \l_my_test_bitset{-2}
 \bitset_show:N \l_my_test_bitset
 
-\bitset_set_true:Nn   \l_my_test_bitset {2}
-\bitset_set_true:Nn   \l_my_test_bitset {4}
-\bitset_set_true:Nn   \l_my_test_bitset {6}
-\bitset_set_true:Nn   \l_my_test_bitset {8}
+\bitset_set_true:Nn   \l_my_test_bitset {3}
+\bitset_set_true:Nn   \l_my_test_bitset {5}
+\bitset_set_true:Nn   \l_my_test_bitset {7}
+\bitset_set_true:Nn   \l_my_test_bitset {9}
 \bitset_to_bin:N   \l_my_test_bitset\par
 \bitset_to_arabic:N\l_my_test_bitset\par
 
 
-\bitset_set_true:Nn \l_my_test_bitset{3}
+\bitset_set_true:Nn \l_my_test_bitset{4}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
 
-\bitset_set_false:Nn \l_my_test_bitset{3}
+\bitset_set_false:Nn \l_my_test_bitset{4}
 \bitset_show:N   \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
 
 40\par
-\bitset_set_true:Nn   \l_my_test_bitset {40}
+\bitset_set_true:Nn   \l_my_test_bitset {41}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
+\bitset_index:Nn \l_my_test_bitset {42},~
 \bitset_index:Nn \l_my_test_bitset {41},~
-\bitset_index:Nn \l_my_test_bitset {40},~
-\bitset_index:Nn \l_my_test_bitset {39}\par
+\bitset_index:Nn \l_my_test_bitset {40}\par
 
-\bitset_set_false:Nn \l_my_test_bitset {40}
+\bitset_set_false:Nn \l_my_test_bitset {41}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
 
 
 39\par
-\bitset_set_true:Nn   \l_my_test_bitset {39}
+\bitset_set_true:Nn   \l_my_test_bitset {40}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
-\bitset_set_false:Nn \l_my_test_bitset {39}
+\bitset_set_false:Nn \l_my_test_bitset {40}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
 
 20\par
-\bitset_set_true:Nn   \l_my_test_bitset {20}
+\bitset_set_true:Nn   \l_my_test_bitset {21}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
-\bitset_set_false:Nn \l_my_test_bitset {20}
+\bitset_set_false:Nn \l_my_test_bitset {21}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
 
 3\par
-\bitset_set_true:Nn   \l_my_test_bitset {3}
+\bitset_set_true:Nn   \l_my_test_bitset {4}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
-\bitset_set_false:Nn \l_my_test_bitset {3}
+\bitset_set_false:Nn \l_my_test_bitset {4}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
 
 0\par
-\bitset_set_true:Nn   \l_my_test_bitset {0}
+\bitset_set_true:Nn   \l_my_test_bitset {1}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
 \bitset_index:Nn \l_my_test_bitset {-1},~
-\bitset_index:Nn \l_my_test_bitset {0},~
-\bitset_index:Nn \l_my_test_bitset {1}\par
+\bitset_index:Nn \l_my_test_bitset {1},~
+\bitset_index:Nn \l_my_test_bitset {2}\par
 
-\bitset_set_false:Nn \l_my_test_bitset {0}
+\bitset_set_false:Nn \l_my_test_bitset {1}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
 
@@ -107,32 +107,32 @@ arabic:~\bitset_to_arabic:N \l_my_test_bitset\par
 \bitset_to_bin:N \l_my_test_bitset\par
 
 7\par
-\bitset_set_true:Nn   \l_my_test_bitset {7}
+\bitset_set_true:Nn   \l_my_test_bitset {8}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
-\bitset_set_false:Nn \l_my_test_bitset {7}
+\bitset_set_false:Nn \l_my_test_bitset {8}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
 
 
 1+2+8-4\par
-\bitset_set_true:Nn   \l_my_test_bitset {1+2+8-4}
+\bitset_set_true:Nn   \l_my_test_bitset {2+2+8-4}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
-\bitset_index:Nn \l_my_test_bitset {1+2+8-4},~
-\bitset_index:Nn \l_my_test_bitset {1+2+4},~
-\bitset_index:Nn \l_my_test_bitset {1+2+9}\par
+\bitset_index:Nn \l_my_test_bitset {2+2+8-4},~
+\bitset_index:Nn \l_my_test_bitset {2+2+4},~
+\bitset_index:Nn \l_my_test_bitset {2+2+9}\par
 
-\bitset_set_false:Nn \l_my_test_bitset {1+2+4}
+\bitset_set_false:Nn \l_my_test_bitset {2+2+4}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
 
 
 int max 3,4\par
-\bitset_set_true:Nn   \l_my_test_bitset {\int_max:nn{3}{4}}
+\bitset_set_true:Nn   \l_my_test_bitset {\int_max:nn{4}{5}}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
-\bitset_set_false:Nn \l_my_test_bitset {\int_max:nn{3}{4}}
+\bitset_set_false:Nn \l_my_test_bitset {\int_max:nn{4}{5}}
 \bitset_show:N \l_my_test_bitset
 \bitset_to_bin:N \l_my_test_bitset\par
 
@@ -145,51 +145,51 @@ global\par
 \bitset_gset_true:Nn \g_my_test_bitset{-2}
 \bitset_show:N \g_my_test_bitset
 
-\bitset_gset_true:Nn \g_my_test_bitset{3}
+\bitset_gset_true:Nn \g_my_test_bitset{4}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
-\bitset_gset_false:Nn \g_my_test_bitset{3}
+\bitset_gset_false:Nn \g_my_test_bitset{4}
 \bitset_show:N   \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
 
 
 40\par
-\bitset_gset_true:Nn   \g_my_test_bitset {40}
+\bitset_gset_true:Nn   \g_my_test_bitset {41}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
-\bitset_gset_false:Nn \g_my_test_bitset {40}
+\bitset_gset_false:Nn \g_my_test_bitset {41}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
 
 39\par
-\bitset_gset_true:Nn   \g_my_test_bitset {39}
+\bitset_gset_true:Nn   \g_my_test_bitset {40}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
-\bitset_gset_false:Nn \g_my_test_bitset {39}
+\bitset_gset_false:Nn \g_my_test_bitset {40}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
 
 20\par
-\bitset_gset_true:Nn   \g_my_test_bitset {20}
+\bitset_gset_true:Nn   \g_my_test_bitset {21}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
-\bitset_gset_false:Nn \g_my_test_bitset {20}
+\bitset_gset_false:Nn \g_my_test_bitset {21}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
 
 3\par
-\bitset_gset_true:Nn   \g_my_test_bitset {3}
+\bitset_gset_true:Nn   \g_my_test_bitset {4}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
-\bitset_gset_false:Nn \g_my_test_bitset {3}
+\bitset_gset_false:Nn \g_my_test_bitset {4}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
 
 0\par
-\bitset_gset_true:Nn   \g_my_test_bitset {0}
+\bitset_gset_true:Nn   \g_my_test_bitset {1}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
-\bitset_gset_false:Nn \g_my_test_bitset {0}
+\bitset_gset_false:Nn \g_my_test_bitset {1}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
 
@@ -210,28 +210,28 @@ global\par
 \bitset_to_bin:N \g_my_test_bitset\par
 
 7\par
-\bitset_gset_true:Nn   \g_my_test_bitset {7}
+\bitset_gset_true:Nn   \g_my_test_bitset {8}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
-\bitset_gset_false:Nn \g_my_test_bitset {7}
+\bitset_gset_false:Nn \g_my_test_bitset {8}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
 
 
 1+2+4\par
-\bitset_gset_true:Nn   \g_my_test_bitset {1+2+4}
+\bitset_gset_true:Nn   \g_my_test_bitset {2+2+4}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
-\bitset_gset_false:Nn \g_my_test_bitset {1+2+4}
+\bitset_gset_false:Nn \g_my_test_bitset {2+2+4}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
 
 
 int max 3,4\par
-\bitset_gset_true:Nn   \g_my_test_bitset {\int_max:nn{3}{4}}
+\bitset_gset_true:Nn   \g_my_test_bitset {\int_max:nn{4}{5}}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
-\bitset_gset_false:Nn \g_my_test_bitset {\int_max:nn{3}{4}}
+\bitset_gset_false:Nn \g_my_test_bitset {\int_max:nn{4}{5}}
 \bitset_show:N \g_my_test_bitset
 \bitset_to_bin:N \g_my_test_bitset\par
 
diff --git a/l3kernel/testfiles/m3bitset002.lvt b/l3kernel/testfiles/m3bitset002.lvt
index da4dd1378..1f716ac24 100644
--- a/l3kernel/testfiles/m3bitset002.lvt
+++ b/l3kernel/testfiles/m3bitset002.lvt
@@ -12,16 +12,16 @@
 \prop_new:N   \l_my_test_bitset_prop
 \prop_set_from_keyval:Nn \l_my_test_bitset_prop
   {
-    Invisible      = 0,
-    Hidden         = 1,
-    Print          = 2,
-    NoZoom         = 3,
-    NoRotate       = 4,
-    NoView         = 5,
-    ReadOnly       = 6,
-    Locked         = 7,
-    ToggleNoView   = 8,
-    LockedContents = 9
+    Invisible      = 1,
+    Hidden         = 2,
+    Print          = 3,
+    NoZoom         = 4,
+    NoRotate       = 5,
+    NoView         = 6,
+    ReadOnly       = 7,
+    Locked         = 8,
+    ToggleNoView   = 9,
+    LockedContents = 10
   }
 
 
@@ -57,16 +57,16 @@ global\par
 \prop_new:N   \g_my_test_bitset_prop
 \prop_gset_from_keyval:Nn \g_my_test_bitset_prop
   {
-    gInvisible      = 0,
-    gHidden         = 1,
-    gPrint          = 2,
-    gNoZoom         = 3,
-    gNoRotate       = 4,
-    gNoView         = 5,
-    gReadOnly       = 6,
-    gLocked         = 7,
-    gToggleNoView   = 8,
-    gLockedContents = 9
+    gInvisible      = 1,
+    gHidden         = 2,
+    gPrint          = 3,
+    gNoZoom         = 4,
+    gNoRotate       = 5,
+    gNoView         = 6,
+    gReadOnly       = 7,
+    gLocked         = 8,
+    gToggleNoView   = 9,
+    gLockedContents = 10
   }
 
 





More information about the latex3-commits mailing list.