为哈希表添加输入节点

为哈希表添加输入节点

[初学者]

我想绘制一个哈希表,其中有一个哈希函数节点,该节点接受多个文档并写入哈希表。当前的 Latex 代码创建了哈希表,但我不确定如何添加指向表的节点并具有多个输入。以下是当前输出和代码(图像显示所需的输出)

先感谢您!

\begin{tikzpicture}
    \coordinate (0);
    \foreach \t/\n[count=\i from 0,evaluate=\i as\j using int(\i+1)] in {
        $d_{3} \rightarrow d_{16}$/ 000 ,
        $d_{5} \rightarrow d_{23} \rightarrow d_{74} \rightarrow d_{101} \rightarrow d_{105}$/001  ,
        /010  ,
        $d_{1} \rightarrow d_{7}$/ 011,
        /100  ,
        $d_{93}$/101 ,
        $d_{46} \rightarrow d_{63} \rightarrow d_{89}$/110 ,
        $d_{10} \rightarrow d_{28} \rightarrow d_{35} \rightarrow d_{110}$/111
    }
    \node at(\i.south)[anchor=north,draw,minimum height=2em,minimum width=2.5em,outer sep=0pt](\j){\n}
    node at(\j.west)[align=right,left]{\i} 
    node at(\j.east)[align=left,right,xshift=-.7em]{$\rightarrow$ \t};
    \end{tikzpicture}

在此处输入图片描述

期望输出: 在此处输入图片描述

答案1

下面的建议使用calc库来计算一些坐标。此外,我使用该arrows库来计算箭头尖。我向环境stealth'添加了选项以更改箭头尖并确保线条从节点和坐标的距离处开始和结束。添加部分的代码:[>=stealth',shorten <=1mm,shorten >=1mm]tikzpicture1mm

    \coordinate (cntr) at ($0.5*(4.west)+0.5*(5.west)$);
    \node[draw](f)at($(cntr)+(-2,0)$){$f()$};
    \draw[->] (f) -- (cntr);
    
    \foreach \i/\y/\in in {1/1.5/150,2/1/160,3/0.5/170,4/0/180,n/-1.5/-150} {
      \node (d\i) at ($(f)+(-3,\y)$) {$d_\i$};
      \draw[->] (d\i) to[out=0,in=\in] (f);
    }
    \draw[dotted,thick] (d4) -- (dn);
    \draw[dotted,thick] (f) ++(-1.7,-0.1) -- +(0,-0.95);

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}
\begin{document}

\begin{tikzpicture}[>=stealth',shorten <=1mm,shorten >=1mm]
    \coordinate (0);
    \foreach \t/\n[count=\i from 0,evaluate=\i as\j using int(\i+1)] in {
        $d_{3} \rightarrow d_{16}$/ 000 ,
        $d_{5} \rightarrow d_{23} \rightarrow d_{74} \rightarrow d_{101} \rightarrow d_{105}$/001  ,
        /010  ,
        $d_{1} \rightarrow d_{7}$/ 011,
        /100  ,
        $d_{93}$/101 ,
        $d_{46} \rightarrow d_{63} \rightarrow d_{89}$/110 ,
        $d_{10} \rightarrow d_{28} \rightarrow d_{35} \rightarrow d_{110}$/111
    }
    \node at(\i.south)[anchor=north,draw,minimum height=2em,minimum width=2.5em,outer sep=0pt](\j){\n}
    node at(\j.west)[align=right,left]{\i} 
    node at(\j.east)[align=left,right,xshift=-.7em]{$\rightarrow$ \t};

    \coordinate (cntr) at ($0.5*(4.west)+0.5*(5.west)$);
    \node[draw](f)at($(cntr)+(-2,0)$){$f()$};
    \draw[->] (f) -- (cntr);
    
    \foreach \i/\y/\in in {1/1.5/150,2/1/160,3/0.5/170,4/0/180,n/-1.5/-150} {
      \node (d\i) at ($(f)+(-3,\y)$) {$d_\i$};
      \draw[->] (d\i) to[out=0,in=\in] (f);
    }
    \draw[dotted,thick] (d4) -- (dn);
    \draw[dotted,thick] (f) ++(-1.7,-0.1) -- +(0,-0.95);
  \end{tikzpicture}

\end{document}

相关内容