]>
sourceware.org Git - systemtap.git/blob - bpf-bitset.cxx
b331f8cf717965ac983ad27d78986766cdcd35ac
2 // Copyright (C) 2016 Red Hat Inc.
4 // This file is part of systemtap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
9 #include "bpf-bitset.h"
14 throw_out_of_range(const char *where
)
16 throw std::out_of_range(where
);
22 set1_const_ref::empty () const
24 for (size_t i
= 0; i
< words
; ++i
)
31 set1_const_ref::operator== (const set1_const_ref
&o
) const
35 for (size_t i
= 0; i
< words
; ++i
)
36 if (data
[i
] != o
.data
[i
])
42 set1_const_ref::is_subset_of(const set1_const_ref
&o
) const
44 size_t n
= std::min(words
, o
.words
);
46 for (size_t i
= 0; i
< n
; ++i
)
47 if (data
[i
] & ~o
.data
[i
])
49 for (; n
< words
; ++n
)
57 set1_const_ref::find_first() const
59 for (size_t i
= 0; i
< words
; ++i
)
61 return i
* bits_per_word
+ __builtin_ctzl (data
[i
]);
66 set1_const_ref::find_next(size_t last
) const
68 size_t i
= (last
+ 1) / bits_per_word
;
69 size_t o
= (last
+ 1) % bits_per_word
;
71 if (__builtin_expect (i
>= words
, 0))
74 word_t w
= data
[i
] & ((word_t
)-1 << o
);
75 for (; w
== 0; w
= data
[i
])
78 return i
* bits_per_word
+ __builtin_ctzl (w
);
82 set1_const_ref::find_next_zero(size_t last
) const
84 size_t i
= (last
+ 1) / bits_per_word
;
85 size_t o
= (last
+ 1) % bits_per_word
;
87 if (__builtin_expect (i
>= words
, 0))
90 word_t w
= ~data
[i
] & ((word_t
)-1 << o
);
91 for (; w
== 0; w
= ~data
[i
])
94 return i
* bits_per_word
+ __builtin_ctzl (w
);
97 set1::set1(size_t bits
)
98 : set1_ref(new word_t
[round_words(bits
)], round_words(bits
))
100 memset(data
, 0, words
* sizeof(word_t
));
103 set1::set1(const set1_const_ref
&o
)
104 : set1_ref(new word_t
[o
.words
], o
.words
)
106 memcpy(data
, o
.data
, words
* sizeof(word_t
));
114 set2::set2(size_t m1
, size_t m2
)
115 : n1(m1
), w2(round_words(m2
)), data(new word_t
[m1
* w2
])
117 memset(data
, 0, n1
* w2
* sizeof(word_t
));
120 set2::set2(const set2
&o
)
121 : n1(o
.n1
), w2(o
.w2
), data(new word_t
[o
.n1
* o
.w2
])
123 memcpy(data
, o
.data
, n1
* w2
* sizeof(word_t
));
133 operator<< (std::ostream
&o
, const set1_const_ref
&s
)
136 for (size_t n
= s
.size(), i
= 0; i
< n
; ++i
)
147 } // namespace bitset
This page took 0.047465 seconds and 6 git commands to generate.