summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsarray.code.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsarray.code.tex')
-rw-r--r--Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsarray.code.tex107
1 files changed, 102 insertions, 5 deletions
diff --git a/Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsarray.code.tex b/Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsarray.code.tex
index 1a0ce28dc03..59b69da9712 100644
--- a/Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsarray.code.tex
+++ b/Master/texmf-dist/tex/generic/pgfplots/liststructure/pgfplotsarray.code.tex
@@ -58,10 +58,12 @@
%
% the elements won't be initialised. Use 'set' for each element.
\def\pgfplotsarrayresize#1#2{%
- \pgfplotsarray@@edef{#1@size}{#2}%
+ \c@pgfplotsarray@tmp=#2
+ \pgfplotsarray@@edef{#1@size}{\the\c@pgfplotsarray@tmp}%
}
\def\pgfplotsarrayresizeglobal#1#2{%
- \expandafter\xdef\csname\string#1@size\endcsname{#2}%
+ \c@pgfplotsarray@tmp=#2
+ \expandafter\xdef\csname\string#1@size\endcsname{\the\c@pgfplotsarray@tmp}%
}
% Invokes code '#2' if the array named '#1' exists and '#3' if it does
@@ -136,7 +138,7 @@
\def\pgfplotsarray@@let#1=#2{%
\def\pgfplotsarray@TMP@@{\expandafter\let\csname\string#1\endcsname}%
- \expandafter\pgfplotsarray@TMP@@\expandafter=\csname\string#2\endcsname
+ \expandafter\pgfplotsarray@TMP@@\csname\string#2\endcsname
}%
\def\pgfplotsarray@@#1#2{%
@@ -178,6 +180,12 @@
\advance\c@pgfplotsarray@tmp by1
\pgfplotsarray@@edef{#2@size}{\the\c@pgfplotsarray@tmp}%
}
+\long\def\pgfplotsarraypushbackglobal#1\to#2{%
+ \pgfplotsarraysize{#2}\to\c@pgfplotsarray@tmp
+ \pgfplotsarray@@\gdef{#2@\the\c@pgfplotsarray@tmp}{#1}%
+ \advance\c@pgfplotsarray@tmp by1
+ \pgfplotsarray@@\xdef{#2@size}{\the\c@pgfplotsarray@tmp}%
+}
\long\def\pgfplotsarraypushbackglobal#1\to#2{%
\pgfplotsarraysize{#2}\to\c@pgfplotsarray@tmp
@@ -245,6 +253,23 @@
\expandafter\global\expandafter\let\csname\string#2@\the\c@pgfplotsarray@tmp\endcsname=#3\relax
}
+% Defines \pgfplotsretval to be a text-representation of the array.
+% It will contain \t to separate cells.
+%
+\def\pgfplotsarraytotext#1{%
+ \begingroup
+ \pgfplotsapplistXnewempty\pgfplotsretval@
+ \pgfplotsarrayforeachungrouped#1\as\entry{%
+ \pgfmathfloatparsenumber\entry
+ \pgfmathfloattosci\pgfmathresult
+ \edef\entry{\pgfmathresult\noexpand\t}%
+ \expandafter\pgfplotsapplistXpushback\entry\to\pgfplotsretval@
+ }%
+ \pgfplotsapplistXlet\pgfplotsretval=\pgfplotsretval@
+ \pgfmath@smuggleone\pgfplotsretval
+ \endgroup
+}
+
% Sets the boolean \ifpgfplotsarrayempty depending on whether array #1 is empty
% or not.
% Example:
@@ -296,11 +321,19 @@
\pgfplotsarray@@getsizeto{#1}{\pgfplotsarray@TMP}%
\c@pgfplotsarray@tmp=0\relax
\def\pgfplotsarrayforeachindex{\the\c@pgfplotsarray@tmp}%
- \long\def\pgfplotsarray@TMPb{#3}%
\pgfutil@loop
\ifnum\c@pgfplotsarray@tmp<\pgfplotsarray@TMP\relax
\expandafter\let\expandafter#2\expandafter=\csname\string#1@\the\c@pgfplotsarray@tmp\endcsname%
- \pgfplotsarray@TMPb
+ \begingroup
+ \toks0={#3}%
+ \xdef\pgfplotsarray@glob@TMP{%
+ \the\toks0 %
+ % restore loop state:
+ \c@pgfplotsarray@tmp=\the\c@pgfplotsarray@tmp\space
+ \noexpand\def\noexpand\pgfplotsarray@TMP{\pgfplotsarray@TMP}%
+ }%
+ \endgroup
+ \pgfplotsarray@glob@TMP
\advance\c@pgfplotsarray@tmp by1
\pgfutil@repeat
\let\pgfplotsarrayforeachindex=\relax%
@@ -417,6 +450,9 @@
% [\pgfplotsarrayforeach\testarray\as\elem{\elem\space}]
%
%--------------------------------------------------
+%
+% @see \pgfplotsutilsortthree
+% @see \pgfplotsutilsortfour
\def\pgfplotsarraysort{%
\pgfutil@ifnextchar[{\pgfplotsarraysort@opt}{\pgfplotsarraysort@opt[]}%
}%
@@ -570,3 +606,64 @@
\pgfplotsarray@mergesort{#1}{#2}{#3}%
\pgfplotsarray@mergesort{#1}{#4}{#5}%
}
+
+
+% A simple, ungrouped insert sort algorithm for small arrays.
+%
+% for i := 1; i < N; ++i do
+% begin
+% value := A[i];
+% j := i - 1;
+% done := false;
+% repeat
+% if A[j] > value then
+% begin
+% A[j + 1] := A[j];
+% j := j - 1;
+% if j < 0 then
+% done := true;
+% end
+% else
+% done := true;
+% until done;
+% A[j + 1] := value;
+% end;
+\def\pgfplotsarrayinsertionsort#1{%
+ \pgfkeysgetvalue{/pgfplots/iflessthan/.@cmd}\pgfplotsarraysort@iflt
+ \pgfplotsarraysizetomacro#1\to\pgfplotsarrayinsertionsort@N
+ \c@pgf@countd=1
+ \pgfplotsarrayinsertionsort@{#1}%
+}%
+\def\pgfplotsarrayinsertionsort@#1{%
+ \ifnum\c@pgf@countd<\pgfplotsarrayinsertionsort@N\relax
+ \pgfplotsarrayselect\c@pgf@countd\of#1\to\pgfplotsarrayinsertionsort@v
+ %
+ \c@pgf@countb=\c@pgf@countd
+ \advance\c@pgf@countb by-1
+ %
+ \pgfplotsarrayinsertionsort@@{#1}%
+ \advance\c@pgf@countb by1
+ \pgfplotsarrayletentry\c@pgf@countb\of#1=\pgfplotsarrayinsertionsort@v
+ %
+ \advance\c@pgf@countd by1
+ \expandafter\pgfplotsarrayinsertionsort@\expandafter#1%
+ \fi
+}
+\def\pgfplotsarrayinsertionsort@@#1{%
+ \pgfplotsarrayselect\c@pgf@countb\of#1\to\pgfplotsarrayinsertionsort@j
+ \pgfplotsarraysort@iflt{\pgfplotsarrayinsertionsort@v}{\pgfplotsarrayinsertionsort@j}
+ {%
+ \advance\c@pgf@countb by1
+ \pgfplotsarrayletentry\c@pgf@countb\of#1=\pgfplotsarrayinsertionsort@j
+ \advance\c@pgf@countb by-2
+ \ifnum\c@pgf@countb<0
+ \let\pgfplotsarrayinsertionsort@@next\relax%
+ \else
+ \def\pgfplotsarrayinsertionsort@@next{\pgfplotsarrayinsertionsort@@#1}%
+ \fi
+ }{%
+ \let\pgfplotsarrayinsertionsort@@next\relax%
+ }\pgfeov%
+ \pgfplotsarrayinsertionsort@@next
+}%
+