6
6
IntSet() = new(zeros(Uint32,256>>>5), 256, false)
9
IntSet(args...) = (s=IntSet(); for a in args; add(s,a); end; s)
9
IntSet(args...) = (s=IntSet(); for a in args; add!(s,a); end; s)
11
11
similar(s::IntSet) = IntSet()
42
function add_each(s::IntSet, ns)
42
function add_each!(s::IntSet, ns)
49
function del(s::IntSet, n::Integer)
49
function delete!(s::IntSet, n::Integer, deflt)
52
52
lim = int(n + div(n,2))
58
s.bits[n>>5 + 1] &= ~(uint32(1)<<(n&31))
62
function del_each(s::IntSet, ns)
58
mask = uint32(1)<<(n&31)
61
if (b&mask)==0; return deflt; end
66
function delete!(s::IntSet, n::Integer)
67
if delete!(s, n, n+1) == n+1
73
function del_each!(s::IntSet, ns)
69
setdiff(a::IntSet, b::IntSet) = del_each(copy(a),b)
80
setdiff(a::IntSet, b::IntSet) = del_each!(copy(a),b)
81
symdiff(a::IntSet, b::IntSet) = a $ b
71
function del_all(s::IntSet)
83
function empty!(s::IntSet)
76
function toggle(s::IntSet, n::Integer)
88
function symdiff!(s::IntSet, n::Integer)
78
90
lim = int(n + dim(n,2))
81
93
s.bits[n>>5 + 1] $= (uint32(1)<<(n&31))
85
function toggle_each(s::IntSet, ns)
97
function symdiff!(s::IntSet, ns)
92
function copy_to(to::IntSet, from::IntSet)
104
function copy!(to::IntSet, from::IntSet)
116
128
isempty(s::IntSet) =
117
129
!s.fill1s && ccall(:bitvector_any1, Uint32, (Ptr{Uint32}, Uint64, Uint64), s.bits, 0, s.limit)==0
119
function choose(s::IntSet)
131
function first(s::IntSet)
122
error("choose: set is empty")
134
error("first: set is empty")
127
function pop(s::IntSet)
139
shift!(s::IntSet) = delete!(s, first(s))
133
141
length(s::IntSet) = int(ccall(:bitvector_count, Uint64, (Ptr{Uint32}, Uint64, Uint64), s.bits, 0, s.limit)) +
134
142
(s.fill1s ? typemax(Int) - s.limit : 0)
136
function show(io, s::IntSet)
144
function show(io::IO, s::IntSet)
137
145
print(io, "IntSet(")
175
183
union(s1::IntSet, s2::IntSet) = (s1.limit >= s2.limit ? union!(copy(s1), s2) : union!(copy(s2), s1))
177
add_each(s::IntSet, s2::IntSet) = union!(s, s2)
185
add_each!(s::IntSet, s2::IntSet) = union!(s, s2)
179
187
function intersect!(s::IntSet, s2::IntSet)
180
188
if s2.limit > s.limit
225
($)(s1::IntSet, s2::IntSet) = (s1.limit >= s2.limit ? xor!(copy(s1), s2) : xor!(copy(s2), s1))
233
($)(s1::IntSet, s2::IntSet) =
234
(s1.limit >= s2.limit ? symdiff!(copy(s1), s2) : symdiff!!(copy(s2), s1))
227
236
|(s::IntSet, s2::IntSet) = union(s, s2)
228
237
(&)(s::IntSet, s2::IntSet) = intersect(s, s2)