| author | wenzelm | 
| Wed, 23 Apr 2008 12:13:08 +0200 | |
| changeset 26741 | eb15fd4cd1ad | 
| parent 25391 | 783e5de2a6c7 | 
| child 27508 | abdab08677d8 | 
| permissions | -rw-r--r-- | 
| 6118 | 1 | (* Title: Pure/General/table.ML | 
| 5015 | 2 | ID: $Id$ | 
| 15014 | 3 | Author: Markus Wenzel and Stefan Berghofer, TU Muenchen | 
| 5015 | 4 | |
| 16342 | 5 | Generic tables. Efficient purely functional implementation using | 
| 6 | balanced 2-3 trees. | |
| 5015 | 7 | *) | 
| 8 | ||
| 9 | signature KEY = | |
| 10 | sig | |
| 11 | type key | |
| 12 | val ord: key * key -> order | |
| 13 | end; | |
| 14 | ||
| 15 | signature TABLE = | |
| 16 | sig | |
| 17 | type key | |
| 18 | type 'a table | |
| 19 | exception DUP of key | |
| 19031 | 20 | exception SAME | 
| 15014 | 21 | exception UNDEF of key | 
| 5015 | 22 | val empty: 'a table | 
| 23 | val is_empty: 'a table -> bool | |
| 5681 | 24 |   val map: ('a -> 'b) -> 'a table -> 'b table
 | 
