diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructure.code.tex')
-rw-r--r-- | Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructure.code.tex | 98 |
1 files changed, 73 insertions, 25 deletions
diff --git a/Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructure.code.tex b/Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructure.code.tex index 48fd19a890c..d7bd7dc73ed 100644 --- a/Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructure.code.tex +++ b/Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsliststructure.code.tex @@ -4,12 +4,17 @@ % % Its implementation is based on Knuth's list macros in "The TeXbook". % +% It features a convenient set of list macros, but it is not fast. +% In fact, every elementary operation requires time O(N), so working +% with this list easily leads to O(N^2) runtime. +% % The following macros are supplied: % % \pgfplotslistnewempty % \pgfplotslistnew % \pgfplotslistcopy % \pgfplotslistpopfront +% \pgfplotslistfront % \pgfplotslistpushback % \pgfplotslistpushfront % \pgfplotslistsize @@ -17,6 +22,10 @@ % \pgfplotslistcheckempty % \pgfplotslistforeach % +% @see \pgfplotsapplist a "real" list with O(1) pushback, but limited application. +% @see \pgfplotsapplistX a preasymptotical fast list to accumulate elements. +% @see \pgfplotsapplistXX an optimized version of \pgfplotsapplistX. +% % Copyright 2007/2008 by Christian Feuersänger. % % This program is free software: you can redistribute it and/or modify @@ -36,8 +45,6 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newtoks\pgfplotslist@TOK@a -\newtoks\pgfplotslist@TOK@b \newif\ifpgfplotslistempty @@ -74,7 +81,7 @@ \else \expandafter\def\expandafter\pgfplotslistnew@impl@rest\expandafter{\pgfplotslistnew@impl@rest,}% \fi - \loop + \pgfutil@loop \ifx\pgfplotslistnew@impl@rest\pgfutil@empty \pgfplots@loop@CONTINUEfalse \else @@ -86,13 +93,13 @@ \else \expandafter\pgfplotslistnew@impl@comma\pgfplotslistnew@impl@rest\tolist#1\relax \fi - \repeat + \pgfutil@repeat } \def\pgfplotslist@EOI{\pgfplotslist@EOI} \def\pgfplotslist@check@backslash@list#1\\#2\pgfplotslist@EOI{% - \def\pgfplotslist@TMPB{#2}% - \ifx\pgfplotslist@TMPB\pgfutil@empty + \def\pgfplotslist@loc@TMPa{#2}% + \ifx\pgfplotslist@loc@TMPa\pgfutil@empty \pgfplotslist@is@backslash@terminatedfalse \else \pgfplotslist@is@backslash@terminatedtrue @@ -119,9 +126,15 @@ % Example: % \pgfplotslistpushfront Next first Element\to\foolist \long\def\pgfplotslistpushfront#1\to#2{% - \pgfplotslist@TOK@a={\pgfplotslist@sep{#1}}% - \pgfplotslist@TOK@b=\expandafter{#2}% - \edef#2{\the\pgfplotslist@TOK@a\the\pgfplotslist@TOK@b}% + \t@pgfplots@toka={\pgfpl@@{#1}}% + \t@pgfplots@tokb=\expandafter{#2}% + \edef#2{\the\t@pgfplots@toka\the\t@pgfplots@tokb}% +} + +% Assembles a low-level list item representation into the token +% register #2. +\def\pgfplotslist@assembleentry#1\into#2{% + #2={\pgfpl@@{#1}}% } % #1: the item to append @@ -129,22 +142,32 @@ % Example: % \pgfplotslistpushback Next last element\to\foolist \long\def\pgfplotslistpushback#1\to#2{% - \pgfplotslist@TOK@a={\pgfplotslist@sep{#1}}% + \t@pgfplots@toka={\pgfpl@@{#1}}% \ifx#2\pgfutil@empty - \pgfplotslist@TOK@b={}% + \t@pgfplots@tokb={}% \else - \pgfplotslist@TOK@b=\expandafter{#2}% + \t@pgfplots@tokb=\expandafter{#2}% \fi - \edef#2{\the\pgfplotslist@TOK@b\the\pgfplotslist@TOK@a}% + \edef#2{\the\t@pgfplots@tokb\the\t@pgfplots@toka}% +} +% Adds '#1' to the GLOBAL list '#2'. +\long\def\pgfplotslistpushbackglobal#1\to#2{% + \t@pgfplots@toka={\pgfpl@@{#1}}% + \ifx#2\pgfutil@empty + \t@pgfplots@tokb={}% + \else + \t@pgfplots@tokb=\expandafter{#2}% + \fi + \xdef#2{\the\t@pgfplots@tokb\the\t@pgfplots@toka}% } % Concatenates two lists #2 and #3 into #1 % Example: % \pgfplotslistconcat\result=\foolist&\bar \long\def\pgfplotslistconcat#1=#2{% - \pgfplotslist@TOK@a=\expandafter{#2}% - \pgfplotslist@TOK@b=\expandafter{#3}% - \edef#1{\the\pgfplotslist@TOK@a\the\pgfplotslist@TOK@b}% + \t@pgfplots@toka=\expandafter{#2}% + \t@pgfplots@tokb=\expandafter{#3}% + \edef#1{\the\t@pgfplots@toka\the\t@pgfplots@tokb}% } % implements #2 := pop_front(#1) @@ -154,16 +177,29 @@ \pgfplotslistcheckempty#1\relax \ifpgfplotslistempty \pgfplots@error{ERROR: \string\pgfplotslistpopfront\ from \string#1\ although list is EMPTY}% + \let#2=\pgfutil@empty \else \expandafter\pgfplotslistpopfront@impl#1\pgfplotslistpopfront@macronames#1#2% \fi } +\long\def\pgfplotslistfront#1\to#2{% + \pgfplotslistcheckempty#1\relax + \ifpgfplotslistempty + \pgfplots@error{ERROR: \string\pgfplotslistfront\ from \string#1\ although list is EMPTY}% + \let#2=\pgfutil@empty + \else + \expandafter\pgfplotslistfront@impl#1\pgfplotslistpopfront@macronames#2% + \fi +} % implementation helper for listpopfront -\long\def\pgfplotslistpopfront@impl\pgfplotslist@sep#1#2\pgfplotslistpopfront@macronames#3#4{% +\long\def\pgfplotslistpopfront@impl\pgfpl@@#1#2\pgfplotslistpopfront@macronames#3#4{% \def#4{#1}% \def#3{#2}% } +\long\def\pgfplotslistfront@impl\pgfpl@@#1#2\pgfplotslistpopfront@macronames#3{% + \def#3{#1}% +} % Counts the number of elements in list #1, storing it into the count % register #2. @@ -172,7 +208,7 @@ % \the\count0 \long\def\pgfplotslistsize#1\to#2{% #2=0% - \long\def\pgfplotslist@sep##1{\advance#2 by 1 }% + \long\def\pgfpl@@##1{\advance#2 by 1 }% #1% } @@ -188,12 +224,15 @@ % \elem % Element \count1: % \pgfplotslistselect\count1\of\foo\to\elem -\long\def\pgfplotslistselect#1\of#2\to#3{% - \global\def\pgfplotslistselect@tmp{\def#3{\pgfplots@error{The requested item #1 of \string#2 is OUT OF RANGE.}}}% +\def\pgfplotslistselect#1\of#2\to#3{% + \global\def\pgfplotslistselect@tmp{\def#3{}\pgfplots@error{The requested list entry with index #1 of \string#2 is too large; this list has not enough elements.}}% + \pgfplotslistselect@{#1}\of{#2}\to{#3}% +} +\def\pgfplotslistselect@#1\of#2\to#3{% \begingroup \count0=#1\relax - \long\def\pgfplotslist@sep##1{% - \advance\count0-1\relax + \long\def\pgfpl@@##1{% + \advance\count0 by-1\relax \ifnum\count0=-1\relax \global\def\pgfplotslistselect@tmp{\def#3{##1}}% \fi% @@ -202,6 +241,10 @@ \endgroup \pgfplotslistselect@tmp } +\def\pgfplotslistselectorempty#1\of#2\to#3{% + \global\def\pgfplotslistselect@tmp{\def#3{}}% + \pgfplotslistselect@{#1}\of{#2}\to{#3}% +} % Sets the boolean \ifpgfplotslistempty depending on whether list #1 is empty % or not. @@ -217,7 +260,12 @@ \ifx#1\pgfutil@empty \pgfplotslistemptytrue \else - \pgfplotslistemptyfalse + \ifx#1\relax + \pgfplots@warning{WARNING: possible logic error in script code: the command \string\pgfplotslistcheckempty{\string#1} encountered an undefined argument.}% + \pgfplotslistemptytrue + \else + \pgfplotslistemptyfalse + \fi \fi } @@ -233,7 +281,7 @@ % Each single element will be grouped with TeX groups. \long\def\pgfplotslistforeach#1\as#2#3{% \begingroup - \long\def\pgfplotslist@sep##1{\def#2{##1}% + \long\def\pgfpl@@##1{\def#2{##1}% \begingroup #3 \endgroup}% @@ -249,7 +297,7 @@ \pgfplots@error{Sorry, you can't nest pgfplotslistforeachungrouped.}% \else \pgfplotslistforeachungroupedrunningtrue - \long\def\pgfplotslist@sep##1{\def#2{##1}#3}% + \long\def\pgfpl@@##1{\def#2{##1}#3}% #1\relax \pgfplotslistforeachungroupedrunningfalse \fi |