-
Notifications
You must be signed in to change notification settings - Fork 0
/
key.tex
378 lines (237 loc) · 8.21 KB
/
key.tex
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
\documentclass[11pt]{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{fullpage}
\usepackage{url}
\usepackage{ocamldoc}
\begin{document}
\tableofcontents
\section{Module {\tt{Key}} : Implementation of a triply-linked list, an extension of a doubly linked
list.}
\label{module:Key}\index{Key@\verb`Key`}
A node in a triply linked list serves one of three purposes:
\begin{itemize}
\item {\tt{DictEnd}} - the end of the list
\item {\tt{Bridge}} - a linked list node. A {\tt{Bridge}} node represents a key in
common between one or several lists, and the lists are maintained as
a map from dictionary id to link.
\end{itemize}
For now, the types of {\tt{dict\_id\_t}} and {\tt{val\_t}} have been hardcoded into
the system, but later they could be modularized using a functor.
\ocamldocvspace{0.5cm}
\label{type:Key.dict-underscoreid-underscoret}\begin{ocamldoccode}
type dict_id_t = string
\end{ocamldoccode}
\index{dict-underscoreid-underscoret@\verb`dict_id_t`}
\begin{ocamldocdescription}
The type of the identifier for the dictionary.
\end{ocamldocdescription}
\label{type:Key.val-underscoret}\begin{ocamldoccode}
type val_t = string
\end{ocamldoccode}
\index{val-underscoret@\verb`val_t`}
\begin{ocamldocdescription}
The type of the value of nodes in the list.
\end{ocamldocdescription}
\begin{ocamldoccode}
{\tt{module }}{\tt{StringMap}}{\tt{ : }}\end{ocamldoccode}
\label{module:Key.StringMap}\index{StringMap@\verb`StringMap`}
{\tt{Map.Make}}{\tt{(}}\begin{ocamldocsigend}
\label{type:Key.StringMap.t}\begin{ocamldoccode}
type t = Key.dict_id_t
\end{ocamldoccode}
\index{t@\verb`t`}
\label{val:Key.StringMap.compare}\begin{ocamldoccode}
val compare : {\textquotesingle}a -> {\textquotesingle}a -> int
\end{ocamldoccode}
\index{compare@\verb`compare`}
\end{ocamldocsigend}
{\tt{)}}
\begin{ocamldocdescription}
Internal module to maintain owner set.
\end{ocamldocdescription}
\begin{ocamldoccode}
{\tt{module }}{\tt{StringSet}}{\tt{ : }}\end{ocamldoccode}
\label{module:Key.StringSet}\index{StringSet@\verb`StringSet`}
{\tt{Set.Make}}{\tt{(}}\begin{ocamldocsigend}
\label{type:Key.StringSet.t}\begin{ocamldoccode}
type t = Key.dict_id_t
\end{ocamldoccode}
\index{t@\verb`t`}
\label{val:Key.StringSet.compare}\begin{ocamldoccode}
val compare : {\textquotesingle}a -> {\textquotesingle}a -> int
\end{ocamldoccode}
\index{compare@\verb`compare`}
\end{ocamldocsigend}
{\tt{)}}
\begin{ocamldocdescription}
Internal module to maintain link map.
\end{ocamldocdescription}
\label{type:Key.t}\begin{ocamldoccode}
type t =
| DictEnd
\end{ocamldoccode}
\begin{ocamldoccomment}
Indicates the end of the list.
\end{ocamldoccomment}
\begin{ocamldoccode}
| Bridge of bridge_t
\end{ocamldoccode}
\begin{ocamldoccomment}
Indicates a bridge node between
one or several lists.
\end{ocamldoccomment}
\index{t@\verb`t`}
\begin{ocamldocdescription}
The basic key type.
\end{ocamldocdescription}
\label{type:Key.link-underscoret}\begin{ocamldoccode}
type link_t = {\char123}
mutable next : t ;
\end{ocamldoccode}
\begin{ocamldoccomment}
The next key in the list
\end{ocamldoccomment}
\begin{ocamldoccode}
mutable prev : t ;
\end{ocamldoccode}
\begin{ocamldoccomment}
The previous key in the list
\end{ocamldoccomment}
\begin{ocamldoccode}
{\char125}
\end{ocamldoccode}
\index{link-underscoret@\verb`link_t`}
\begin{ocamldocdescription}
{\tt{link\_t}} represents a link to keys before and after the current item.
It is used in the {\tt{Bridge}} node inside a map.
\end{ocamldocdescription}
\label{type:Key.bridge-underscoret}\begin{ocamldoccode}
type bridge_t = {\char123}
bvalue : val_t ;
\end{ocamldoccode}
\begin{ocamldoccomment}
The value of the {\tt{Bridge}} node.
\end{ocamldoccomment}
\begin{ocamldoccode}
owners : StringSet.t ;
\end{ocamldoccode}
\begin{ocamldoccomment}
The set of owners of the value
in this node.
\end{ocamldoccomment}
\begin{ocamldoccode}
mutable links : link_t StringMap.t ;
\end{ocamldoccode}
\begin{ocamldoccomment}
The set of
dictionaries which this node is linked to.
\end{ocamldoccomment}
\begin{ocamldoccode}
{\char125}
\end{ocamldoccode}
\index{bridge-underscoret@\verb`bridge_t`}
\begin{ocamldocdescription}
{\tt{bridge\_t}} is the type of a {\tt{Bridge}} node. A {\tt{Bridge}} node uses a
{\tt{StringMap}} to keep track of which dictionaries this node is included
in.
\end{ocamldocdescription}
\label{val:Key.empty-underscorelink}\begin{ocamldoccode}
val empty_link : unit -> link_t
\end{ocamldoccode}
\index{empty-underscorelink@\verb`empty_link`}
\begin{ocamldocdescription}
Creates an empty link.
\end{ocamldocdescription}
\label{val:Key.create}\begin{ocamldoccode}
val create : val_t -> StringMap.key -> t
\end{ocamldoccode}
\index{create@\verb`create`}
\begin{ocamldocdescription}
Creates a simple key containing {\tt{value}} for dictionary {\tt{did}}.
\end{ocamldocdescription}
\label{val:Key.belongs-underscoreto}\begin{ocamldoccode}
val belongs_to : StringSet.elt -> t -> bool
\end{ocamldoccode}
\index{belongs-underscoreto@\verb`belongs_to`}
\begin{ocamldocdescription}
Tests whether the input node belongs to {\tt{dict}}.
\end{ocamldocdescription}
\label{val:Key.add-underscorelink}\begin{ocamldoccode}
val add_link : t -> StringMap.key -> unit
\end{ocamldoccode}
\index{add-underscorelink@\verb`add_link`}
\begin{ocamldocdescription}
Adds a link to {\tt{did}} in node {\tt{key}}.
\end{ocamldocdescription}
\label{exception:Key.No-underscorelink}\begin{ocamldoccode}
exception No_link
\end{ocamldoccode}
\index{No-underscorelink@\verb`No_link`}
\begin{ocamldocdescription}
An exception that is thrown when trying to get the link of a
{\tt{DictEnd}} node.
\end{ocamldocdescription}
\label{val:Key.get-underscorelink}\begin{ocamldoccode}
val get_link : StringMap.key -> t -> link_t
\end{ocamldoccode}
\index{get-underscorelink@\verb`get_link`}
\begin{ocamldocdescription}
Returns the link for the node for dictionary {\tt{dict}}, raising {\tt{No\_link}}
if the node is a {\tt{DictEnd}}. If the node doesn't contain a link for
{\tt{dict}}, then a link is added to the node and the new link is returned.
\end{ocamldocdescription}
\label{val:Key.insert-underscoreafter}\begin{ocamldoccode}
val insert_after : t -> t -> StringMap.key -> t
\end{ocamldoccode}
\index{insert-underscoreafter@\verb`insert_after`}
\begin{ocamldocdescription}
Inserts {\tt{ins}} immediately after {\tt{key}} in dictionary {\tt{dict}},
returning the new {\tt{ins}} node.
\end{ocamldocdescription}
\label{val:Key.insert-underscorebefore}\begin{ocamldoccode}
val insert_before : t -> t -> StringMap.key -> t
\end{ocamldoccode}
\index{insert-underscorebefore@\verb`insert_before`}
\begin{ocamldocdescription}
Inserts {\tt{ins}} immediately before {\tt{key}} in dictionary {\tt{dict}},
returning the new {\tt{ins}} node.
\end{ocamldocdescription}
\label{val:Key.to-underscorelist}\begin{ocamldoccode}
val to_list : t -> StringMap.key -> val_t list
\end{ocamldoccode}
\index{to-underscorelist@\verb`to_list`}
\begin{ocamldocdescription}
Converts a triply-linked list into a regular list starting with node
{\tt{key}} and using the {\tt{dict}} link in any {\tt{Bridge}} nodes.
\end{ocamldocdescription}
\label{val:Key.prev-underscorekey}\begin{ocamldoccode}
val prev_key : t -> StringMap.key -> t
\end{ocamldoccode}
\index{prev-underscorekey@\verb`prev_key`}
\begin{ocamldocdescription}
Returns the key before {\tt{key}} in {\tt{did}}.
\end{ocamldocdescription}
\label{val:Key.next-underscorekey}\begin{ocamldoccode}
val next_key : t -> StringMap.key -> t
\end{ocamldoccode}
\index{next-underscorekey@\verb`next_key`}
\begin{ocamldocdescription}
Returns the key after {\tt{key}} in {\tt{did}}.
\end{ocamldocdescription}
\label{val:Key.is-underscorebridge}\begin{ocamldoccode}
val is_bridge : t -> bool
\end{ocamldoccode}
\index{is-underscorebridge@\verb`is_bridge`}
\begin{ocamldocdescription}
Returns true if the node is a {\tt{Bridge}}.
\end{ocamldocdescription}
\label{val:Key.value}\begin{ocamldoccode}
val value : t -> val_t
\end{ocamldoccode}
\index{value@\verb`value`}
\begin{ocamldocdescription}
Returns the value of a node, failing on DictEnd.
\end{ocamldocdescription}
\end{document}