src/Pure/General/table.ML
author wenzelm
Thu, 02 Jun 2005 18:29:52 +0200
changeset 16192 733267a60e32
parent 16139 21ce46ca61cc
child 16342 b146c31a2955
permissions -rw-r--r--
exists: made non-strict; added forall;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6118
caa439435666 fixed titles;
wenzelm
parents: 5681
diff changeset
     1
(*  Title:      Pure/General/table.ML
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
     3
    Author:     Markus Wenzel and Stefan Berghofer, TU Muenchen
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
     4
8806
wenzelm
parents: 8606
diff changeset
     5
Generic tables and tables indexed by strings.  Efficient purely
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
     6
functional implementation using balanced 2-3 trees.
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
     7
*)
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
     8
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
     9
signature KEY =
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    10
sig
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    11
  type key
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    12
  val ord: key * key -> order
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    13
end;
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    14
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    15
signature TABLE =
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    16
sig
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    17
  type key
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    18
  type 'a table
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    19
  exception DUP of key
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    20
  exception DUPS of key list
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
    21
  exception UNDEF of key
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    22
  val empty: 'a table
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    23
  val is_empty: 'a table -> bool
5681
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    24
  val map: ('a -> 'b) -> 'a table -> 'b table
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    25
  val foldl: ('a * (key * 'b) -> 'a) -> 'a * 'b table -> 'a
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    26
  val dest: 'a table -> (key * 'a) list
5681
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    27
  val keys: 'a table -> key list
8409
ef01ee11b14e Added function min_key.
berghofe
parents: 7061
diff changeset
    28
  val min_key: 'a table -> key option
15160
394fb9b8908b changes
obua
parents: 15014
diff changeset
    29
  val max_key: 'a table -> key option
