1
\begin{center}
\scalebox{0.8}{
  \begin{tikzpicture}
    % directory
    \xyshift{+00mm}{+00mm}{\exthashidxdirectoryeight{directory}{3}}
    % buckets
    \xyshift{+20mm}{+50mm}{\exthashidxbucketfour{A}{3}{}{}{64}{16}}
    \xyshift{+20mm}{+25mm}{\exthashidxbucketfour{B}{2}{1}{5}{21}{}}
    \xyshift{+20mm}{+00mm}{\exthashidxbucketfour{C}{2}{10}{}{}{}}
    \xyshift{+20mm}{-25mm}{\exthashidxbucketfour{D}{2}{15}{7}{51}{}}
    \xyshift{+20mm}{-50mm}{\exthashidxbucketfour{A2}{4}{4}{12}{20}{36}}
     \xyshift{+20mm}{-75mm}{\exthashidxbucketfour{A3}{4}{12}{}{}{}}

    % links
    \exthashidxlink{directory-0000}{A}
    \exthashidxlink{directory-0001}{B}
    \exthashidxlink{directory-0010}{C}
    \exthashidxlink{directory-0011}{D}
    \exthashidxlink{directory-0100}{A2}
    \exthashidxlink{directory-0101}{B}
    \exthashidxlink{directory-0110}{C}
    \exthashidxlink{directory-0111}{D}
    \exthashidxlink{directory-1000}{A}
    \exthashidxlink{directory-1001}{B}
    \exthashidxlink{directory-1010}{C}
    \exthashidxlink{directory-1011}{D}
    \exthashidxlink{directory-1100}{A3}
    \exthashidxlink{directory-1101}{B}
    \exthashidxlink{directory-1110}{C}
    \exthashidxlink{directory-1111}{D}

  \end{tikzpicture}
}

\end{center}

Inspired by an answer in How do I draw Extendible Hashing/Skip List diagrams using Tikz Library?, I want to draw a graph like this. enter image description here However, my code can't compile successfully, and it says "Package pff error: No shape named directory-0000 is known" And I have no idea how to draw a graph like this. Thanks for help in advance.

1

If you want to have four binary numbers, you need to use \exthashidxdirectorysixteen instead of \exthashidxdirectoryeight.

\documentclass[12pt, a4paper]{article}
\usepackage{exthashidx}
\renewcommand{\exthashidxlink}[2]{
  \draw[ehilink] (#1.east) -- (#2-a.west);
}

\begin{document}
\begin{center}
\scalebox{0.8}{
  \begin{tikzpicture}
    % directory
    \xyshift{+00mm}{+00mm}{\exthashidxdirectorysixteen{directory}{3}}
    % buckets
    \xyshift{+20mm}{+50mm}{\exthashidxbucketfour{A}{3}{}{}{64}{16}}
    \xyshift{+20mm}{+25mm}{\exthashidxbucketfour{B}{2}{1}{5}{21}{}}
    \xyshift{+20mm}{+00mm}{\exthashidxbucketfour{C}{2}{10}{}{}{}}
    \xyshift{+20mm}{-25mm}{\exthashidxbucketfour{D}{2}{15}{7}{51}{}}
    \xyshift{+20mm}{-50mm}{\exthashidxbucketfour{A2}{4}{4}{12}{20}{36}}
     \xyshift{+20mm}{-75mm}{\exthashidxbucketfour{A3}{4}{12}{}{}{}}

    % links
    \exthashidxlink{directory-0000}{A}
    \exthashidxlink{directory-0001}{B}
    \exthashidxlink{directory-0010}{C}
    \exthashidxlink{directory-0011}{D}
    \exthashidxlink{directory-0100}{A2}
    \exthashidxlink{directory-0101}{B}
    \exthashidxlink{directory-0110}{C}
    \exthashidxlink{directory-0111}{D}
    \exthashidxlink{directory-1000}{A}
    \exthashidxlink{directory-1001}{B}
    \exthashidxlink{directory-1010}{C}
    \exthashidxlink{directory-1011}{D}
    \exthashidxlink{directory-1100}{A3}
    \exthashidxlink{directory-1101}{B}
    \exthashidxlink{directory-1110}{C}
    \exthashidxlink{directory-1111}{D}

  \end{tikzpicture}
}  
\end{center}
\end{document}

enter image description here

I also redefined \exthashidxlink. I'd also like to politely tell you not to use this package, but to use standard TikZ tools. To be honest (but please don't interpret this as an aggression) the style file is far from optimal, and sooner or later you will run into problems that cannot be resolved that easily. So I would draw this with some basic TikZ commands like this.

