1if not modules then modules = { } end modules [ ' l-set ' ] = {
2 version = 1 . 001 ,
3 comment = " companion to luat-lib.mkiv " ,
4 author = " Hans Hagen, PRAGMA-ADE, Hasselt NL " ,
5 copyright = " PRAGMA ADE / ConTeXt Development Team " ,
6 license = " see context related readme files "
7}
8
9
10
11set = set or { }
12
13local nums = { }
14local tabs = { }
15local concat = table . concat
16local next , type = next , type
17
18set . create = table . tohash
19
20function set . tonumber ( t )
21 if next ( t ) then
22 local s = " "
23
24 for k , v in next , t do
25 if v then
26
27 s = s . . " " . . k
28 end
29 end
30 local n = nums [ s ]
31 if not n then
32 n = # tabs + 1
33 tabs [ n ] = t
34 nums [ s ] = n
35 end
36 return n
37 else
38 return 0
39 end
40end
41
42function set . totable ( n )
43 if n = = 0 then
44 return { }
45 else
46 return tabs [ n ] or { }
47 end
48end
49
50function set . tolist ( n )
51 if n = = 0 or not tabs [ n ] then
52 return " "
53 else
54 local t , n = { } , 0
55 for k , v in next , tabs [ n ] do
56 if v then
57 n = n + 1
58 t [ n ] = k
59 end
60 end
61 return concat ( t , " " )
62 end
63end
64
65function set . contains ( n , s )
66 if type ( n ) = = " table " then
67 return n [ s ]
68 elseif n = = 0 then
69 return false
70 else
71 local t = tabs [ n ]
72 return t and t [ s ]
73 end
74end
75
76
77
78
79
80
81
82
83
84
85
86
87
88 |