Skip to content
Newer
Older
100644 74 lines (60 sloc) 1.64 KB
b826f24 @JeffBezanson keyword change: renaming type to abstract and struct to type
JeffBezanson authored Jan 17, 2011
1 type Set{T}
9296f4f @StefanKarpinski rename: HashTable => Dict, IdTable => ObjectIdDict [closes #766].
StefanKarpinski authored Apr 26, 2012
2 hash::Dict{T,Bool}
d67f9d2 @StefanKarpinski Really stupidly inefficient Set implementation.
StefanKarpinski authored Nov 30, 2010
3
9296f4f @StefanKarpinski rename: HashTable => Dict, IdTable => ObjectIdDict [closes #766].
StefanKarpinski authored Apr 26, 2012
4 Set() = new(Dict{T,Bool}())
5 Set(x...) = add_each(new(Dict{T,Bool}(length(x))), x)
d67f9d2 @StefanKarpinski Really stupidly inefficient Set implementation.
StefanKarpinski authored Nov 30, 2010
6 end
c261663 @StefanKarpinski Use Set(...) to construct sets instead of set(...).
StefanKarpinski authored Jun 24, 2011
7 Set() = Set{Any}()
757563f @StefanKarpinski Simpler and more efficient generic Set construction.
StefanKarpinski authored Nov 24, 2011
8 Set(x...) = Set{Any}(x...)
9 Set{T}(x::T...) = Set{T}(x...)
d67f9d2 @StefanKarpinski Really stupidly inefficient Set implementation.
StefanKarpinski authored Nov 30, 2010
10
366560e @StefanKarpinski Massive super-commit removing current_output_stream [closes #754]
StefanKarpinski authored May 2, 2012
11 show(io, s::Set) = (show(io, typeof(s)); show_comma_array(io, s,'(',')'))
78fd437 @StefanKarpinski Make IPC work as previously sketched with & and |.
StefanKarpinski authored Dec 6, 2010
12
a555efb @StefanKarpinski New hash-based Set implementation [closes #1].
StefanKarpinski authored Jun 14, 2011
13 isempty(s::Set) = isempty(s.hash)
d1ba897 @JeffBezanson use length() everywhere, make numel() an alias
JeffBezanson authored Feb 23, 2012
14 length(s::Set) = length(s.hash)
ed13933 @StefanKarpinski set functionality: elements, union [|], inter [&], diff [-].
StefanKarpinski authored May 25, 2012
15 elements(s::Set) = keys(s.hash)
a6dc8c5 @StefanKarpinski Various fixes and improvements to the Set API.
StefanKarpinski authored Nov 24, 2011
16 eltype{T}(s::Set{T}) = T
d67f9d2 @StefanKarpinski Really stupidly inefficient Set implementation.
StefanKarpinski authored Nov 30, 2010
17
a555efb @StefanKarpinski New hash-based Set implementation [closes #1].
StefanKarpinski authored Jun 15, 2011
18 has(s::Set, x) = has(s.hash, x)
763e658 @JeffBezanson fixing issue #214, abstract Associative type
JeffBezanson authored Nov 15, 2011
19 get(s::Set, x, deflt) = get(s.hash, x, false)
20
09d12f8 @JeffBezanson fixing #635
JeffBezanson authored Mar 24, 2012
21 add(s::Set, x) = (s.hash[x] = true; s)
22 del(s::Set, x) = (del(s.hash, x); s)
468a035 @StefanKarpinski Single pair pipeline works with generic process framework.
StefanKarpinski authored Dec 1, 2010
23
7bb95bc @StefanKarpinski Faster subprocess spawning.
StefanKarpinski authored Jan 3, 2012
24 add_each(s::Set, xs) = (for x=xs; add(s,x); end; s)
25 del_each(s::Set, xs) = (for x=xs; del(s,x); end; s)
26
27 similar{T}(s::Set{T}) = Set{T}()
f9bc57e @JeffBezanson fixing #327. length only for ordered collections, numel for all colle…
JeffBezanson authored Jan 6, 2012
28 copy(s::Set) = add_each(similar(s), s)
f72a9da @StefanKarpinski Implement union of sets.
StefanKarpinski authored Dec 6, 2010
29
8145560 @StefanKarpinski Allow clearing a Set without mutating its fields.
StefanKarpinski authored Mar 27, 2012
30 del_all{T}(s::Set{T}) = (del_all(s.hash); s)
5d1b231 @JeffBezanson adding missing del_all methods for some collections
JeffBezanson authored Aug 11, 2011
31
a555efb @StefanKarpinski New hash-based Set implementation [closes #1].
StefanKarpinski authored Jun 15, 2011
32 start(s::Set) = start(s.hash)
33 done(s::Set, state) = done(s.hash, state)
34 next(s::Set, state) = (((k,v),state) = next(s.hash, state); (k,state))
35
a6dc8c5 @StefanKarpinski Various fixes and improvements to the Set API.
StefanKarpinski authored Nov 24, 2011
36 union() = Set()
ed13933 @StefanKarpinski set functionality: elements, union [|], inter [&], diff [-].
StefanKarpinski authored May 25, 2012
37 union(s::Set) = copy(s)
a6dc8c5 @StefanKarpinski Various fixes and improvements to the Set API.
StefanKarpinski authored Nov 24, 2011
38 function union(s::Set, sets::Set...)
39 U = eltype(s)
ed13933 @StefanKarpinski set functionality: elements, union [|], inter [&], diff [-].
StefanKarpinski authored May 25, 2012
40 if U != Any
41 for t in sets
42 T = eltype(t)
43 U = subtype(T,U) ? U :
44 subtype(U,T) ? T : Any # TODO: tigher upper bound
a6dc8c5 @StefanKarpinski Various fixes and improvements to the Set API.
StefanKarpinski authored Nov 24, 2011
45 end
46 end
ed13933 @StefanKarpinski set functionality: elements, union [|], inter [&], diff [-].
StefanKarpinski authored May 25, 2012
47 u = Set{U}()
48 add_each(u,s)
12806ac @StefanKarpinski Consider `for x in v` idiomatic for non-range iterations.
StefanKarpinski authored Jan 9, 2012
49 for t in sets
ed13933 @StefanKarpinski set functionality: elements, union [|], inter [&], diff [-].
StefanKarpinski authored May 25, 2012
50 add_each(u,t)
08bd956 @StefanKarpinski Replace varargs add(s, xs...) with add_each(s, xs).
StefanKarpinski authored Nov 25, 2011
51 end
ed13933 @StefanKarpinski set functionality: elements, union [|], inter [&], diff [-].
StefanKarpinski authored May 25, 2012
52 return u
a6dc8c5 @StefanKarpinski Various fixes and improvements to the Set API.
StefanKarpinski authored Nov 24, 2011
53 end
ed13933 @StefanKarpinski set functionality: elements, union [|], inter [&], diff [-].
StefanKarpinski authored May 25, 2012
54
55 inter() = Set()
56 inter(s::Set) = copy(s)
57 function inter(s::Set, sets::Set...)
58 i = copy(s)
59 for x in s
60 for t in sets
61 if !has(t,x)
62 del(i,x)
63 end
64 end
65 end
66 return i
67 end
68
69 diff(a::Set, b::Set) = del_each(copy(a),b)
70
71 |(s::Set...) = union(s...)
72 (&)(s::Set...) = inter(s...)
73 -(a::Set, b::Set) = diff(a,b)
Something went wrong with that request. Please try again.