7061
69d42b56151f added exists;
wenzelm
parents: 6118
diff changeset
    30
  val exists: (key * 'a -> bool) -> 'a table -> bool
16192
733267a60e32 exists: made non-strict;
wenzelm
parents: 16139
diff changeset
    31
  val forall: (key * 'a -> bool) -> 'a table -> bool
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    32
  val lookup: 'a table * key -> 'a option
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    33
  val update: (key * 'a) * 'a table -> 'a table
12287
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
    34
  val update_new: (key * 'a) * 'a table -> 'a table                    (*exception DUP*)
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
    35
  val map_entry: key -> ('a -> 'a) -> 'a table -> 'a table
12287
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
    36
  val make: (key * 'a) list -> 'a table                                (*exception DUPS*)
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
    37
  val extend: 'a table * (key * 'a) list -> 'a table                   (*exception DUPS*)
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
    38
  val join: ('a * 'a -> 'a option) -> 'a table * 'a table -> 'a table  (*exception DUPS*)
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
    39
  val merge: ('a * 'a -> bool) -> 'a table * 'a table -> 'a table      (*exception DUPS*)
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
    40
  val delete: key -> 'a table -> 'a table                              (*exception UNDEF*)
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
    41
  val delete_safe: key -> 'a table -> 'a table
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
    42
  val insert: ('a * 'a -> bool) -> key * 'a -> 'a table -> 'a table    (*exception DUP*)
16139
21ce46ca61cc remove(_multi): generalized type;
wenzelm
parents: 16002
diff changeset
    43
  val remove: ('b * 'a -> bool) -> key * 'b -> 'a table -> 'a table
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    44
  val lookup_multi: 'a list table * key -> 'a list
8606
80992b8566e5 export update_multi;
wenzelm
parents: 8409
diff changeset
    45
  val update_multi: (key * 'a) * 'a list table -> 'a list table
16139
21ce46ca61cc remove(_multi): generalized type;
wenzelm
parents: 16002
diff changeset
    46
  val remove_multi: ('b * 'a -> bool) -> key * 'b -> 'a list table -> 'a list table
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    47
  val make_multi: (key * 'a) list -> 'a list table
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    48
  val dest_multi: 'a list table -> (key * 'a) list
12287
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
    49
  val merge_multi: ('a * 'a -> bool) ->
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
    50
    'a list table * 'a list table -> 'a list table                     (*exception DUPS*)
12287
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
    51
  val merge_multi': ('a * 'a -> bool) ->
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
    52
    'a list table * 'a list table -> 'a list table                     (*exception DUPS*)
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    53
end;
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    54
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    55
functor TableFun(Key: KEY): TABLE =
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    56
struct
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    57
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    58
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    59
(* datatype table *)
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    60
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    61
type key = Key.key;
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    62
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    63
datatype 'a table =
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    64
  Empty |
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    65
  Branch2 of 'a table * (key * 'a) * 'a table |
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    66
  Branch3 of 'a table * (key * 'a) * 'a table * (key * 'a) * 'a table;
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    67
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    68
exception DUP of key;
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    69
exception DUPS of key list;
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    70
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    71
5681
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    72
(* empty *)
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    73
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    74
val empty = Empty;
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    75
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    76
fun is_empty Empty = true
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    77
  | is_empty _ = false;
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
    78
5681
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    79
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    80
(* map and fold combinators *)
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    81
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    82
fun map_table _ Empty = Empty
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    83
  | map_table f (Branch2 (left, (k, x), right)) =
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    84
      Branch2 (map_table f left, (k, f x), map_table f right)
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    85
  | map_table f (Branch3 (left, (k1, x1), mid, (k2, x2), right)) =
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    86
      Branch3 (map_table f left, (k1, f x1), map_table f mid, (k2, f x2), map_table f right);
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    87
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    88
fun foldl_table _ (x, Empty) = x
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    89
  | foldl_table f (x, Branch2 (left, p, right)) =
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    90
      foldl_table f (f (foldl_table f (x, left), p), right)
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    91
  | foldl_table f (x, Branch3 (left, p1, mid, p2, right)) =
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    92
      foldl_table f (f (foldl_table f (f (foldl_table f (x, left), p1), mid), p2), right);
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    93
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    94
fun dest tab = rev (foldl_table (fn (rev_ps, p) => p :: rev_ps) ([], tab));
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
    95
fun keys tab = rev (foldl_table (fn (rev_ks, (k, _)) => k :: rev_ks) ([], tab));
16192
733267a60e32 exists: made non-strict;
wenzelm
parents: 16139
diff changeset
    96
733267a60e32 exists: made non-strict;
wenzelm
parents: 16139
diff changeset
    97
local exception TRUE in
733267a60e32 exists: made non-strict;
wenzelm
parents: 16139
diff changeset
    98
733267a60e32 exists: made non-strict;
wenzelm
parents: 16139
diff changeset
    99
fun exists pred tab =
733267a60e32 exists: made non-strict;
wenzelm
parents: 16139
diff changeset
   100
  (foldl_table (fn ((), e) => if pred e then raise TRUE else ()) ((), tab); false)
733267a60e32 exists: made non-strict;
wenzelm
parents: 16139
diff changeset
   101
    handle TRUE => true;
733267a60e32 exists: made non-strict;
wenzelm
parents: 16139
diff changeset
   102
733267a60e32 exists: made non-strict;
wenzelm
parents: 16139
diff changeset
   103
fun forall pred = not o exists (not o pred);
733267a60e32 exists: made non-strict;
wenzelm
parents: 16139
diff changeset
   104
733267a60e32 exists: made non-strict;
wenzelm
parents: 16139
diff changeset
   105
end;
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   106
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   107
fun min_key Empty = NONE
16002
wenzelm
parents: 15761
diff changeset
   108
  | min_key (Branch2 (left, (k, _), _)) = SOME (if_none (min_key left) k)
wenzelm
parents: 15761
diff changeset
   109
  | min_key (Branch3 (left, (k, _), _, _, _)) = SOME (if_none (min_key left) k);
8409
ef01ee11b14e Added function min_key.
berghofe
parents: 7061
diff changeset
   110
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   111
fun max_key Empty = NONE
16002
wenzelm
parents: 15761
diff changeset
   112
  | max_key (Branch2 (_, (k, _), right)) = SOME (if_none (max_key right) k)
wenzelm
parents: 15761
diff changeset
   113
  | max_key (Branch3 (_, _, _, (k,_), right)) = SOME (if_none (max_key right) k);
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   114
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   115
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   116
(* lookup *)
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   117
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   118
fun lookup (Empty, _) = NONE
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   119
  | lookup (Branch2 (left, (k, x), right), key) =
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   120
      (case Key.ord (key, k) of
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   121
        LESS => lookup (left, key)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   122
      | EQUAL => SOME x
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   123
      | GREATER => lookup (right, key))
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   124
  | lookup (Branch3 (left, (k1, x1), mid, (k2, x2), right), key) =
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   125
      (case Key.ord (key, k1) of
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   126
        LESS => lookup (left, key)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   127
      | EQUAL => SOME x1
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   128
      | GREATER =>
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   129
          (case Key.ord (key, k2) of
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   130
            LESS => lookup (mid, key)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   131
          | EQUAL => SOME x2
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   132
          | GREATER => lookup (right, key)));
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   133
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   134
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   135
(* updates *)
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   136
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   137
datatype 'a growth =
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   138
  Stay of 'a table |
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   139
  Sprout of 'a table * (key * 'a) * 'a table;
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   140
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   141
exception SAME;
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   142
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   143
fun modify key f tab =
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   144
  let
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   145
    fun modfy Empty = Sprout (Empty, (key, f NONE), Empty)
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   146
      | modfy (Branch2 (left, p as (k, x), right)) =
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   147
          (case Key.ord (key, k) of
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   148
            LESS =>
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   149
              (case modfy left of
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   150
                Stay left' => Stay (Branch2 (left', p, right))
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   151
              | Sprout (left1, q, left2) => Stay (Branch3 (left1, q, left2, p, right)))
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   152
          | EQUAL => Stay (Branch2 (left, (k, f (SOME x)), right))
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   153
          | GREATER =>
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   154
              (case modfy right of
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   155
                Stay right' => Stay (Branch2 (left, p, right'))
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   156
              | Sprout (right1, q, right2) =>
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   157
                  Stay (Branch3 (left, p, right1, q, right2))))
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   158
      | modfy (Branch3 (left, p1 as (k1, x1), mid, p2 as (k2, x2), right)) =
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   159
          (case Key.ord (key, k1) of
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   160
            LESS =>
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   161
              (case modfy left of
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   162
                Stay left' => Stay (Branch3 (left', p1, mid, p2, right))
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   163
              | Sprout (left1, q, left2) =>
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   164
                  Sprout (Branch2 (left1, q, left2), p1, Branch2 (mid, p2, right)))
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   165
          | EQUAL => Stay (Branch3 (left, (k1, f (SOME x1)), mid, p2, right))
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   166
          | GREATER =>
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   167
              (case Key.ord (key, k2) of
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   168
                LESS =>
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   169
                  (case modfy mid of
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   170
                    Stay mid' => Stay (Branch3 (left, p1, mid', p2, right))
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   171
                  | Sprout (mid1, q, mid2) =>
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   172
                      Sprout (Branch2 (left, p1, mid1), q, Branch2 (mid2, p2, right)))
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   173
              | EQUAL => Stay (Branch3 (left, p1, mid, (k2, f (SOME x2)), right))
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   174
              | GREATER =>
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   175
                  (case modfy right of
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   176
                    Stay right' => Stay (Branch3 (left, p1, mid, p2, right'))
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   177
                  | Sprout (right1, q, right2) =>
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   178
                      Sprout (Branch2 (left, p1, mid), p2, Branch2 (right1, q, right2)))));
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   179
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   180
  in
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   181
    (case modfy tab of
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   182
      Stay tab' => tab'
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   183
    | Sprout br => Branch2 br)
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   184
    handle SAME => tab
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   185
  end;
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   186
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   187
fun update ((key, x), tab) = modify key (fn _ => x) tab;
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   188
fun update_new ((key, x), tab) = modify key (fn NONE => x | SOME _ => raise DUP key) tab;
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   189
fun map_entry key f = modify key (fn NONE => raise SAME | SOME x => f x);
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   190
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   191
12287
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   192
(* extend and make *)
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   193
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   194
fun extend (table, args) =
12287
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   195
  let
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   196
    fun add (key, x) (tab, dups) =
