-
Notifications
You must be signed in to change notification settings - Fork 2
/
tigertab.sml
59 lines (56 loc) · 1.59 KB
/
tigertab.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
structure tigertab :> tigertab =
struct
open Polyhash
type ('a, 'b) Tabla = ('a, 'b) hash_table
exception yaExiste of string
exception noExiste
exception noExisteS of string
fun tabNueva() = mkPolyTable(100, noExiste)
fun fromTab t =
let val t' = tabNueva()
in apply (fn x => insert t' x) t; t' end
fun name x = x
fun tabEsta(s, t) =
case peek t s of
SOME _ => true
| NONE => false
fun tabInserta(s, e, t) = let val t' = copy t in (peekInsert t' (s, e); t') end
fun tabRInserta(s, e, t) = let val t' = copy t in (insert t' (s, e); t') end
fun tabBusca(s, t) = peek t s
fun tabSaca(s, t) =
case tabBusca(s, t) of
SOME t => t
| NONE => raise noExiste
fun tabAplica(f, t) = map(fn(_, e) => f e) t
fun tabAAplica(f, g, t) =
let val l' = listItems t
val t' = mkPolyTable(100, noExiste)
in
List.app(fn(k, e) => insert t' (k, e))
(List.map(fn(k, e) => (f k, g e)) l');
t'
end
fun tabRAAplica(f, g, t) =
let val l' = rev(listItems t)
val t' = mkPolyTable(100, noExiste)
in
List.app(fn(k, e) => insert t' (k, e))
(List.map(fn(k, e) => (f k, g e)) l');
t'
end
fun tabInserList(t, l) =
let val t' = copy t in (List.app(fn(s, e) => insert t' (s, e)) l; t') end
fun tabAList t = listItems t
fun tabFiltra(f, t) =
let val l = listItems t
val t' = mkPolyTable(100, noExiste)
in
List.app(fn(k, e) => insert t' (k,e))
(List.filter (fn(a, b) => f b) l);
t'
end
fun tabPrimer(f, t) = hd(List.filter (fn(a, b) => f b) (listItems t))
fun tabClaves t = List.map (fn(x, y) => x) (listItems t)
fun tabValores t = List.map (fn(x, y) => y) (listItems t)
fun fromList xs = tabInserList( tabNueva(), xs)
end