src/Pure/General/change_table.ML
author wenzelm
Tue, 10 Dec 2024 16:37:09 +0100
changeset 81569 f8b28356ab94
parent 77976 ca11a87bd2c6
permissions -rw-r--r--
more LaTeX markup for printed entities;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/General/change_table.ML
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
     3
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
     4
Generic tables with extra bookkeeping of changes relative to some
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
     5
common base version, subject to implicit block structure.  Support for
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
     6
efficient join/merge of big global tables with small local updates.
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
     7
*)
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
     8
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
     9
signature CHANGE_TABLE =
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    10
sig
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    11
  structure Table: TABLE
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    12
  type key = Table.key
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    13
  exception DUP of key
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    14
  exception SAME
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    15
  type 'a T
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    16
  val table_of: 'a T -> 'a Table.table
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    17
  val empty: 'a T
56054
d1130b831e93 more standard internal data integrity;
wenzelm
parents: 56053
diff changeset
    18
  val is_empty: 'a T -> bool
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    19
  val change_base: bool -> 'a T -> 'a T
56139
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    20
  val change_ignore: 'a T -> 'a T
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    21
  val join: (key -> 'a * 'a -> 'a) (*exception SAME*) -> 'a T * 'a T -> 'a T  (*exception DUP*)
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    22
  val merge: ('a * 'a -> bool) -> 'a T * 'a T -> 'a T  (*exception DUP*)
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    23
  val fold: (key * 'b -> 'a -> 'a) -> 'b T -> 'a -> 'a
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    24
  val dest: 'a T -> (key * 'a) list
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    25
  val lookup_key: 'a T -> key -> (key * 'a) option
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    26
  val lookup: 'a T -> key -> 'a option
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    27
  val defined: 'a T -> key -> bool
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    28
  val update: key * 'a -> 'a T -> 'a T
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    29
  val update_new: key * 'a -> 'a T -> 'a T  (*exception DUP*)
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    30
  val map_entry: key -> ('a -> 'a) -> 'a T -> 'a T
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    31
  val map_default: key * 'a -> ('a -> 'a) -> 'a T -> 'a T
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    32
  val delete_safe: key -> 'a T -> 'a T
77976
ca11a87bd2c6 more operations;
wenzelm
parents: 77975
diff changeset
    33
  val lookup_list: 'a list T -> Table.key -> 'a list
77974
93999ffdb9dd more operations;
wenzelm
parents: 77723
diff changeset
    34
  val insert_list: ('a * 'a -> bool) -> key * 'a -> 'a list T -> 'a list T
93999ffdb9dd more operations;
wenzelm
parents: 77723
diff changeset
    35
  val remove_list: ('b * 'a -> bool) -> key * 'b -> 'a list T -> 'a list T
93999ffdb9dd more operations;
wenzelm
parents: 77723
diff changeset
    36
  val update_list: ('a * 'a -> bool) -> key * 'a -> 'a list T -> 'a list T
77975
a7ca67369755 more operations;
wenzelm
parents: 77974
diff changeset
    37
  val merge_list: ('a * 'a -> bool) -> 'a list T * 'a list T -> 'a list T
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    38
end;
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    39
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    40
functor Change_Table(Key: KEY): CHANGE_TABLE =
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    41
struct
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    42
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    43
structure Table = Table(Key);
77723
b761c91c2447 performance tuning: prefer functor Set() over Table();
wenzelm
parents: 56139
diff changeset
    44
structure Set = Set(Key);
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    45
type key = Table.key;
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    46
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    47
exception SAME = Table.SAME;
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    48
exception DUP = Table.DUP;
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    49
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    50
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    51
(* optional change *)
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    52
56139
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    53
datatype change =
77723
b761c91c2447 performance tuning: prefer functor Set() over Table();
wenzelm
parents: 56139
diff changeset
    54
  No_Change | Change of {base: serial, depth: int, changes: Set.T option};
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    55
56067
wenzelm
parents: 56054
diff changeset
    56