| 16446 | 25 | val map': (key -> 'a -> 'b) -> 'a table -> 'b table | 
| 26 | val fold: (key * 'b -> 'a -> 'a) -> 'b table -> 'a -> 'a | |
| 17579 | 27 | val fold_map: (key * 'b -> 'a -> 'c * 'a) -> 'b table -> 'a -> 'c table * 'a | 
| 5015 | 28 | val dest: 'a table -> (key * 'a) list | 
| 5681 | 29 | val keys: 'a table -> key list | 
| 8409 | 30 | val min_key: 'a table -> key option | 
| 15160 | 31 | val max_key: 'a table -> key option | 
| 7061 | 32 | val exists: (key * 'a -> bool) -> 'a table -> bool | 
| 16192 | 33 | val forall: (key * 'a -> bool) -> 'a table -> bool | 
| 16887 | 34 | val defined: 'a table -> key -> bool | 
| 17412 | 35 | val lookup: 'a table -> key -> 'a option | 
| 36 | val update: (key * 'a) -> 'a table -> 'a table | |
| 37 | val update_new: (key * 'a) -> 'a table -> 'a table (*exception DUP*) | |
| 17179 | 38 | val default: key * 'a -> 'a table -> 'a table | 
| 15665 | 39 |   val map_entry: key -> ('a -> 'a) -> 'a table -> 'a table
 | 
| 20141 | 40 |   val map_default: (key * 'a) -> ('a -> 'a) -> 'a table -> 'a table
 | 
| 23655 
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
 wenzelm parents: 
21065diff
changeset | 41 | val make: (key * 'a) list -> 'a table (*exception DUP*) | 
| 
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
 wenzelm parents: 
21065diff
changeset | 42 | val extend: 'a table * (key * 'a) list -> 'a table (*exception DUP*) | 
| 19031 | 43 | val join: (key -> 'a * 'a -> 'a) (*exception DUP/SAME*) -> | 
| 23655 
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
 wenzelm parents: 
21065diff
changeset | 44 | 'a table * 'a table -> 'a table (*exception DUP*) | 
| 
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
 wenzelm parents: 
21065diff
changeset | 45 |   val merge: ('a * 'a -> bool) -> 'a table * 'a table -> 'a table      (*exception DUP*)
 | 
| 15665 | 46 | val delete: key -> 'a table -> 'a table (*exception UNDEF*) | 
| 15761 | 47 | val delete_safe: key -> 'a table -> 'a table | 
| 16466 | 48 |   val member: ('b * 'a -> bool) -> 'a table -> key * 'b -> bool
 | 
| 15761 | 49 |   val insert: ('a * 'a -> bool) -> key * 'a -> 'a table -> 'a table    (*exception DUP*)
 | 
| 16139 | 50 |   val remove: ('b * 'a -> bool) -> key * 'b -> 'a table -> 'a table
 | 
| 18946 | 51 | val lookup_list: 'a list table -> key -> 'a list | 
| 25391 | 52 | val cons_list: (key * 'a) -> 'a list table -> 'a list table | 
| 19506 | 53 |   val insert_list: ('a * 'a -> bool) -> key * 'a -> 'a list table -> 'a list table
 | 
| 18946 | 54 |   val remove_list: ('b * 'a -> bool) -> key * 'b -> 'a list table -> 'a list table
 | 
| 25391 | 55 |   val update_list: ('a * 'a -> bool) -> key * 'a -> 'a list table -> 'a list table
 | 
| 18946 | 56 | val make_list: (key * 'a) list -> 'a list table | 
| 57 | val dest_list: 'a list table -> (key * 'a) list | |
| 58 |   val merge_list: ('a * 'a -> bool) ->
 | |
| 23655 
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
 wenzelm parents: 
21065diff
changeset | 59 | 'a list table * 'a list table -> 'a list table (*exception DUP*) | 
| 5015 | 60 | end; | 
| 61 | ||
| 62 | functor TableFun(Key: KEY): TABLE = | |
| 63 | struct | |
| 64 | ||
| 65 | ||
| 66 | (* datatype table *) | |
| 67 | ||
| 68 | type key = Key.key; | |
| 69 | ||
| 70 | datatype 'a table = | |
| 71 | Empty | | |
| 72 | Branch2 of 'a table * (key * 'a) * 'a table | | |
| 73 | Branch3 of 'a table * (key * 'a) * 'a table * (key * 'a) * 'a table; | |
| 74 | ||
| 75 | exception DUP of key; | |
| 76 | ||
| 77 | ||
| 5681 | 78 | (* empty *) | 
| 79 | ||
| 5015 | 80 | val empty = Empty; | 
| 81 | ||
| 82 | fun is_empty Empty = true | |
| 83 | | is_empty _ = false; | |
| 84 | ||
| 5681 | 85 | |
| 86 | (* map and fold combinators *) | |
| 87 | ||
| 16657 | 88 | fun map_table f = | 
| 89 | let | |
| 90 | fun map Empty = Empty | |
| 91 | | map (Branch2 (left, (k, x), right)) = | |
| 92 | Branch2 (map left, (k, f k x), map right) | |
| 93 | | map (Branch3 (left, (k1, x1), mid, (k2, x2), right)) = | |
| 94 | Branch3 (map left, (k1, f k1 x1), map mid, (k2, f k2 x2), map right); | |
| 95 | in map end; | |
| 5681 | 96 | |
| 16657 | 97 | fun fold_table f = | 
| 98 | let | |
| 99 | fun fold Empty x = x | |
| 100 | | fold (Branch2 (left, p, right)) x = | |
| 101 | fold right (f p (fold left x)) | |
| 102 | | fold (Branch3 (left, p1, mid, p2, right)) x = | |
| 103 | fold right (f p2 (fold mid (f p1 (fold left x)))); | |
| 104 | in fold end; | |
| 5681 | 105 | |
| 17709 | 106 | fun fold_map_table f = | 
| 17579 | 107 | let | 
| 108 | fun fold_map Empty s = (Empty, s) | |
| 109 | | fold_map (Branch2 (left, p as (k, x), right)) s = | |
| 110 | s | |
| 111 | |> fold_map left | |
| 112 | ||>> f p | |
| 113 | ||>> fold_map right | |
| 114 | |-> (fn ((l, e), r) => pair (Branch2 (l, (k, e), r))) | |
| 115 | | fold_map (Branch3 (left, p1 as (k1, x1), mid, p2 as (k2, x2), right)) s = | |
| 116 | s | |
| 117 | |> fold_map left | |
| 118 | ||>> f p1 | |
| 119 | ||>> fold_map mid | |
| 120 | ||>> f p2 | |
| 121 | ||>> fold_map right | |
| 122 | |-> (fn ((((l, e1), m), e2), r) => pair (Branch3 (l, (k1, e1), m, (k2, e2), r))) | |
| 123 | in fold_map end; | |
| 124 | ||
| 16446 | 125 | fun dest tab = rev (fold_table cons tab []); | 
| 126 | fun keys tab = rev (fold_table (cons o #1) tab []); | |
| 16192 | 127 | |
| 128 | local exception TRUE in | |
| 129 | ||
| 130 | fun exists pred tab = | |
| 16446 | 131 | (fold_table (fn p => fn () => if pred p then raise TRUE else ()) tab (); false) | 
| 16192 | 132 | handle TRUE => true; | 
| 133 | ||
| 134 | fun forall pred = not o exists (not o pred); | |
| 135 | ||
| 136 | end; | |
| 5015 | 137 | |
| 15531 | 138 | fun min_key Empty = NONE | 
| 16864 | 139 | | min_key (Branch2 (Empty, (k, _), _)) = SOME k | 
| 140 | | min_key (Branch3 (Empty, (k, _), _, _, _)) = SOME k | |
| 141 | | min_key (Branch2 (left, _, _)) = min_key left | |
| 142 | | min_key (Branch3 (left, _, _, _, _)) = min_key left; | |
| 8409 | 143 | |
| 15531 | 144 | fun max_key Empty = NONE | 
| 16864 | 145 | | max_key (Branch2 (_, (k, _), Empty)) = SOME k | 
| 146 | | max_key (Branch3 (_, _, _, (k, _), Empty)) = SOME k | |
| 147 | | max_key (Branch2 (_, _, right)) = max_key right | |
| 148 | | max_key (Branch3 (_, _, _, _, right)) = max_key right; | |
| 15665 | 149 | |
| 5015 | 150 | |
| 151 | (* lookup *) | |
| 152 | ||
| 19031 | 153 | fun lookup tab key = | 
| 154 | let | |
| 155 | fun look Empty = NONE | |
| 156 | | look (Branch2 (left, (k, x), right)) = | |
| 157 | (case Key.ord (key, k) of | |
| 158 | LESS => look left | |
| 159 | | EQUAL => SOME x | |
| 160 | | GREATER => look right) | |
| 161 | | look (Branch3 (left, (k1, x1), mid, (k2, x2), right)) = | |
| 162 | (case Key.ord (key, k1) of | |
| 163 | LESS => look left | |
| 164 | | EQUAL => SOME x1 | |
| 165 | | GREATER => | |
| 166 | (case Key.ord (key, k2) of | |
| 167 | LESS => look mid | |
| 168 | | EQUAL => SOME x2 | |
| 169 | | GREATER => look right)); | |
| 170 | in look tab end; | |
| 5015 | 171 | |
| 19031 | 172 | fun defined tab key = | 
| 173 | let | |
| 174 | fun def Empty = false | |
| 175 | | def (Branch2 (left, (k, x), right)) = | |
| 176 | (case Key.ord (key, k) of | |
| 177 | LESS => def left | |
| 178 | | EQUAL => true | |
| 179 | | GREATER => def right) | |
| 180 | | def (Branch3 (left, (k1, x1), mid, (k2, x2), right)) = | |
| 181 | (case Key.ord (key, k1) of | |
| 182 | LESS => def left | |
| 183 | | EQUAL => true | |
| 184 | | GREATER => | |
| 185 | (case Key.ord (key, k2) of | |
| 186 | LESS => def mid | |
| 187 | | EQUAL => true | |
| 188 | | GREATER => def right)); | |
| 189 | in def tab end; | |
| 16887 | 190 | |
| 5015 | 191 | |
| 19031 | 192 | (* modify *) | 
| 5015 | 193 | |
| 194 | datatype 'a growth = | |
| 195 | Stay of 'a table | | |
| 196 | Sprout of 'a table * (key * 'a) * 'a table; | |
| 197 | ||
| 15761 | 198 | exception SAME; | 
| 199 | ||
| 15665 | 200 | fun modify key f tab = | 
| 201 | let | |
| 202 | fun modfy Empty = Sprout (Empty, (key, f NONE), Empty) | |
| 203 | | modfy (Branch2 (left, p as (k, x), right)) = | |
| 204 | (case Key.ord (key, k) of | |
| 205 | LESS => | |
| 206 | (case modfy left of | |
| 207 | Stay left' => Stay (Branch2 (left', p, right)) | |
| 208 | | Sprout (left1, q, left2) => Stay (Branch3 (left1, q, left2, p, right))) | |
| 209 | | EQUAL => Stay (Branch2 (left, (k, f (SOME x)), right)) | |
| 210 | | GREATER => | |
| 211 | (case modfy right of | |
| 212 | Stay right' => Stay (Branch2 (left, p, right')) | |
| 213 | | Sprout (right1, q, right2) => | |
| 214 | Stay (Branch3 (left, p, right1, q, right2)))) | |
| 215 | | modfy (Branch3 (left, p1 as (k1, x1), mid, p2 as (k2, x2), right)) = | |
| 216 | (case Key.ord (key, k1) of | |
| 5015 | 217 | LESS => | 
| 15665 | 218 | (case modfy left of | 
| 219 | Stay left' => Stay (Branch3 (left', p1, mid, p2, right)) | |
| 220 | | Sprout (left1, q, left2) => | |
| 221 | Sprout (Branch2 (left1, q, left2), p1, Branch2 (mid, p2, right))) | |
| 222 | | EQUAL => Stay (Branch3 (left, (k1, f (SOME x1)), mid, p2, right)) | |
| 5015 | 223 | | GREATER => | 
| 15665 | 224 | (case Key.ord (key, k2) of | 
| 225 | LESS => | |
| 226 | (case modfy mid of | |
| 227 | Stay mid' => Stay (Branch3 (left, p1, mid', p2, right)) | |
| 228 | | Sprout (mid1, q, mid2) => | |
| 229 | Sprout (Branch2 (left, p1, mid1), q, Branch2 (mid2, p2, right))) | |
| 230 | | EQUAL => Stay (Branch3 (left, p1, mid, (k2, f (SOME x2)), right)) | |
| 231 | | GREATER => | |
| 232 | (case modfy right of | |
| 233 | Stay right' => Stay (Branch3 (left, p1, mid, p2, right')) | |
| 234 | | Sprout (right1, q, right2) => | |
| 235 | Sprout (Branch2 (left, p1, mid), p2, Branch2 (right1, q, right2))))); | |
| 5015 | 236 | |
| 15665 | 237 | in | 
| 238 | (case modfy tab of | |
| 239 | Stay tab' => tab' | |
| 240 | | Sprout br => Branch2 br) | |
| 241 | handle SAME => tab | |
| 242 | end; | |
| 5015 | 243 | |
| 17412 | 244 | fun update (key, x) tab = modify key (fn _ => x) tab; | 
| 245 | fun update_new (key, x) tab = modify key (fn NONE => x | SOME _ => raise DUP key) tab; | |
| 17709 | 246 | fun default (key, x) tab = modify key (fn NONE => x | SOME _ => raise SAME) tab; | 
| 15761 | 247 | fun map_entry key f = modify key (fn NONE => raise SAME | SOME x => f x); | 
| 20141 | 248 | fun map_default (key, x) f = modify key (fn NONE => f x | SOME x => f x); | 
| 5015 | 249 | |
| 250 | ||
| 15014 | 251 | (* delete *) | 
| 252 | ||
| 15665 | 253 | exception UNDEF of key; | 
| 254 | ||
| 255 | local | |
| 256 | ||
| 257 | fun compare NONE (k2, _) = LESS | |
| 258 | | compare (SOME k1) (k2, _) = Key.ord (k1, k2); | |
| 15014 | 259 | |
| 260 | fun if_eq EQUAL x y = x | |
| 261 | | if_eq _ x y = y; | |
| 262 | ||
| 15531 | 263 | fun del (SOME k) Empty = raise UNDEF k | 
| 264 | | del NONE (Branch2 (Empty, p, Empty)) = (p, (true, Empty)) | |
| 265 | | del NONE (Branch3 (Empty, p, Empty, q, Empty)) = | |
| 15014 | 266 | (p, (false, Branch2 (Empty, q, Empty))) | 
| 15665 | 267 | | del k (Branch2 (Empty, p, Empty)) = (case compare k p of | 
| 16002 | 268 | EQUAL => (p, (true, Empty)) | _ => raise UNDEF (the k)) | 
| 15665 | 269 | | del k (Branch3 (Empty, p, Empty, q, Empty)) = (case compare k p of | 
| 15014 | 270 | EQUAL => (p, (false, Branch2 (Empty, q, Empty))) | 
| 15665 | 271 | | _ => (case compare k q of | 
| 15014 | 272 | EQUAL => (q, (false, Branch2 (Empty, p, Empty))) | 
| 16002 | 273 | | _ => raise UNDEF (the k))) | 
| 15665 | 274 | | del k (Branch2 (l, p, r)) = (case compare k p of | 
| 15014 | 275 | LESS => (case del k l of | 
| 276 | (p', (false, l')) => (p', (false, Branch2 (l', p, r))) | |
| 277 | | (p', (true, l')) => (p', case r of | |
| 278 | Branch2 (rl, rp, rr) => | |
| 279 | (true, Branch3 (l', p, rl, rp, rr)) | |
| 280 | | Branch3 (rl, rp, rm, rq, rr) => (false, Branch2 | |
| 281 | (Branch2 (l', p, rl), rp, Branch2 (rm, rq, rr))))) | |
| 15531 | 282 | | ord => (case del (if_eq ord NONE k) r of | 
| 15014 | 283 | (p', (false, r')) => (p', (false, Branch2 (l, if_eq ord p' p, r'))) | 
| 284 | | (p', (true, r')) => (p', case l of | |
| 285 | Branch2 (ll, lp, lr) => | |
| 286 | (true, Branch3 (ll, lp, lr, if_eq ord p' p, r')) | |
| 287 | | Branch3 (ll, lp, lm, lq, lr) => (false, Branch2 | |
| 288 | (Branch2 (ll, lp, lm), lq, Branch2 (lr, if_eq ord p' p, r')))))) | |
| 15665 | 289 | | del k (Branch3 (l, p, m, q, r)) = (case compare k q of | 
| 290 | LESS => (case compare k p of | |
| 15014 | 291 | LESS => (case del k l of | 
| 292 | (p', (false, l')) => (p', (false, Branch3 (l', p, m, q, r))) | |
| 293 | | (p', (true, l')) => (p', (false, case (m, r) of | |
| 294 | (Branch2 (ml, mp, mr), Branch2 _) => | |
| 295 | Branch2 (Branch3 (l', p, ml, mp, mr), q, r) | |
| 296 | | (Branch3 (ml, mp, mm, mq, mr), _) => | |
| 297 | Branch3 (Branch2 (l', p, ml), mp, Branch2 (mm, mq, mr), q, r) | |
| 298 | | (Branch2 (ml, mp, mr), Branch3 (rl, rp, rm, rq, rr)) => | |
| 299 | Branch3 (Branch2 (l', p, ml), mp, Branch2 (mr, q, rl), rp, | |
| 300 | Branch2 (rm, rq, rr))))) | |
| 15531 | 301 | | ord => (case del (if_eq ord NONE k) m of | 
| 15014 | 302 | (p', (false, m')) => | 
| 303 | (p', (false, Branch3 (l, if_eq ord p' p, m', q, r))) | |
| 304 | | (p', (true, m')) => (p', (false, case (l, r) of | |
| 305 | (Branch2 (ll, lp, lr), Branch2 _) => | |
| 306 | Branch2 (Branch3 (ll, lp, lr, if_eq ord p' p, m'), q, r) | |
| 307 | | (Branch3 (ll, lp, lm, lq, lr), _) => | |
| 308 | Branch3 (Branch2 (ll, lp, lm), lq, | |
| 309 | Branch2 (lr, if_eq ord p' p, m'), q, r) | |
| 310 | | (_, Branch3 (rl, rp, rm, rq, rr)) => | |
| 311 | Branch3 (l, if_eq ord p' p, Branch2 (m', q, rl), rp, | |
| 312 | Branch2 (rm, rq, rr)))))) | |
| 15531 | 313 | | ord => (case del (if_eq ord NONE k) r of | 
| 15014 | 314 | (q', (false, r')) => | 
| 315 | (q', (false, Branch3 (l, p, m, if_eq ord q' q, r'))) | |
| 316 | | (q', (true, r')) => (q', (false, case (l, m) of | |
| 317 | (Branch2 _, Branch2 (ml, mp, mr)) => | |
| 318 | Branch2 (l, p, Branch3 (ml, mp, mr, if_eq ord q' q, r')) | |
| 319 | | (_, Branch3 (ml, mp, mm, mq, mr)) => | |
| 320 | Branch3 (l, p, Branch2 (ml, mp, mm), mq, | |
| 321 | Branch2 (mr, if_eq ord q' q, r')) | |
| 322 | | (Branch3 (ll, lp, lm, lq, lr), Branch2 (ml, mp, mr)) => | |
| 323 | Branch3 (Branch2 (ll, lp, lm), lq, Branch2 (lr, p, ml), mp, | |
| 324 | Branch2 (mr, if_eq ord q' q, r')))))); | |
| 325 | ||
| 15665 | 326 | in | 
| 327 | ||
| 15761 | 328 | fun delete key tab = snd (snd (del (SOME key) tab)); | 
| 329 | fun delete_safe key tab = delete key tab handle UNDEF _ => tab; | |
| 15014 | 330 | |
| 15665 | 331 | end; | 
| 332 | ||
| 15014 | 333 | |
| 19031 | 334 | (* membership operations *) | 
| 16466 | 335 | |
| 336 | fun member eq tab (key, x) = | |
| 17412 | 337 | (case lookup tab key of | 
| 16466 | 338 | NONE => false | 
| 339 | | SOME y => eq (x, y)); | |
| 15761 | 340 | |
| 341 | fun insert eq (key, x) = | |
| 342 | modify key (fn NONE => x | SOME y => if eq (x, y) then raise SAME else raise DUP key); | |
| 343 | ||
| 344 | fun remove eq (key, x) tab = | |
| 17412 | 345 | (case lookup tab key of | 
| 15761 | 346 | NONE => tab | 
| 347 | | SOME y => if eq (x, y) then delete key tab else tab); | |
| 348 | ||
| 349 | ||
| 19031 | 350 | (* simultaneous modifications *) | 
| 351 | ||
| 23655 
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
 wenzelm parents: 
