1

I would like to visualize a hash table that maps integers onto arrays of integers. I have found visualizations for both arrays and hashtables, but none of the hashtables had arrays as values.

What I need is a combination of this post on arrays and this post on hashtables. So the result would look something like this:

enter image description here

2 Answers2

4

enter image description here

By using TikZ libraries matrix for nodes and arrows.meta for arrows:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                matrix,
                positioning}
\tikzset{
          }
\begin{document}
    \begin{tikzpicture}[
every edge/.style = {draw=gray, semithick, -Straight Barb},
 hashtable/.style = {matrix of nodes,
                     nodes in empty cells,
                     nodes = {draw, minimum size=8mm, anchor=center,
                              inner sep=0pt, outer sep=0pt},
                     column sep=-\pgflinewidth,
                     row sep=-\pgflinewidth},
                        ]
\matrix (m1) [hashtable]
{   
    \\  \\  \\
};
%
\matrix (m2) [hashtable, right=of m1]
{   
    &   &   \\
    &   &   \\
    &   &   \\
};
%
\draw   (m1-1-1) edge (m2-1-1) 
        (m1-2-1) edge (m2-2-1)
        (m1-3-1) edge (m2-3-1);
    \end{tikzpicture}
\end{document}
Zarko
  • 296,517
0

That can be simply drawn with TikZ (see the first code). The second code is just for a comparison with Asymptote.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usepackage{asymptote}
\begin{document}
\begin{tikzpicture}
\draw 
(0,0) grid (1,3)
(1,.5) coordinate (A1)
(1,1.5) coordinate (A2)
(1,2.5) coordinate (A3);
\draw[shift={(2.5,0)}] 
(0,0) grid (3,3)
(0,.5) coordinate (B1)
(0,1.5) coordinate (B2)
(0,2.5) coordinate (B3);
\foreach \i in {1,2,3}
\draw[->,shorten >=1mm,shorten <=1mm] (A\i)--(B\i);
\end{tikzpicture}
\hspace{1cm}

\begin{asy} unitsize(1cm); import geometry; pair[] A={(1,.5),(1,1.5),(1,2.5)}; add(grid(1,3,red));

transform t=shift(2.5,0); pair[] B={(0,.5),(0,1.5),(0,2.5)}; add(t*grid(3,3,blue));

for(int i=0; i<A.length;++i){ pair p=relpoint(A[i]--tB[i],.1); pair q=relpoint(A[i]--tB[i],.9); draw(p--q,Arrow(TeXHead)); } \end{asy} \end{document}

Black Mild
  • 17,569