fun make_change base depth changes =
wenzelm
parents: 56054
diff changeset
    57
  Change {base = base, depth = depth, changes = changes};
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    58
56139
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    59
fun ignore_change (Change {base, depth, changes = SOME _}) =
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    60
      make_change base depth NONE
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    61
  | ignore_change change = change;
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    62
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    63
fun update_change key (Change {base, depth, changes = SOME ch}) =
77723
b761c91c2447 performance tuning: prefer functor Set() over Table();
wenzelm
parents: 56139
diff changeset
    64
      make_change base depth (SOME (Set.insert key ch))
56139
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    65
  | update_change _ change = change;
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    66
56067
wenzelm
parents: 56054
diff changeset
    67
fun base_change true No_Change =
77723
b761c91c2447 performance tuning: prefer functor Set() over Table();
wenzelm
parents: 56139
diff changeset
    68
      make_change (serial ()) 0 (SOME Set.empty)
56067
wenzelm
parents: 56054
diff changeset
    69
  | base_change true (Change {base, depth, changes}) =
wenzelm
parents: 56054
diff changeset
    70
      make_change base (depth + 1) changes
wenzelm
parents: 56054
diff changeset
    71
  | base_change false (Change {base, depth, changes}) =
wenzelm
parents: 56054
diff changeset
    72
      if depth = 0 then No_Change else make_change base (depth - 1) changes
56139
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    73
  | base_change false No_Change = raise Fail "Unbalanced change structure";
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    74
56139
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    75
fun cannot_merge () = raise Fail "Cannot merge: incompatible change structure";
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    76
56067
wenzelm
parents: 56054
diff changeset
    77
fun merge_change (No_Change, No_Change) = NONE
wenzelm
parents: 56054
diff changeset
    78
  | merge_change (Change change1, Change change2) =
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    79
      let
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    80
        val {base = base1, depth = depth1, changes = changes1} = change1;
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    81
        val {base = base2, depth = depth2, changes = changes2} = change2;
56139
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    82
        val _ = if base1 = base2 andalso depth1 = depth2 then () else cannot_merge ();
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    83
        val (swapped, ch2) =
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    84
          (case (changes1, changes2) of
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    85
            (_, SOME ch2) => (false, ch2)
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    86
          | (SOME ch1, _) => (true, ch1)
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    87
          | _ => cannot_merge ());
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
    88
      in SOME (swapped, ch2, make_change base1 depth1 NONE) end
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    89
  | merge_change _ = cannot_merge ();
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    90
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    91
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    92
(* table with changes *)
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    93
56067
wenzelm
parents: 56054
diff changeset
    94
datatype 'a T = Change_Table of {change: change, table: 'a Table.table};
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    95
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
    96
fun table_of (Change_Table {table, ...}) = table;
56054
d1130b831e93 more standard internal data integrity;
wenzelm
parents: 56053
diff changeset
    97
56067
wenzelm
parents: 56054
diff changeset
    98
val empty = Change_Table {change = No_Change, table = Table.empty};
wenzelm
parents: 56054
diff changeset
    99
wenzelm
parents: 56054
diff changeset
   100
fun is_empty (Change_Table {change, table}) =
wenzelm
parents: 56054
diff changeset
   101
  (case change of No_Change => Table.is_empty table | _ => false);
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   102
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   103
fun make_change_table (change, table) = Change_Table {change = change, table = table};
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   104
fun map_change_table f (Change_Table {change, table}) = make_change_table (f (change, table));
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   105
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   106
fun change_base begin = (map_change_table o apfst) (base_change begin);
56139
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
   107
fun change_ignore arg = (map_change_table o apfst) ignore_change arg;
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   108
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   109
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   110
(* join and merge *)
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   111
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   112
fun join f (arg1, arg2) =
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   113
  let
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   114
    val Change_Table {change = change1, table = table1} = arg1;
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   115
    val Change_Table {change = change2, table = table2} = arg2;
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   116
  in
56054
d1130b831e93 more standard internal data integrity;
wenzelm
parents: 56053
diff changeset
   117
    if pointer_eq (change1, change2) andalso pointer_eq (table1, table2) then arg1