21065diff
changeset | 352 | fun extend (table, args) = fold update_new args table; | 
| 19031 | 353 | |
| 354 | fun make entries = extend (empty, entries); | |
| 5015 | 355 | |
| 12287 | 356 | fun join f (table1, table2) = | 
| 23655 
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
 wenzelm parents: 
21065diff
changeset | 357 | let fun add (key, y) tab = modify key (fn NONE => y | SOME x => f key (x, y)) tab; | 
| 
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
 wenzelm parents: 
21065diff
changeset | 358 | in fold_table add table2 table1 end; | 
| 12287 | 359 | |
| 19031 | 360 | fun merge eq = join (fn key => fn xy => if eq xy then raise SAME else raise DUP key); | 
| 5015 | 361 | |
| 362 | ||
| 19031 | 363 | (* list tables *) | 
| 15761 | 364 | |
| 18946 | 365 | fun lookup_list tab key = these (lookup tab key); | 
| 25391 | 366 | |
| 367 | fun cons_list (key, x) tab = modify key (fn NONE => [x] | SOME xs => x :: xs) tab; | |
| 5015 | 368 | |
| 20124 | 369 | fun insert_list eq (key, x) = | 
| 370 | modify key (fn NONE => [x] | SOME xs => if Library.member eq xs x then raise SAME else x :: xs); | |
| 25391 | 371 | |
| 18946 | 372 | fun remove_list eq (key, x) tab = | 
| 15761 | 373 | map_entry key (fn xs => (case Library.remove eq x xs of [] => raise UNDEF key | ys => ys)) tab | 
| 374 | handle UNDEF _ => delete key tab; | |
| 5015 | 375 | |
| 25391 | 376 | fun update_list eq (key, x) = | 
| 377 | modify key (fn NONE => [x] | SOME [] => [x] | SOME (xs as y :: _) => | |
| 378 | if eq (x, y) then raise SAME else Library.update eq x xs); | |
| 379 | ||
| 380 | fun make_list args = fold_rev cons_list args empty; | |
| 19482 
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
 wenzelm parents: 
19073diff
changeset | 381 | fun dest_list tab = maps (fn (key, xs) => map (pair key) xs) (dest tab); | 
| 19031 | 382 | fun merge_list eq = join (fn _ => Library.merge eq); | 
| 5015 | 383 | |
| 384 | ||
| 5681 | 385 | (*final declarations of this structure!*) | 
| 16446 | 386 | fun map f = map_table (K f); | 
| 387 | val map' = map_table; | |
| 388 | val fold = fold_table; | |
| 17579 | 389 | val fold_map = fold_map_table; | 
| 5015 | 390 | |
| 391 | end; | |
| 392 | ||
| 16342 | 393 | structure Inttab = TableFun(type key = int val ord = int_ord); | 
| 16687 
51fa05ce0f32
Symtab: use fast_string_ord instead of string_ord -- affects order of Symtab.dest etc.;
 wenzelm parents: 
16657diff
changeset | 394 | structure Symtab = TableFun(type key = string val ord = fast_string_ord); |