Debian Codegraph @

texmf-dist/tex/generic/pgf/utilities/pgfutil-common-lists.tex

raw
1 % Copyright 2019 by Christian Feuersaenger
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Public License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
11 %
12 % This list here is a general re-implementation of the list used in
13 % the PGF system layer.
14 % It employs two collect-buffers to reduce the runtime.
15 %
16 % - It has pre-asymptotical runtime O(N), but is O(N^2) asymptotically.
17 % - It requires only 5 macros per list.
18 %
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20
21 \pgfutil@packagewarning
22 {pgfutil-common-lists}%
23 {This package is deprecated and will be removed by the end of 2022}
24
25 % Usage:
26 % \pgfapplistnewempty\macro
27 \def\pgfapplistnewempty#1{%
28 \expandafter\let\csname pgfapp@#1\endcsname=\pgfutil@empty
29 \expandafter\let\csname pgfapp@#1@smallbuf\endcsname=\pgfutil@empty
30 \expandafter\let\csname pgfapp@#1@bigbuf\endcsname=\pgfutil@empty
31 \expandafter\def\csname pgfapp@#1@smallbuf@c\endcsname{0}%
32 \expandafter\def\csname pgfapp@#1@bigbuf@c\endcsname{0}%
33 }%
34
35 % #1: the item to append
36 % #2: the list as macro name
37 \long\def\pgfapplistpushback#1\to#2{%
38 \begingroup
39 \c@pgf@counta=\csname pgfapp@#2@smallbuf@c\endcsname\relax
40 \advance\c@pgf@counta by1
41 \xdef\pgf@glob@TMPa{\the\c@pgf@counta}%
42 \endgroup
43 \expandafter\let\csname pgfapp@#2@smallbuf@c\endcsname=\pgf@glob@TMPa
44 \ifnum\csname pgfapp@#2@smallbuf@c\endcsname<40
45 \t@pgf@toka=\expandafter\expandafter\expandafter{\csname pgfapp@#2@smallbuf\endcsname#1}%
46 \expandafter\edef\csname pgfapp@#2@smallbuf\endcsname{\the\t@pgf@toka}%
47 \else
48 \pgfapplistpushback@smallbufoverfl{#1}{#2}%
49 \fi
50 }%
51 \long\def\pgfapplistpushback@smallbufoverfl#1#2{%
52 \begingroup
53 \c@pgf@counta=\csname pgfapp@#2@bigbuf@c\endcsname\relax
54 \advance\c@pgf@counta by1
55 \xdef\pgf@glob@TMPa{\the\c@pgf@counta}%
56 \endgroup
57 \expandafter\let\csname pgfapp@#2@bigbuf@c\endcsname=\pgf@glob@TMPa
58 %
59 \ifnum\csname pgfapp@#2@bigbuf@c\endcsname<30
60 \t@pgf@toka=\expandafter\expandafter\expandafter{\csname pgfapp@#2@bigbuf\endcsname}%
61 \t@pgf@tokb=\expandafter\expandafter\expandafter{\csname pgfapp@#2@smallbuf\endcsname#1}%
62 \expandafter\edef\csname pgfapp@#2@bigbuf\endcsname{\the\t@pgf@toka\the\t@pgf@tokb}%
63 \expandafter\let\csname pgfapp@#2@smallbuf\endcsname=\pgfutil@empty
64 \expandafter\def\csname pgfapp@#2@smallbuf@c\endcsname{0}%
65 \else%
66 \t@pgf@toka=\expandafter\expandafter\expandafter{\csname pgfapp@#2\endcsname}%
67 \t@pgf@tokb=\expandafter\expandafter\expandafter{\csname pgfapp@#2@bigbuf\endcsname}%
68 \t@pgf@tokc=\expandafter\expandafter\expandafter{\csname pgfapp@#2@smallbuf\endcsname#1}%
69 \expandafter\edef\csname pgfapp@#2\endcsname{\the\t@pgf@toka\the\t@pgf@tokb\the\t@pgf@tokc}%
70 \expandafter\let\csname pgfapp@#2@smallbuf\endcsname=\pgfutil@empty
71 \expandafter\def\csname pgfapp@#2@smallbuf@c\endcsname{0}%
72 \expandafter\let\csname pgfapp@#2@bigbuf\endcsname=\pgfutil@empty
73 \expandafter\def\csname pgfapp@#2@bigbuf@c\endcsname{0}%
74 \fi%
75 }%
76 \def\pgfapplist@flushbuffers#1{%
77 \t@pgf@toka=\expandafter\expandafter\expandafter{\csname pgfapp@#1\endcsname}%
78 \t@pgf@tokb=\expandafter\expandafter\expandafter{\csname pgfapp@#1@bigbuf\endcsname}%
79 \t@pgf@tokc=\expandafter\expandafter\expandafter{\csname pgfapp@#1@smallbuf\endcsname}%
80 \expandafter\edef\csname pgfapp@#1\endcsname{\the\t@pgf@toka\the\t@pgf@tokb\the\t@pgf@tokc}%
81 \expandafter\let\csname pgfapp@#1@smallbuf\endcsname=\pgfutil@empty
82 \expandafter\def\csname pgfapp@#1@smallbuf@c\endcsname{0}%
83 \expandafter\let\csname pgfapp@#1@bigbuf\endcsname=\pgfutil@empty
84 \expandafter\def\csname pgfapp@#1@bigbuf@c\endcsname{0}%
85 }%
86
87 \def\pgfapplistlet#1=#2{%
88 \pgfapplist@flushbuffers{#2}%
89 \expandafter\let\expandafter#1\csname pgfapp@#2\endcsname
90 }%
91
92
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %
95 % A variant of applist which has the same runtime requirements, but
96 % does PUSH FRONT only.
97 %
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99
100
101 % Usage:
102 % \pgfprependlistnewempty{list}
103 \def\pgfprependlistnewempty#1{%
104 \expandafter\let\csname pgfpPRP@#1\endcsname=\pgfutil@empty
105 \expandafter\let\csname pgfpPRP@#1@smallbuf\endcsname=\pgfutil@empty
106 \expandafter\let\csname pgfpPRP@#1@bigbuf\endcsname=\pgfutil@empty
107 \expandafter\def\csname pgfpPRP@#1@smallbuf@c\endcsname{0}%
108 \expandafter\def\csname pgfpPRP@#1@bigbuf@c\endcsname{0}%
109 }%
110
111 % #1: the item to prepend
112 % #2: the list as macro name
113 \long\def\pgfprependlistpushfront#1\to#2{%
114 \begingroup
115 \c@pgf@counta=\csname pgfpPRP@#2@smallbuf@c\endcsname\relax
116 \advance\c@pgf@counta by1
117 \xdef\pgf@glob@TMPa{\the\c@pgf@counta}%
118 \endgroup
119 \expandafter\let\csname pgfpPRP@#2@smallbuf@c\endcsname=\pgf@glob@TMPa
120 \ifnum\csname pgfpPRP@#2@smallbuf@c\endcsname<40
121 \t@pgf@toka=\expandafter\expandafter\expandafter{\csname pgfpPRP@#2@smallbuf\endcsname}%
122 \t@pgf@tokb={#1}%
123 \expandafter\edef\csname pgfpPRP@#2@smallbuf\endcsname{\the\t@pgf@tokb\the\t@pgf@toka}%
124 \else
125 \pgfprependlistpushfront@smallbufoverfl{#1}{#2}%
126 \fi
127 }%
128 \long\def\pgfprependlistpushfront@smallbufoverfl#1#2{%
129 \begingroup
130 \c@pgf@counta=\csname pgfpPRP@#2@bigbuf@c\endcsname\relax
131 \advance\c@pgf@counta by1
132 \xdef\pgf@glob@TMPa{\the\c@pgf@counta}%
133 \endgroup
134 \expandafter\let\csname pgfpPRP@#2@bigbuf@c\endcsname=\pgf@glob@TMPa
135 %
136 \ifnum\csname pgfpPRP@#2@bigbuf@c\endcsname<30
137 \t@pgf@toka=\expandafter\expandafter\expandafter{\csname pgfpPRP@#2@bigbuf\endcsname}%
138 \t@pgf@tokb=\expandafter\expandafter\expandafter{\csname pgfpPRP@#2@smallbuf\endcsname}%
139 \t@pgf@tokc={#1}%
140 \expandafter\edef\csname pgfpPRP@#2@bigbuf\endcsname{\the\t@pgf@tokc\the\t@pgf@tokb\the\t@pgf@toka}%
141 \expandafter\let\csname pgfpPRP@#2@smallbuf\endcsname=\pgfutil@empty
142 \expandafter\def\csname pgfpPRP@#2@smallbuf@c\endcsname{0}%
143 \else%
144 \pgfprependlist@flushbuffers{#2}%
145 \t@pgf@toka=\expandafter\expandafter\expandafter{\csname pgfpPRP@#2\endcsname}%
146 \t@pgf@tokb={#1}%
147 \expandafter\edef\csname pgfpPRP@#2\endcsname{\the\t@pgf@tokb\the\t@pgf@toka}%
148 \fi%
149 }%
150 \def\pgfprependlist@flushbuffers#1{%
151 \t@pgf@toka=\expandafter\expandafter\expandafter{\csname pgfpPRP@#1\endcsname}%
152 \t@pgf@tokb=\expandafter\expandafter\expandafter{\csname pgfpPRP@#1@bigbuf\endcsname}%
153 \t@pgf@tokc=\expandafter\expandafter\expandafter{\csname pgfpPRP@#1@smallbuf\endcsname}%
154 \expandafter\edef\csname pgfpPRP@#1\endcsname{\the\t@pgf@tokc\the\t@pgf@tokb\the\t@pgf@toka}%
155 \expandafter\let\csname pgfpPRP@#1@smallbuf\endcsname=\pgfutil@empty
156 \expandafter\def\csname pgfpPRP@#1@smallbuf@c\endcsname{0}%
157 \expandafter\let\csname pgfpPRP@#1@bigbuf\endcsname=\pgfutil@empty
158 \expandafter\def\csname pgfpPRP@#1@bigbuf@c\endcsname{0}%
159 }%
160 \def\pgfprependlistlet#1=#2{%
161 \pgfprependlist@flushbuffers{#2}%
162 \expandafter\let\expandafter#1\csname pgfpPRP@#2\endcsname
163 }%