aboutsummaryrefslogtreecommitdiff
path: root/thesis/parts/implementation.tex
diff options
context:
space:
mode:
Diffstat (limited to 'thesis/parts/implementation.tex')
-rw-r--r--thesis/parts/implementation.tex44
1 files changed, 26 insertions, 18 deletions
diff --git a/thesis/parts/implementation.tex b/thesis/parts/implementation.tex
index bc2802c..d8997f0 100644
--- a/thesis/parts/implementation.tex
+++ b/thesis/parts/implementation.tex
@@ -80,7 +80,7 @@ We originally experimented with coefficients up to $x^3$, but found that this le
\section{Profiling}
We implement profiling using the \code{ProfilerWrapper} type (\code{src/crates/library/src/profiler.rs}), which takes as type parameters the inner container implementation and an index, used later to identify what container type the output corresponds to.
-We then implement any primrose traits that the inner container implements, counting the number of times each operation is called.
+We then implement any Primrose traits that the inner container implements, counting the number of times each operation is called.
We also check the length of the container after each insert operation, and track the maximum.
Tracking is done per-instance, and recorded when the container goes out of scope and its \code{Drop} implementation is called.
@@ -103,23 +103,31 @@ Selection is done per container type.
For each candidate implementation, we calculate its cost on each partition in the profiler output, then sum these values to get the total estimated cost for each implementation.
This is implemented in \code{src/crates/candelabra/src/profiler/info.rs} and \code{src/crates/candelabra/src/select.rs}.
-In order to try and suggest an adaptive container, we use the following algorithm:
-
-\begin{enumerate}
-\item Sort the list of partitions in order of ascending maximum n values.
-\item Calculate the cost for each candidate in each partition individually.
-\item For each partition, find the best candidate and store it in the array \code{best}. Note that we don't sum across all partitions this time.
-\item Find the lowest index \code{i} where \code{best[i] != best[0]}
-\item Check that \code{i} splits the list properly: For all \code{j < i}, we require \code{best[j] == best[0]} and for all \code{j>=i}, we require \code{best[j] == best[i]}.
-\item Let \code{before} be the name of the candidate in \code{best[0]}, \code{after} be the name of the candidate in \code{best[i]}, and \code{threshold} be halfway between the maximum n values of partition \code{i} and partition \code{i-1}.
-\item Calculate the cost of switching as:
- $$
- C_{\mathit{before,clear}}(\mathit{threshold}) + \mathit{threshold} * C_{\mathit{after,insert}}(\mathit{threshold})
- $$
-\item Calculate the cost of not switching: The sum of the difference in cost between \code{before} and \code{after} for all partitions with index \code{> i}.
-\item If the cost of not switching is less than the cost of switching, don't make a suggestion.
-\item Otherwise, suggest an adaptive container which switches from \code{before} to \code{after} when $n$ gets above \code{threshold}. Its estimated cost is the cost for \code{before} up to partition \code{i}, plus the cost of \code{after} for all other partitions, and the cost of switching.
-\end{enumerate}
+In order to try and suggest an adaptive container, we use algorithm \ref{alg:adaptive_container}.
+
+\begin{algorithm}
+ \caption{Adaptive container suggestion algorithm}
+ \label{alg:adaptive_container}
+ \begin{algorithmic}
+ \State Sort $\mathit{partitions}$ in order of ascending maximum n values.
+ \State $\mathit{costs} \gets$ the cost for each candidate in each partition.
+ \State $\mathit{best} \gets$ the best candidate per partition
+ \State $i \gets$ the lowest index where $\mathit{best}[i] \neq \mathit{best}[0]$
+ \If{exists $j < i$ where $\mathit{best}[j] \neq \mathit{best}[0]$, or exists $j\geq i$ where $\mathit{best}[j] \neq \mathit{best}[i]$}
+ \State \Return no suggestion
+ \EndIf
+ \State $\mathit{before} \gets$ name of the candidate in \code{best[0]}
+ \State $\mathit{after} \gets$ name of the candidate in \code{best[i]}
+ \State $\mathit{threshold} \gets$ halfway between the max n values of partition $i$ and $i-1$
+ \State $\mathit{switching\_cost} \gets C_{\mathit{before,clear}}(\mathit{threshold}) + \mathit{threshold} * C_{\mathit{after,insert}}(\mathit{threshold})$
+ \State $\mathit{not\_switching\_cost} \gets$ the sum of the difference in cost between $\mathit{before}$ and $\mathit{after}$ for all partitions with index $> i$.
+ \If{$\mathit{switching\_cost} > \mathit{not\_switching\_cost}$}
+ \State \Return no suggestion
+ \Else
+ \State \Return suggestion for an adaptive container which switches from $\mathit{before}$ to $\mathit{after}$ when $n$ gets above $\mathit{threshold}$. Its estimated cost is $\mathit{switching\_cost} + \sum_{k=0}^i \mathit{costs}[\mathit{before}][k] + \sum_{k=i}^{|partitions|} \mathit{costs}[\mathit{after}][k]$
+ \EndIf
+ \end{algorithmic}
+\end{algorithm}
\section{Code Generation}