\documentclass[12pt, a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart,positioning}
\newcommand{\fourdigits}[1]{%
\ifnum #1<10 0%
\fi%
\ifnum #1<100 0%
\fi%
\ifnum #1<1000 0%
\fi% 
\number #1
}
\tikzset{bucket/.style={draw,rectangle split,rectangle split
horizontal,rectangle split parts=#1,text width=.5cm,anchor=west},
mybox/.style={rectangle,draw,minimum width=1.5cm,minimum height=0.5cm}}
\newcommand{\mybucketfour}[7][]{
\node[bucket=4,#1] (#2){#4
\nodepart{two}
#5
\nodepart{three}
#6
\nodepart{four}
#7
};
\node[draw,above left=0pt of #2.north west,anchor=south west,fill=gray!30,
text width=.5cm,yshift=-\pgflinewidth]{\textbf{#3}};
}
\newcommand{\Connect}[3][-latex]{\draw[#1] (#2) to[out=0,in=180] (#3);}
\begin{document}
\begin{center}
  \begin{tikzpicture}[font=\sffamily,node distance=1.5cm]
    % directory
    \begin{scope}[xshift=-4cm,yshift=2cm]   
    \foreach \X [count=\Y] in {0,...,15}
    {\pgfmathsetmacro{\Bin}{bin(\X)}
    \ifnum\X=0
    \node[mybox,label=left:{\fourdigits{\Bin}},alias=directory-\fourdigits{\Bin}] (box-\Y) {};
    \else
    \node[mybox,below=0.2cm of box-\X,label=left:{\fourdigits{\Bin}},
    alias=directory-\fourdigits{\Bin}] (box-\Y) {};
    \fi
    }
    \end{scope}
    % buckets
    \mybucketfour{A}{3}{}{}{64}{16}
    \mybucketfour[below=of A.west,anchor=west]{B}{2}{1}{5}{21}{}
    \mybucketfour[below=of B.west,anchor=west]{C}{2}{10}{}{}{}
    \mybucketfour[below=of C.west,anchor=west]{D}{2}{15}{7}{51}{}
    \mybucketfour[below=of D.west,anchor=west]{A2}{4}{4}{12}{20}{36}
    \mybucketfour[below=of A2.west,anchor=west]{A3}{4}{12}{}{}{}
    % links
    \Connect{directory-0000}{A}
    \Connect{directory-0001}{B}
    \Connect{directory-0010}{C}
    \Connect{directory-0011}{D}
    \Connect{directory-0100}{A2}
    \Connect{directory-0101}{B}
    \Connect{directory-0110}{C}
    \Connect{directory-0111}{D}
    \Connect{directory-1000}{A}
    \Connect{directory-1001}{B}
    \Connect{directory-1010}{C}
    \Connect{directory-1011}{D}
    \Connect{directory-1100}{A3}
    \Connect{directory-1101}{B}
    \Connect{directory-1110}{C}
    \Connect{directory-1111}{D}
  \end{tikzpicture}
\end{center}  
\end{document}


\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
  \begin{tikzpicture}[
      >={Stealth[scale=1.5]},
      bullet/.style={
        fill=black,
        circle,
        inner sep=1pt
      },
      projection/.style={
        ->,
        thick,
        shorten <=2pt,
        shorten >=2pt
      },
    ]

    \draw (0, 0) circle [x radius=1, y radius=1.7];
    \node [bullet, label=left:\(   a  \)] (a) at (0,1.2) {};
    \node [bullet, label=left:\(   b  \)] (b) at (0,0.4) {};
    \node [bullet, label=left:\(   c  \)] (c) at (0,-0.4) {};
    \node [bullet, label=left:\(   d  \)] (d) at (0,-1.2) {};
    \node[font=\large] (E) at (0, 2) {\(E\)};

    \begin{scope}[xshift=3.5cm]
      \draw (0, 0) circle [x radius=1, y radius=1.7]; 
      \node [bullet, label=right:\(    \tilde{a}     \)] (w) at (0,1.2) {};
      \node [bullet, label=right:\(    \tilde{b}     \)] (x) at (0,0.4) {};
      \node [bullet, label=right:\(    \tilde{c}     \)] (h) at (0,-0.4) {};
      \node [bullet, label=right:\(    \tilde{d}     \)] (v) at (0,-1.2) {};
      \node[font=\large] (F) at (0, 2) {\(F\)};
    \end{scope}

    \draw [projection] (a) -- (x);
    \draw [projection] (b) -- (h);
    \draw [projection] (c) -- (v);
    \draw [projection] (d) -- (x);
  \end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.