This file is indexed.

/usr/share/doc/libghc-hashtables-doc/html/hashtables.txt is in libghc-hashtables-doc 1.2.1.0-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Mutable hash tables in the ST monad
--   
--   This package provides a couple of different implementations of mutable
--   hash tables in the ST monad, as well as a typeclass abstracting their
--   common operations, and a set of wrappers to use the hash tables in the
--   IO monad.
--   
--   <i>QUICK START</i>: documentation for the hash table operations is
--   provided in the <a>Data.HashTable.Class</a> module, and the IO
--   wrappers (which most users will probably prefer) are located in the
--   <a>Data.HashTable.IO</a> module.
--   
--   This package currently contains three hash table implementations:
--   
--   <ol>
--   <li><a>Data.HashTable.ST.Cuckoo</a> contains an implementation of
--   "cuckoo hashing" as introduced by Pagh and Rodler in 2001 (see
--   <a>http://en.wikipedia.org/wiki/Cuckoo_hashing</a>). Cuckoo hashing
--   has worst-case <i>O(1)</i> lookups and can reach a high "load factor",
--   in which the table can perform acceptably well even when approaching
--   90% full. Randomized testing shows this implementation of cuckoo
--   hashing to be slightly faster on insert and slightly slower on lookup
--   than <a>Data.Hashtable.ST.Basic</a>, while being more space efficient
--   by about a half-word per key-value mapping. Cuckoo hashing, like the
--   basic hash table implementation using linear probing, can suffer from
--   long delays when the table is resized.</li>
--   <li><a>Data.HashTable.ST.Basic</a> contains a basic open-addressing
--   hash table using linear probing as the collision strategy. On a pure
--   speed basis it should currently be the fastest available Haskell hash
--   table implementation for lookups, although it has a higher memory
--   overhead than the other tables and can suffer from long delays when
--   the table is resized because all of the elements in the table need to
--   be rehashed.</li>
--   <li><a>Data.HashTable.ST.Linear</a> contains a linear hash table (see
--   <a>http://en.wikipedia.org/wiki/Linear_hashing</a>), which trades some
--   insert and lookup performance for higher space efficiency and much
--   shorter delays when expanding the table. In most cases, benchmarks
--   show this table to be currently slightly faster than
--   <tt>Data.HashTable</tt> from the Haskell base library.</li>
--   </ol>
--   
--   It is recommended to create a concrete type alias in your code when
--   using this package, i.e.:
--   
--   <pre>
--   import qualified Data.HashTable.IO as H
--   
--   type HashTable k v = H.BasicHashTable k v
--   
--   foo :: IO (HashTable Int Int)
--   foo = do
--       ht &lt;- H.new
--       H.insert ht 1 1
--       return ht
--   </pre>
--   
--   Firstly, this makes it easy to switch to a different hash table
--   implementation, and secondly, using a concrete type rather than
--   leaving your functions abstract in the HashTable class should allow
--   GHC to optimize away the typeclass dictionaries.
--   
--   This package accepts a couple of different cabal flags:
--   
--   <ul>
--   <li><tt>unsafe-tricks</tt>, default <i>ON</i>. If this flag is
--   enabled, we use some unsafe GHC-specific tricks to save indirections
--   (namely <tt>unsafeCoerce#</tt> and <tt>reallyUnsafePtrEquality#</tt>.
--   These techniques rely on assumptions about the behaviour of the GHC
--   runtime system and, although they've been tested and should be safe
--   under normal conditions, are slightly dangerous. Caveat emptor. In
--   particular, these techniques are incompatible with HPC code coverage
--   reports.</li>
--   <li><tt>sse42</tt>, default <i>OFF</i>. If this flag is enabled, we
--   use some SSE 4.2 instructions (see
--   <a>http://en.wikipedia.org/wiki/SSE4</a>, first available on Intel
--   Core 2 processors) to speed up cache-line searches for cuckoo
--   hashing.</li>
--   <li><tt>bounds-checking</tt>, default <i>OFF</i>. If this flag is
--   enabled, array accesses are bounds-checked.</li>
--   <li><tt>debug</tt>, default <i>OFF</i>. If turned on, we'll rudely
--   spew debug output to stdout.</li>
--   <li><tt>portable</tt>, default <i>OFF</i>. If this flag is enabled, we
--   use only pure Haskell code and try not to use unportable GHC
--   extensions. Turning this flag on forces <tt>unsafe-tricks</tt> and
--   <tt>sse42</tt> <i>OFF</i>.</li>
--   </ul>
--   
--   Please send bug reports to
--   <a>https://github.com/gregorycollins/hashtables/issues</a>.
@package hashtables
@version 1.2.1.0


-- | This module contains a <a>HashTable</a> typeclass for the hash table
--   implementations in this package. This allows you to provide functions
--   which will work for any hash table implementation in this collection.
--   
--   It is recommended to create a concrete type alias in your code when
--   using this package, i.e.:
--   
--   <pre>
--   import qualified Data.HashTable.IO as H
--   
--   type HashTable k v = H.BasicHashTable k v
--   
--   foo :: IO (HashTable Int Int)
--   foo = do
--       ht &lt;- H.new
--       H.insert ht 1 1
--       return ht
--   </pre>
--   
--   or
--   
--   <pre>
--   import qualified Data.HashTable.ST.Cuckoo as C
--   import qualified Data.HashTable.Class as H
--   
--   type HashTable s k v = C.HashTable s k v
--   
--   foo :: ST s (HashTable s k v)
--   foo = do
--       ht &lt;- H.new
--       H.insert ht 1 1
--       return ht
--   </pre>
--   
--   Firstly, this makes it easy to switch to a different hash table
--   implementation, and secondly, using a concrete type rather than
--   leaving your functions abstract in the <a>HashTable</a> class should
--   allow GHC to optimize away the typeclass dictionaries.
--   
--   Note that the functions in this typeclass are in the <a>ST</a> monad;
--   if you want hash tables in <a>IO</a>, use the convenience wrappers in
--   <a>Data.HashTable.IO</a>.
module Data.HashTable.Class

-- | A typeclass for hash tables in the <a>ST</a> monad. The operations on
--   these hash tables are typically both key- and value-strict.
class HashTable h

-- | Creates a new, default-sized hash table. <i>O(1)</i>.
new :: HashTable h => ST s (h s k v)

-- | Creates a new hash table sized to hold <tt>n</tt> elements.
--   <i>O(n)</i>.
newSized :: HashTable h => Int -> ST s (h s k v)

-- | Inserts a key/value mapping into a hash table, replacing any existing
--   mapping for that key.
--   
--   <i>O(n)</i> worst case, <i>O(1)</i> amortized.
insert :: (HashTable h, Eq k, Hashable k) => h s k v -> k -> v -> ST s ()

-- | Deletes a key-value mapping from a hash table. <i>O(n)</i> worst case,
--   <i>O(1)</i> amortized.
delete :: (HashTable h, Eq k, Hashable k) => h s k v -> k -> ST s ()

-- | Looks up a key-value mapping in a hash table. <i>O(n)</i> worst case,
--   (<i>O(1)</i> for cuckoo hash), <i>O(1)</i> amortized.
lookup :: (HashTable h, Eq k, Hashable k) => h s k v -> k -> ST s (Maybe v)

-- | A strict fold over the key-value records of a hash table in the
--   <a>ST</a> monad. <i>O(n)</i>.
foldM :: HashTable h => (a -> (k, v) -> ST s a) -> a -> h s k v -> ST s a

-- | A side-effecting map over the key-value records of a hash table.
--   <i>O(n)</i>.
mapM_ :: HashTable h => ((k, v) -> ST s b) -> h s k v -> ST s ()

-- | Computes the overhead (in words) per key-value mapping. Used for
--   debugging, etc; time complexity depends on the underlying hash table
--   implementation. <i>O(n)</i>.
computeOverhead :: HashTable h => h s k v -> ST s Double

-- | Create a hash table from a list of key-value pairs. <i>O(n)</i>.
fromList :: (HashTable h, Eq k, Hashable k) => [(k, v)] -> ST s (h s k v)

-- | Create a hash table from a list of key-value pairs, with a size hint.
--   <i>O(n)</i>.
fromListWithSizeHint :: (HashTable h, Eq k, Hashable k) => Int -> [(k, v)] -> ST s (h s k v)

-- | Given a hash table, produce a list of key-value pairs. <i>O(n)</i>.
toList :: (HashTable h) => h s k v -> ST s [(k, v)]


-- | A basic open-addressing hash table using linear probing. Use this hash
--   table if you...
--   
--   <ul>
--   <li>want the fastest possible lookups, and very fast inserts.</li>
--   <li>don't care about wasting a little bit of memory to get it.</li>
--   <li>don't care that a table resize might pause for a long time to
--   rehash all of the key-value mappings.</li>
--   <li>have a workload which is not heavy with deletes; deletes clutter
--   the table with deleted markers and force the table to be completely
--   rehashed fairly often.</li>
--   </ul>
--   
--   Of the hash tables in this collection, this hash table has the best
--   lookup performance, while maintaining competitive insert performance.
--   
--   <i>Space overhead</i>
--   
--   This table is not especially memory-efficient; firstly, the table has
--   a maximum load factor of 0.83 and will be resized if load exceeds this
--   value. Secondly, to improve insert and lookup performance, we store a
--   16-bit hash code for each key in the table.
--   
--   Each hash table entry requires at least 2.25 words (on a 64-bit
--   machine), two for the pointers to the key and value and one quarter
--   word for the hash code. We don't count key and value pointers as
--   overhead, because they have to be there -- so the overhead for a full
--   slot is at least one quarter word -- but empty slots in the hash table
--   count for a full 2.25 words of overhead. Define <tt>m</tt> as the
--   number of slots in the table, <tt>n</tt> as the number of key value
--   mappings, and <tt>ws</tt> as the machine word size in <i>bytes</i>. If
--   the load factor is <tt>k=n/m</tt>, the amount of space <i>wasted</i>
--   per mapping in words is:
--   
--   <pre>
--   w(n) = (m*(2*ws + 2) - n*(2*ws)) / ws
--   </pre>
--   
--   Since <tt>m=n/k</tt>,
--   
--   <pre>
--   w(n) = n/k * (2*ws + 2) - n*(2*ws)
--        = (n * (2 + 2*ws*(1-k)) <i> k) </i> ws
--   </pre>
--   
--   Solving for <tt>k=0.83</tt>, the maximum load factor, gives a
--   <i>minimum</i> overhead of 0.71 words per mapping on a 64-bit machine,
--   or 1.01 words per mapping on a 32-bit machine. If <tt>k=0.5</tt>,
--   which should be under normal usage the <i>maximum</i> overhead
--   situation, then the overhead would be 2.5 words per mapping on a
--   64-bit machine, or 3.0 words per mapping on a 32-bit machine.
--   
--   <i>Space overhead: experimental results</i>
--   
--   In randomized testing on a 64-bit machine (see
--   <tt>test/compute-overhead/ComputeOverhead.hs</tt> in the source
--   distribution), mean overhead (that is, the number of words needed to
--   store the key-value mapping over and above the two words necessary for
--   the key and the value pointers) is approximately 1.24 machine words
--   per key-value mapping with a standard deviation of about 0.30 words,
--   and 1.70 words per mapping at the 95th percentile.
--   
--   <i>Expensive resizes</i>
--   
--   If enough elements are inserted into the table to make it exceed the
--   maximum load factor, the table is resized. A resize involves a
--   complete rehash of all the elements in the table, which means that any
--   given call to <a>insert</a> might take <i>O(n)</i> time in the size of
--   the table, with a large constant factor. If a long pause waiting for
--   the table to resize is unacceptable for your application, you should
--   choose the included linear hash table instead.
--   
--   <i>References:</i>
--   
--   <ul>
--   <li>Knuth, Donald E. <i>The Art of Computer Programming</i>, vol. 3
--   Sorting and Searching. Addison-Wesley Publishing Company, 1973.</li>
--   </ul>
module Data.HashTable.ST.Basic

-- | An open addressing hash table using linear probing.
data HashTable s k v

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:new</a>.
new :: ST s (HashTable s k v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:newSized</a>.
newSized :: Int -> ST s (HashTable s k v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:delete</a>.
delete :: (Hashable k, Eq k) => (HashTable s k v) -> k -> ST s ()

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:lookup</a>.
lookup :: (Eq k, Hashable k) => (HashTable s k v) -> k -> ST s (Maybe v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:insert</a>.
insert :: (Eq k, Hashable k) => (HashTable s k v) -> k -> v -> ST s ()

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:mapM_</a>.
mapM_ :: ((k, v) -> ST s b) -> HashTable s k v -> ST s ()

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:foldM</a>.
foldM :: (a -> (k, v) -> ST s a) -> a -> HashTable s k v -> ST s a

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:computeOverhead</a>.
computeOverhead :: HashTable s k v -> ST s Double
instance GHC.Show.Show Data.HashTable.ST.Basic.Slot
instance Data.HashTable.Class.HashTable Data.HashTable.ST.Basic.HashTable
instance GHC.Show.Show (Data.HashTable.ST.Basic.HashTable s k v)
instance GHC.Base.Monoid Data.HashTable.ST.Basic.Slot


-- | A hash table using the cuckoo strategy. (See
--   <a>http://en.wikipedia.org/wiki/Cuckoo_hashing</a>). Use this hash
--   table if you...
--   
--   <ul>
--   <li>want the fastest possible inserts, and very fast lookups.</li>
--   <li>are conscious of memory usage; this table has less space overhead
--   than <a>Data.HashTable.ST.Basic</a> or
--   <a>Data.HashTable.ST.Linear</a>.</li>
--   <li>don't care that a table resize might pause for a long time to
--   rehash all of the key-value mappings.</li>
--   </ul>
--   
--   <i>Details:</i>
--   
--   The basic idea of cuckoo hashing, first introduced by Pagh and Rodler
--   in 2001, is to use <i>d</i> hash functions instead of only one; in
--   this implementation d=2 and the strategy we use is to split up a flat
--   array of slots into <tt>k</tt> buckets, each cache-line-sized:
--   
--   <pre>
--   +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+----------+
--   |x0|x1|x2|x3|x4|x5|x6|x7|y0|y1|y2|y3|y4|y5|y6|y7|z0|z1|z2........|
--   +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+----------+
--   [  ^^^  bucket 0  ^^^  ][  ^^^  bucket 1  ^^^  ]...
--   </pre>
--   
--   There are actually three parallel arrays: one unboxed array of
--   <a>Int</a>s for hash codes, one boxed array for keys, and one boxed
--   array for values. When looking up a key-value mapping, we hash the key
--   using two hash functions and look in both buckets in the hash code
--   array for the key. Each bucket is cache-line sized, with its keys in
--   no particular order. Because the hash code array is unboxed, we can
--   search it for the key using a highly-efficient branchless strategy in
--   C code, using SSE instructions if available.
--   
--   On insert, if both buckets are full, we knock out a randomly-selected
--   entry from one of the buckets (using a random walk ensures that "key
--   cycles" are broken with maximum probability) and try to repeat the
--   insert procedure. This process may not succeed; if all items have not
--   successfully found a home after some number of tries, we give up and
--   rehash all of the elements into a larger table.
--   
--   <i>Space overhead: experimental results</i>
--   
--   The implementation of cuckoo hash given here is almost as fast for
--   lookups as the basic open-addressing hash table using linear probing,
--   and on average is more space-efficient: in randomized testing on my
--   64-bit machine (see <tt>test/compute-overhead/ComputeOverhead.hs</tt>
--   in the source distribution), mean overhead is 0.77 machine words per
--   key-value mapping, with a standard deviation of 0.29 words, and 1.23
--   words per mapping at the 95th percentile.
--   
--   <i>References:</i>
--   
--   <ul>
--   <li>A. Pagh and F. Rodler. Cuckoo hashing. In /Proceedings of the 9th
--   Annual European Symposium on Algorithms/, pp. 121-133, 2001.</li>
--   </ul>
module Data.HashTable.ST.Cuckoo

-- | A cuckoo hash table.
data HashTable s k v

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:new</a>.
new :: ST s (HashTable s k v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:newSized</a>.
newSized :: Int -> ST s (HashTable s k v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:delete</a>.
delete :: (Hashable k, Eq k) => HashTable s k v -> k -> ST s ()

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:lookup</a>.
lookup :: (Eq k, Hashable k) => HashTable s k v -> k -> ST s (Maybe v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:insert</a>.
insert :: (Eq k, Hashable k) => HashTable s k v -> k -> v -> ST s ()

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:mapM_</a>.
mapM_ :: ((k, v) -> ST s a) -> HashTable s k v -> ST s ()

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:foldM</a>.
foldM :: (a -> (k, v) -> ST s a) -> a -> HashTable s k v -> ST s a
instance Data.HashTable.Class.HashTable Data.HashTable.ST.Cuckoo.HashTable
instance GHC.Show.Show (Data.HashTable.ST.Cuckoo.HashTable s k v)


-- | An implementation of linear hash tables. (See
--   <a>http://en.wikipedia.org/wiki/Linear_hashing</a>). Use this hash
--   table if you...
--   
--   <ul>
--   <li>don't care that inserts and lookups are slower than the other hash
--   table implementations in this collection (this one is slightly faster
--   than <tt>Data.HashTable</tt> from the base library in most cases)</li>
--   <li>have a soft real-time or interactive application for which the
--   risk of introducing a long pause on insert while all of the keys are
--   rehashed is unacceptable.</li>
--   </ul>
--   
--   <i>Details:</i>
--   
--   Linear hashing allows for the expansion of the hash table one slot at
--   a time, by moving a "split" pointer across an array of pointers to
--   buckets. The number of buckets is always a power of two, and the
--   bucket to look in is defined as:
--   
--   <pre>
--   bucket(level,key) = hash(key) mod (2^level)
--   </pre>
--   
--   The "split pointer" controls the expansion of the hash table. If the
--   hash table is at level <tt>k</tt> (i.e. <tt>2^k</tt> buckets have been
--   allocated), we first calculate <tt>b=bucket(level-1,key)</tt>. If
--   <tt>b &lt; splitptr</tt>, the destination bucket is calculated as
--   <tt>b'=bucket(level,key)</tt>, otherwise the original value <tt>b</tt>
--   is used.
--   
--   The split pointer is incremented once an insert causes some bucket to
--   become fuller than some predetermined threshold; the bucket at the
--   split pointer (*not* the bucket which triggered the split!) is then
--   rehashed, and half of its keys can be expected to be rehashed into the
--   upper half of the table.
--   
--   When the split pointer reaches the middle of the bucket array, the
--   size of the bucket array is doubled, the level increases, and the
--   split pointer is reset to zero.
--   
--   Linear hashing, although not quite as fast for inserts or lookups as
--   the implementation of linear probing included in this package, is well
--   suited for interactive applications because it has much better worst
--   case behaviour on inserts. Other hash table implementations can suffer
--   from long pauses, because it is occasionally necessary to rehash all
--   of the keys when the table grows. Linear hashing, on the other hand,
--   only ever rehashes a bounded (effectively constant) number of keys
--   when an insert forces a bucket split.
--   
--   <i>Space overhead: experimental results</i>
--   
--   In randomized testing (see
--   <tt>test/compute-overhead/ComputeOverhead.hs</tt> in the source
--   distribution), mean overhead is approximately 1.51 machine words per
--   key-value mapping with a very low standard deviation of about 0.06
--   words, 1.60 words per mapping at the 95th percentile.
--   
--   <i>Unsafe tricks</i>
--   
--   Then the <tt>unsafe-tricks</tt> flag is on when this package is built
--   (and it is on by default), we use some unsafe tricks (namely
--   <tt>unsafeCoerce#</tt> and <tt>reallyUnsafePtrEquality#</tt>) to save
--   indirections in this table. These techniques rely on assumptions about
--   the behaviour of the GHC runtime system and, although they've been
--   tested and should be safe under normal conditions, are slightly
--   dangerous. Caveat emptor. In particular, these techniques are
--   incompatible with HPC code coverage reports.
--   
--   References:
--   
--   <ul>
--   <li>W. Litwin. Linear hashing: a new tool for file and table
--   addressing. In <i>Proc. 6th International Conference on Very Large
--   Data Bases, Volume 6</i>, pp. 212-223, 1980.</li>
--   <li>P-A. Larson. Dynamic hash tables. <i>Communications of the ACM</i>
--   31: 446-457, 1988.</li>
--   </ul>
module Data.HashTable.ST.Linear

-- | A linear hash table.
data HashTable s k v

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:new</a>.
new :: ST s (HashTable s k v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:newSized</a>.
newSized :: Int -> ST s (HashTable s k v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:delete</a>.
delete :: (Hashable k, Eq k) => (HashTable s k v) -> k -> ST s ()

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:lookup</a>.
lookup :: (Eq k, Hashable k) => (HashTable s k v) -> k -> ST s (Maybe v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:insert</a>.
insert :: (Eq k, Hashable k) => (HashTable s k v) -> k -> v -> ST s ()

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:mapM_</a>.
mapM_ :: ((k, v) -> ST s b) -> HashTable s k v -> ST s ()

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:foldM</a>.
foldM :: (a -> (k, v) -> ST s a) -> a -> HashTable s k v -> ST s a

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:computeOverhead</a>.
computeOverhead :: HashTable s k v -> ST s Double
instance Data.HashTable.Class.HashTable Data.HashTable.ST.Linear.HashTable
instance GHC.Show.Show (Data.HashTable.ST.Linear.HashTable s k v)


-- | This module provides wrappers in <a>IO</a> around the functions from
--   <a>Data.HashTable.Class</a>.
--   
--   This module exports three concrete hash table types, one for each hash
--   table implementation in this package:
--   
--   <pre>
--   type BasicHashTable  k v = IOHashTable (B.HashTable)  k v
--   type CuckooHashTable k v = IOHashTable (Cu.HashTable) k v
--   type LinearHashTable k v = IOHashTable (L.HashTable)  k v
--   </pre>
--   
--   The <a>IOHashTable</a> type can be thought of as a wrapper around a
--   concrete hashtable type, which sets the <tt>ST</tt> monad state type
--   to <a>PrimState</a> <a>IO</a>, a.k.a. <tt>RealWorld</tt>:
--   
--   <pre>
--   type IOHashTable tabletype k v = tabletype (PrimState IO) k v
--   </pre>
--   
--   This module provides <a>stToIO</a> wrappers around the hashtable
--   functions (which are in <tt>ST</tt>) to make it convenient to use them
--   in <a>IO</a>. It is intended to be imported qualified and used with a
--   user-defined type alias, i.e.:
--   
--   <pre>
--   import qualified Data.HashTable.IO as H
--   
--   type HashTable k v = H.CuckooHashTable k v
--   
--   foo :: IO (HashTable Int Int)
--   foo = do
--       ht &lt;- H.new
--       H.insert ht 1 1
--       return ht
--   </pre>
--   
--   Essentially, anywhere you see <tt><a>IOHashTable</a> h k v</tt> in the
--   type signatures below, you can plug in any of
--   <tt><a>BasicHashTable</a> k v</tt>, <tt><a>CuckooHashTable</a> k
--   v</tt>, or <tt><a>LinearHashTable</a> k v</tt>.
module Data.HashTable.IO

-- | A type alias for a basic open addressing hash table using linear
--   probing. See <a>Data.HashTable.ST.Basic</a>.
type BasicHashTable k v = IOHashTable (HashTable) k v

-- | A type alias for the cuckoo hash table. See
--   <a>Data.HashTable.ST.Cuckoo</a>.
type CuckooHashTable k v = IOHashTable (HashTable) k v

-- | A type alias for the linear hash table. See
--   <a>Data.HashTable.ST.Linear</a>.
type LinearHashTable k v = IOHashTable (HashTable) k v

-- | A type alias for our hash tables, which run in <tt>ST</tt>, to set the
--   state token type to <a>PrimState</a> <a>IO</a> (aka
--   <tt>RealWorld</tt>) so that we can use them in <a>IO</a>.
type IOHashTable tabletype k v = tabletype (PrimState IO) k v

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:new</a>.
new :: HashTable h => IO (IOHashTable h k v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:newSized</a>.
newSized :: HashTable h => Int -> IO (IOHashTable h k v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:insert</a>.
insert :: (HashTable h, Eq k, Hashable k) => IOHashTable h k v -> k -> v -> IO ()

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:delete</a>.
delete :: (HashTable h, Eq k, Hashable k) => IOHashTable h k v -> k -> IO ()

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:lookup</a>.
lookup :: (HashTable h, Eq k, Hashable k) => IOHashTable h k v -> k -> IO (Maybe v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:fromList</a>.
fromList :: (HashTable h, Eq k, Hashable k) => [(k, v)] -> IO (IOHashTable h k v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:fromListWithSizeHint</a>.
fromListWithSizeHint :: (HashTable h, Eq k, Hashable k) => Int -> [(k, v)] -> IO (IOHashTable h k v)

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:toList</a>.
toList :: (HashTable h, Eq k, Hashable k) => IOHashTable h k v -> IO [(k, v)]

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:mapM_</a>.
mapM_ :: (HashTable h) => ((k, v) -> IO a) -> IOHashTable h k v -> IO ()

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:foldM</a>.
foldM :: (HashTable h) => (a -> (k, v) -> IO a) -> a -> IOHashTable h k v -> IO a

-- | See the documentation for this function in
--   <a>Data.HashTable.Class#v:computeOverhead</a>.
computeOverhead :: (HashTable h) => IOHashTable h k v -> IO Double