d1130b831e93 more standard internal data integrity;
wenzelm
parents: 56053
diff changeset
   118
    else if is_empty arg2 then arg1
d1130b831e93 more standard internal data integrity;
wenzelm
parents: 56053
diff changeset
   119
    else if is_empty arg1 then arg2
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   120
    else
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   121
      (case merge_change (change1, change2) of
56067
wenzelm
parents: 56054
diff changeset
   122
        NONE => make_change_table (No_Change, Table.join f (table1, table2))
56139
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
   123
      | SOME (swapped, ch2, change') =>
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   124
          let
56139
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
   125
            fun maybe_swap (x, y) = if swapped then (y, x) else (x, y);
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
   126
            val (tab1, tab2) = maybe_swap (table1, table2);
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
   127
            fun update key tab =
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
   128
              (case Table.lookup tab2 key of
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
   129
                NONE => tab
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   130
              | SOME y =>
56139
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
   131
                  (case Table.lookup tab key of
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
   132
                    NONE => Table.update (key, y) tab
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   133
                  | SOME x =>
56139
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
   134
                      (case (SOME (f key (maybe_swap (x, y))) handle Table.SAME => NONE) of
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
   135
                        NONE => tab
b7add947a6ef more frugal recording of changes: join merely requires information from one side;
wenzelm
parents: 56068
diff changeset
   136
                      | SOME z => Table.update (key, z) tab)));
77723
b761c91c2447 performance tuning: prefer functor Set() over Table();
wenzelm
parents: 56139
diff changeset
   137
          in make_change_table (change', Set.fold update ch2 tab1) end)
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   138
  end;
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   139
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   140
fun merge eq =
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   141
  join (fn key => fn xy => if eq xy then raise Table.SAME else raise Table.DUP key);
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   142
77975
a7ca67369755 more operations;
wenzelm
parents: 77974
diff changeset
   143
fun merge_list eq =
a7ca67369755 more operations;
wenzelm
parents: 77974
diff changeset
   144
  join (fn _ => fn xy => if eq_list eq xy then raise Table.SAME else Library.merge eq xy);
a7ca67369755 more operations;
wenzelm
parents: 77974
diff changeset
   145
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   146
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   147
(* derived operations *)
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   148
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   149
fun fold f arg = Table.fold f (table_of arg);
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   150
fun dest arg = Table.dest (table_of arg);
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   151
fun lookup_key arg = Table.lookup_key (table_of arg);
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   152
fun lookup arg = Table.lookup (table_of arg);
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   153
fun defined arg = Table.defined (table_of arg);
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   154
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   155
fun change_table key f =
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   156
  map_change_table (fn (change, table) => (update_change key change, f table));
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   157
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   158
fun update (key, x)        = change_table key (Table.update (key, x));
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   159
fun update_new (key, x)    = change_table key (Table.update_new (key, x));
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   160
fun map_entry key f        = change_table key (Table.map_entry key f);
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   161
fun map_default (key, x) f = change_table key (Table.map_default (key, x) f);
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   162
fun delete_safe key        = change_table key (Table.delete_safe key);
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   163
77976
ca11a87bd2c6 more operations;
wenzelm
parents: 77975
diff changeset
   164
fun lookup_list arg = Table.lookup_list (table_of arg);
77974
93999ffdb9dd more operations;
wenzelm
parents: 77723
diff changeset
   165
fun insert_list eq (key, x) = change_table key (Table.insert_list eq (key, x));
93999ffdb9dd more operations;
wenzelm
parents: 77723
diff changeset
   166
fun remove_list eq (key, x) = change_table key (Table.remove_list eq (key, x));
93999ffdb9dd more operations;
wenzelm
parents: 77723
diff changeset
   167
fun update_list eq (key, x) = change_table key (Table.update_list eq (key, x));
93999ffdb9dd more operations;
wenzelm
parents: 77723
diff changeset
   168
56053
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   169
end;
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   170
030531cc4c62 tables with changes relative to some common base version -- support for efficient join/merge of big global tables with small local updates;
wenzelm
parents:
diff changeset
   171
structure Change_Table = Change_Table(type key = string val ord = fast_string_ord);