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