16002
wenzelm
parents: 15761
diff changeset
   197
      if is_some (lookup (tab, key)) then (tab, key :: dups)
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   198
      else (update ((key, x), tab), dups);
12287
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   199
  in
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   200
    (case fold add args (table, []) of
12287
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   201
      (table', []) => table'
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   202
    | (_, dups) => raise DUPS (rev dups))
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   203
  end;
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   204
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   205
fun make pairs = extend (empty, pairs);
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   206
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   207
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   208
(* delete *)
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   209
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   210
exception UNDEF of key;
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   211
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   212
local
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   213
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   214
fun compare NONE (k2, _) = LESS
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   215
  | compare (SOME k1) (k2, _) = Key.ord (k1, k2);
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   216
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   217
fun if_eq EQUAL x y = x
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   218
  | if_eq _ x y = y;
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   219
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   220
fun del (SOME k) Empty = raise UNDEF k
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   221
  | del NONE (Branch2 (Empty, p, Empty)) = (p, (true, Empty))
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   222
  | del NONE (Branch3 (Empty, p, Empty, q, Empty)) =
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   223
      (p, (false, Branch2 (Empty, q, Empty)))
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   224
  | del k (Branch2 (Empty, p, Empty)) = (case compare k p of
16002
wenzelm
parents: 15761
diff changeset
   225
      EQUAL => (p, (true, Empty)) | _ => raise UNDEF (the k))
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   226
  | del k (Branch3 (Empty, p, Empty, q, Empty)) = (case compare k p of
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   227
      EQUAL => (p, (false, Branch2 (Empty, q, Empty)))
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   228
    | _ => (case compare k q of
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   229
        EQUAL => (q, (false, Branch2 (Empty, p, Empty)))
16002
wenzelm
parents: 15761
diff changeset
   230
      | _ => raise UNDEF (the k)))
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   231
  | del k (Branch2 (l, p, r)) = (case compare k p of
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   232
      LESS => (case del k l of
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   233
        (p', (false, l')) => (p', (false, Branch2 (l', p, r)))
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   234
      | (p', (true, l')) => (p', case r of
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   235
          Branch2 (rl, rp, rr) =>
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   236
            (true, Branch3 (l', p, rl, rp, rr))
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   237
        | Branch3 (rl, rp, rm, rq, rr) => (false, Branch2
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   238
            (Branch2 (l', p, rl), rp, Branch2 (rm, rq, rr)))))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   239
    | ord => (case del (if_eq ord NONE k) r of
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   240
        (p', (false, r')) => (p', (false, Branch2 (l, if_eq ord p' p, r')))
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   241
      | (p', (true, r')) => (p', case l of
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   242
          Branch2 (ll, lp, lr) =>
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   243
            (true, Branch3 (ll, lp, lr, if_eq ord p' p, r'))
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   244
        | Branch3 (ll, lp, lm, lq, lr) => (false, Branch2
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   245
            (Branch2 (ll, lp, lm), lq, Branch2 (lr, if_eq ord p' p, r'))))))
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   246
  | del k (Branch3 (l, p, m, q, r)) = (case compare k q of
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   247
      LESS => (case compare k p of
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   248
        LESS => (case del k l of
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   249
          (p', (false, l')) => (p', (false, Branch3 (l', p, m, q, r)))
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   250
        | (p', (true, l')) => (p', (false, case (m, r) of
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   251
            (Branch2 (ml, mp, mr), Branch2 _) =>
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   252
              Branch2 (Branch3 (l', p, ml, mp, mr), q, r)
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   253
          | (Branch3 (ml, mp, mm, mq, mr), _) =>
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   254
              Branch3 (Branch2 (l', p, ml), mp, Branch2 (mm, mq, mr), q, r)
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   255
          | (Branch2 (ml, mp, mr), Branch3 (rl, rp, rm, rq, rr)) =>
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   256
              Branch3 (Branch2 (l', p, ml), mp, Branch2 (mr, q, rl), rp,
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   257
                Branch2 (rm, rq, rr)))))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   258
      | ord => (case del (if_eq ord NONE k) m of
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   259
          (p', (false, m')) =>
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   260
            (p', (false, Branch3 (l, if_eq ord p' p, m', q, r)))
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   261
        | (p', (true, m')) => (p', (false, case (l, r) of
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   262
            (Branch2 (ll, lp, lr), Branch2 _) =>
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   263
              Branch2 (Branch3 (ll, lp, lr, if_eq ord p' p, m'), q, r)
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   264
          | (Branch3 (ll, lp, lm, lq, lr), _) =>
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   265
              Branch3 (Branch2 (ll, lp, lm), lq,
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   266
                Branch2 (lr, if_eq ord p' p, m'), q, r)
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   267
          | (_, Branch3 (rl, rp, rm, rq, rr)) =>
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   268
              Branch3 (l, if_eq ord p' p, Branch2 (m', q, rl), rp,
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   269
                Branch2 (rm, rq, rr))))))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   270
    | ord => (case del (if_eq ord NONE k) r of
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   271
        (q', (false, r')) =>
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   272
          (q', (false, Branch3 (l, p, m, if_eq ord q' q, r')))
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   273
      | (q', (true, r')) => (q', (false, case (l, m) of
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   274
          (Branch2 _, Branch2 (ml, mp, mr)) =>
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   275
            Branch2 (l, p, Branch3 (ml, mp, mr, if_eq ord q' q, r'))
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   276
        | (_, Branch3 (ml, mp, mm, mq, mr)) =>
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   277
            Branch3 (l, p, Branch2 (ml, mp, mm), mq,
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   278
              Branch2 (mr, if_eq ord q' q, r'))
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   279
        | (Branch3 (ll, lp, lm, lq, lr), Branch2 (ml, mp, mr)) =>
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   280
            Branch3 (Branch2 (ll, lp, lm), lq, Branch2 (lr, p, ml), mp,
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   281
              Branch2 (mr, if_eq ord q' q, r'))))));
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   282
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   283
in
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   284
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   285
fun delete key tab = snd (snd (del (SOME key) tab));
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   286
fun delete_safe key tab = delete key tab handle UNDEF _ => tab;
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   287
15665
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   288
end;
7e7412fffc0c tuned updates, added map_entry;
wenzelm
parents: 15574
diff changeset
   289
