-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexthashidx.sty
216 lines (191 loc) · 7.52 KB
/
exthashidx.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
% Simple package for drawing Extendible Hashing Indexes using TikZ. See
% https://github.com/doersino/hashing-indexes-tikz for updates and a comparable
% package for Linear Hashing Indexes.
% Layout based on visualizations used in slide set "Hash-Based Indexing" from
% http://db.inf.uni-tuebingen.de/teaching/DatenbanksystemeIISS2016.html.
% Based on weiwBTree.sty from http://www.cse.unsw.edu.au/~weiw/tools.html.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{exthashidx}
\newif\if@ehirecordpointers\@ehirecordpointersfalse
\DeclareOption{ehirecordpointers}{
\@ehirecordpointerstrue
}
\ExecuteOptions{}
\ProcessOptions\relax
\RequirePackage{tikz}
\RequirePackage{ifthen}
\usetikzlibrary{arrows,shapes,matrix}
% ------------------------------------------------------------------------------
% global style declarations
\tikzstyle{ehidirectory} = [ampersand replacement=\&, row sep=-0.6pt, column sep=-0.6pt, matrix anchor=east, column 2/.style={anchor=base west}]
\tikzstyle{ehibucket} = [ampersand replacement=\&, row sep=-0.6pt, column sep=-0.6pt, matrix anchor=west, column 1/.style={anchor=west}]
\tikzstyle{ehidepth} = [draw, semithick, fill=gray!40, minimum size=2em, font=\sffamily\bfseries]
\tikzstyle{ehiptr} = [draw, semithick, minimum height=2em, minimum width=4em]
\tikzstyle{ehival} = [draw, semithick, minimum size=2em, font=\ttfamily]
\tikzstyle{ehibin} = [minimum height=2em, font=\ttfamily]
\tikzstyle{ehilabel} = [minimum height=2em, font=\sffamily\bfseries, inner sep=0]
\tikzstyle{ehilink} = [draw, semithick, ->, >=triangle 45, shorten >=.5em]
% ------------------------------------------------------------------------------
% helper macros (almost verbatim from weiwBTree.sty)
\newcommand{\ehisuppressemptystr}[1]{% leave blank for entries in leaf nodes
\ifthenelse{\equal{#1}{}}%
{%
\relax%
}%
% Else
{%
#1%
\if@ehirecordpointers
\textsuperscript{*}
\fi
}%
}%
\providecommand{\xyshift}[3]{% help to place the nodes
\begin{scope}[xshift=#1, yshift=#2]
#3
\end{scope}%
}
% ------------------------------------------------------------------------------
% link between directory entry and bucket
% #1: directory entry
% #2: bucket
\newcommand{\exthashidxlink}[2]{
\draw[ehilink] (#1.center) -- (#2-a.west);
}
% directory with capacity = 4
% #1: identifier
% #2: depth
\newcommand{\exthashidxdirectoryfour}[2]{
\matrix[ehidirectory] (#1)
{
\& \node[ehidepth] (#1-depth) {#2}; \\
\node[ehibin] {00 \hspace*{1em}}; \& \node[ehiptr] (#1-00) {\relax}; \\
\node[ehibin] {01 \hspace*{1em}}; \& \node[ehiptr] (#1-01) {\relax}; \\
\node[ehibin] {10 \hspace*{1em}}; \& \node[ehiptr] (#1-10) {\relax}; \\
\node[ehibin] {11 \hspace*{1em}}; \& \node[ehiptr] (#1-11) {\relax}; \\
\& \node[ehilabel] (#1-label) {#1}; \\
};
}
% directory with capacity = 8
% #1: identifier
% #2: depth
\newcommand{\exthashidxdirectoryeight}[2]{
\matrix[ehidirectory] (#1)
{
\& \node[ehidepth] (#1-depth) {#2}; \\
\node[ehibin] {000 \hspace*{1em}}; \& \node[ehiptr] (#1-000) {\relax}; \\
\node[ehibin] {001 \hspace*{1em}}; \& \node[ehiptr] (#1-001) {\relax}; \\
\node[ehibin] {010 \hspace*{1em}}; \& \node[ehiptr] (#1-010) {\relax}; \\
\node[ehibin] {011 \hspace*{1em}}; \& \node[ehiptr] (#1-011) {\relax}; \\
\node[ehibin] {100 \hspace*{1em}}; \& \node[ehiptr] (#1-100) {\relax}; \\
\node[ehibin] {101 \hspace*{1em}}; \& \node[ehiptr] (#1-101) {\relax}; \\
\node[ehibin] {110 \hspace*{1em}}; \& \node[ehiptr] (#1-110) {\relax}; \\
\node[ehibin] {111 \hspace*{1em}}; \& \node[ehiptr] (#1-111) {\relax}; \\
\& \node[ehilabel] (#1-label) {#1}; \\
};
}
% directory with capacity = 16
% #1: identifier
% #2: depth
\newcommand{\exthashidxdirectorysixteen}[2]{
\matrix[ehidirectory] (#1)
{
\& \node[ehidepth] (#1-depth) {#2}; \\
\node[ehibin] {0000 \hspace*{1em}}; \& \node[ehiptr] (#1-0000) {\relax}; \\
\node[ehibin] {0001 \hspace*{1em}}; \& \node[ehiptr] (#1-0001) {\relax}; \\
\node[ehibin] {0010 \hspace*{1em}}; \& \node[ehiptr] (#1-0010) {\relax}; \\
\node[ehibin] {0011 \hspace*{1em}}; \& \node[ehiptr] (#1-0011) {\relax}; \\
\node[ehibin] {0100 \hspace*{1em}}; \& \node[ehiptr] (#1-0100) {\relax}; \\
\node[ehibin] {0101 \hspace*{1em}}; \& \node[ehiptr] (#1-0101) {\relax}; \\
\node[ehibin] {0110 \hspace*{1em}}; \& \node[ehiptr] (#1-0110) {\relax}; \\
\node[ehibin] {0111 \hspace*{1em}}; \& \node[ehiptr] (#1-0111) {\relax}; \\
\node[ehibin] {1000 \hspace*{1em}}; \& \node[ehiptr] (#1-1000) {\relax}; \\
\node[ehibin] {1001 \hspace*{1em}}; \& \node[ehiptr] (#1-1001) {\relax}; \\
\node[ehibin] {1010 \hspace*{1em}}; \& \node[ehiptr] (#1-1010) {\relax}; \\
\node[ehibin] {1011 \hspace*{1em}}; \& \node[ehiptr] (#1-1011) {\relax}; \\
\node[ehibin] {1100 \hspace*{1em}}; \& \node[ehiptr] (#1-1100) {\relax}; \\
\node[ehibin] {1101 \hspace*{1em}}; \& \node[ehiptr] (#1-1101) {\relax}; \\
\node[ehibin] {1110 \hspace*{1em}}; \& \node[ehiptr] (#1-1110) {\relax}; \\
\node[ehibin] {1111 \hspace*{1em}}; \& \node[ehiptr] (#1-1111) {\relax}; \\
\& \node[ehilabel] (#1-label) {#1}; \\
};
}
% bucket with capacity = 1
% #1: identifier
% #2: depth
% #3: value
\newcommand{\exthashidxbucketone}[3]{
\matrix[ehibucket] (#1)
{
\node[ehidepth] (#1-depth) {#2}; \\
\node[ehival] (#1-a) {\ehisuppressemptystr{#3}}; \&
\node[ehilabel] (#1-label) {\hspace*{1em} bucket #1};\\
};
}
% bucket with capacity = 2
% #1: identifier
% #2: depth
% #3-#4: values
\newcommand{\exthashidxbuckettwo}[4]{
\matrix[ehibucket] (#1)
{
\node[ehidepth] (#1-depth) {#2}; \\
\node[ehival] (#1-a) {\ehisuppressemptystr{#3}}; \&
\node[ehival] (#1-b) {\ehisuppressemptystr{#4}}; \&
\node[ehilabel] (#1-label) {\hspace*{1em} bucket #1};\\
};
}
% bucket with capacity = 3
% #1: identifier
% #2: depth
% #3-#5: values
\newcommand{\exthashidxbucketthree}[5]{
\matrix[ehibucket] (#1)
{
\node[ehidepth] (#1-depth) {#2}; \\
\node[ehival] (#1-a) {\ehisuppressemptystr{#3}}; \&
\node[ehival] (#1-b) {\ehisuppressemptystr{#4}}; \&
\node[ehival] (#1-c) {\ehisuppressemptystr{#5}}; \&
\node[ehilabel] (#1-label) {\hspace*{1em} bucket #1};\\
};
}
% bucket with capacity = 4
% #1: identifier
% #2: depth
% #3-#6: values
\newcommand{\exthashidxbucketfour}[6]{
\matrix[ehibucket] (#1)
{
\node[ehidepth] (#1-depth) {#2}; \\
\node[ehival] (#1-a) {\ehisuppressemptystr{#3}}; \&
\node[ehival] (#1-b) {\ehisuppressemptystr{#4}}; \&
\node[ehival] (#1-c) {\ehisuppressemptystr{#5}}; \&
\node[ehival] (#1-d) {\ehisuppressemptystr{#6}}; \&
\node[ehilabel] (#1-label) {\hspace*{1em} bucket #1};\\
};
}
% ------------------------------------------------------------------------------
% example
%\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}{3}{4}{12}{20}{36}}
% % links
% \exthashidxlink{directory-000}{A}
% \exthashidxlink{directory-001}{B}
% \exthashidxlink{directory-010}{C}
% \exthashidxlink{directory-011}{D}
% \exthashidxlink{directory-100}{A2}
% \exthashidxlink{directory-101}{B}
% \exthashidxlink{directory-110}{C}
% \exthashidxlink{directory-111}{D}
% \end{tikzpicture}
% }
%\end{center}