File: hashtbloper.mli

package info (click to toggle)
missinglib 0.4.10.debian-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 504 kB
  • ctags: 329
  • sloc: ml: 1,726; sh: 233; makefile: 163
file content (59 lines) | stat: -rw-r--r-- 2,378 bytes parent folder | download | duplicates (2)
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
(* arch-tag: Hash table operators interface
Copyright (C) 2004 John Goerzen <jgoerzen@complete.org>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*)

(** Hash table convenience operators

These are operators to help make your work with hash tables easier.  For other
utitilies, see also the {!Hashtblutil}.

Unlike the functions in {!Hashtblutil}, all of these operators are
{b non-destructive}.  That is, they do not modify the hash tables on which
they operate, but rather return a new hash table that represents the result.
This leads to the most natural behavior for an operator. *)

(** Shorcut to get an element from a hash.  The following: {[
  hash /> 5 ]}

is the same as: {[
  Hashtbl.find hash 5 ]}

This can be combined to form more powerful constructs.  Consider this example: {[
  let sections = Hashtbl.create 5;;
  let options = Hashtbl.create 5;;
  Hashtbl.replace options "option1" "value1";;
  Hashtbl.replace sections "section1" options;;
  sections /> "section1" /> "option1";;
     returns "value1" ]} *)
val (/>): ('a, 'b) Hashtbl.t -> 'a -> 'b

(** Add (merge) two hashes.  For instance, this: {[
   hash1 /+ hash2 ]}

Returns a new hash (hash1 and hash2 are unmodified).  It will contain
all key/value pairs in either hash.  If any pairs are duplicated, the
values in hash2 take precedence. *)
val (/+): ('a, 'b) Hashtbl.t -> ('a, 'b) Hashtbl.t -> ('a, 'b) Hashtbl.t

(** Returns a new hash that has the given (key, value) pair added to the hash
passed in.  If a duplicate key is given, the new pair takes precedence.

For example: {[
  let newhash = hash // ("key", "value");; ]}

This will return a new hash that has the elements of [hash] plus one more. *)
val (//): ('a, 'b) Hashtbl.t -> 'a * 'b -> ('a, 'b) Hashtbl.t