#!/bin/bash -e

#export GNUTERM=sixel
export GNUTERM=png
#gnuplot -e "set term png size 1024,768; set output 'test.png'; test; set output"

f=run4
r=$f.txt
d=`date +%Y-%m-%d`
desc="$1"

title="Search Methods [Random, Integer-Keys, Win10, MS-cl, ${desc:-$r}, $d, udok]"

#cat <<EOF >x
gnuplot <<EOF
#set term png size 800,600;
#set term png size 1024,768;
set term png size 1600,1200;
set output '$f.png';
set title "$title" noenhanced;
set xlabel 'Number of Elements (32 Bytes)';
set ylabel 'Picoseconds/Search';
set logscale x;
set logscale y;
#set ytics 5;
set mxtics 10;
set mytics 10;
#set xtics nomirror;
#set ytics nomirror;

set style line 100 lt 0.5 lc rgb "#707070" lw 1.5
#set style line 100 lt 0.5 lc rgb "black" lw 1
#set style line 100 lt 1   lc rgb "gray" lw 1
set style line 101 lt 0.5 lc rgb "#C0C0C0" lw 1

set grid mytics ytics ls 100, ls 101
set grid mxtics xtics ls 100, ls 101

set grid front;
set grid;

set yrange [100:1000000];
set key left top;

# Create some linestyles for our data
# pt = point type (triangles, circles, squares, etc.)
# ps = point size
set style line 1  lt 1 lc rgb "#BB0000" lw 2 pt 7  ps 1.5
set style line 2  lt 1 lc rgb "#909090" lw 2 pt 6  ps 1.5
set style line 3  lt 1 lc rgb "#00BB00" lw 2 pt 6  ps 1.5
set style line 4  lt 1 lc rgb "#D000D0" lw 2 pt 6  ps 1.5
set style line 5  lt 1 lc rgb "#E0C040" lw 2 pt 3  ps 1.5
set style line 6  lt 1 lc rgb "#B0F0B0" lw 2 pt 3  ps 1.5
set style line 7  lt 1 lc rgb "#A000A0" lw 2 pt 3  ps 1.5
set style line 8  lt 1 lc rgb "#A0A0A0" lw 2 pt 3  ps 1.5
set style line 9  lt 1 lc rgb "#0000BB" lw 2 pt 4  ps 2.0
set style line 10 lt 1 lc rgb "#E0E000" lw 2 pt 4  ps 2.0
set style line 11 lt 1 lc rgb "#90D090" lw 2 pt 7  ps 2.0
set style line 12 lt 1 lc rgb "#E00020" lw 2 pt 7  ps 1.0
set style line 13 lt 1 lc rgb "#9090E0" lw 2 pt 7  ps 1.5
set style line 14 lt 1 lc rgb "#E0A0A0" lw 2 pt 4  ps 2.0
set style line 15 lt 1 lc rgb "#00BBAA" lw 2 pt 6  ps 1.5


#plot "$r" using 1:2 title 'Max-Collisions' with linespoints pt 7, \
#   "$r" using 1:3 title 'Mean-Collisions' with linespoints pt 7, \
#   "$r" using 1:4 title 'CPU-Cycles' with linespoints pt 7, \
#   "$r" using 1:(10*\$5) title '10*LoadFactor' with lines;

# Plot the actual data
# u 1:2 = using column 1 for X axis and column 2 for Y axis
# w lp = with linepoints, meaning put a point symbol and draw a line
# ls 1 = use our defined linestyle 1
# t "Test 1" = title "Test 1" will go in the legend
# The rest of the lines plot columns 3, 5 and 7

plot \
     "$r" using 1:(1*\$2)  with lp ls 1  t "Direct-Access", \
     "$r" using 1:12 with lp ls 2  t "RobinHood-Hash-Direct-Key" noenhanced, \
     "$r" using 1:3  with lp ls 3  t "RobinHood-Hash", \
     "$r" using 1:13 with lp ls 15 t "Daniel-Abrecht HashMap", \
     "$r" using 1:7  with lp ls 4  t "std::unordered_map" noenhanced, \
     "$r" using 1:10 with lp ls 5  t "bsearch-branchless" noenhanced, \
     "$r" using 1:9  with lp ls 6  t "bsearch-inline" noenhanced, \
     "$r" using 1:8  with lp ls 7  t "bsearch-runtime", \
     "$r" using 1:11 with lp ls 8  t "std::lower_bound" noenhanced, \
     "$r" using 1:4  with lp ls 9  t "AVL-Tree", \
     "$r" using 1:5  with lp ls 14 t "std::set", \
     "$r" using 1:6  with lp ls 10 t "std::map", \
     "$r" using 1:14 with lp ls 11 t "Linear-Search", \
     "$r" using 1:16 with lp ls 12 t "std::find", \
     "$r" using 1:15 with lp ls 13 t "Linear-Search-NoBranch";

set output
EOF