15014
97ab70c3d955 Added delete operation.
berghofe
parents: 14981
diff changeset
   290
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   291
(* insert and remove *)
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   292
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   293
fun insert eq (key, x) =
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   294
  modify key (fn NONE => x | SOME y => if eq (x, y) then raise SAME else raise DUP key);
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   295
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   296
fun remove eq (key, x) tab =
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   297
  (case lookup (tab, key) of
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   298
    NONE => tab
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   299
  | SOME y => if eq (x, y) then delete key tab else tab);
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   300
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   301
12287
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   302
(* join and merge *)
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   303
12287
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   304
fun join f (table1, table2) =
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   305
  let
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   306
    fun add ((tab, dups), (key, x)) =
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   307
      (case lookup (tab, key) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   308
        NONE => (update ((key, x), tab), dups)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   309
      | SOME y =>
12287
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   310
          (case f (y, x) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   311
            SOME z => (update ((key, z), tab), dups)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   312
          | NONE => (tab, key :: dups)));
12287
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   313
  in
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   314
    (case foldl_table add ((table1, []), table2) of
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   315
      (table', []) => table'
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   316
    | (_, dups) => raise DUPS (rev dups))
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   317
  end;
7017cee2f3ac added join, merge_multi(');
wenzelm
parents: 8806
diff changeset
   318
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   319
fun merge eq tabs = join (fn (y, x) => if eq (y, x) then SOME y else NONE) tabs;
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   320
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   321
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   322
(* tables with multiple entries per key *)
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   323
16002
wenzelm
parents: 15761
diff changeset
   324
fun lookup_multi arg = if_none (lookup arg) [];
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   325
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   326
fun update_multi ((key, x), tab) = modify key (fn NONE => [x] | SOME xs => x :: xs) tab;
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   327
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   328
fun remove_multi eq (key, x) tab =
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   329
  map_entry key (fn xs => (case Library.remove eq x xs of [] => raise UNDEF key | ys => ys)) tab
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   330
  handle UNDEF _ => delete key tab;
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   331
15761
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   332
fun make_multi args = foldr update_multi empty args;
c9561302c74a added delete_safe, insert, remove, remove_multi;
wenzelm
parents: 15665
diff changeset
   333
fun dest_multi tab = List.concat (map (fn (key, xs) => map (pair key) xs) (dest tab));
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   334
fun merge_multi eq tabs = join (fn (xs, xs') => SOME (gen_merge_lists eq xs xs')) tabs;
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15160
diff changeset
   335
fun merge_multi' eq tabs = join (fn (xs, xs') => SOME (gen_merge_lists' eq xs xs')) tabs;
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   336
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   337
5681
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
   338
(*final declarations of this structure!*)
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
   339
val map = map_table;
464913c6086a added foldl, keys;
wenzelm
parents: 5015
diff changeset
   340
val foldl = foldl_table;
5015
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   341
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   342
end;
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   343
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   344
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   345
(*tables indexed by strings*)
44fd9e09c637 moved table.ML to General/table.ML;
wenzelm
parents:
diff changeset
   346
structure Symtab = TableFun(type key = string val ord = string_ord);