18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_LIBADT_VECTSET_HPP
26 #define SHARE_LIBADT_VECTSET_HPP
27
28 #include "memory/allocation.hpp"
29 #include "utilities/copy.hpp"
30
31 // Vector Sets
32
33 // These sets can grow or shrink, based on the initial size and the largest
34 // element currently in them.
35
36 //------------------------------VectorSet--------------------------------------
37 class VectorSet : public AnyObj {
38 private:
39
40 static const uint word_bits = 5;
41 static const uint bit_mask = 31;
42
43 // Used 32-bit words
44 uint _size;
45 uint32_t* _data;
46 // Allocated words
47 uint _data_size;
48 Arena* _set_arena;
49
50 void init(Arena* arena);
51 // Grow vector to required word capacity
52 void grow(uint new_word_capacity);
53 public:
54 VectorSet();
55 VectorSet(Arena* arena);
56 ~VectorSet() {}
57
58 NONCOPYABLE(VectorSet);
59 VectorSet& operator=(VectorSet&&) = delete;
60 // Allow move constructor for && (eg. capture return of function)
61 VectorSet(VectorSet&&) = default;
62
63 void insert(uint elem);
64 bool is_empty() const;
65 void reset() {
66 _size = 0;
67 }
98 }
99
100 void remove(uint elem) {
101 uint32_t word = elem >> word_bits;
102 if (word >= _size) {
103 return;
104 }
105 uint32_t mask = 1U << (elem & bit_mask);
106 _data[word] &= ~mask; // Clear bit
107 }
108
109 // Fast inlined set
110 void set(uint elem) {
111 uint32_t word = elem >> word_bits;
112 if (word >= _size) {
113 grow(word);
114 }
115 uint32_t mask = 1U << (elem & bit_mask);
116 _data[word] |= mask;
117 }
118 };
119
120 #endif // SHARE_LIBADT_VECTSET_HPP
|
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_LIBADT_VECTSET_HPP
26 #define SHARE_LIBADT_VECTSET_HPP
27
28 #include "memory/allocation.hpp"
29 #include "utilities/copy.hpp"
30
31 // Vector Sets
32
33 // These sets can grow or shrink, based on the initial size and the largest
34 // element currently in them.
35
36 //------------------------------VectorSet--------------------------------------
37 class VectorSet : public AnyObj {
38 friend VectorSet intersect(const VectorSet&, const VectorSet&);
39
40 private:
41
42 static const uint word_bits = 5;
43 static const uint bit_mask = 31;
44
45 // Used 32-bit words
46 uint _size;
47 // Allocated words
48 uint32_t* _data;
49 Arena* _set_arena;
50
51 void init(Arena* arena);
52 // Grow vector to required word capacity
53 void grow(uint new_word_capacity);
54 public:
55 VectorSet();
56 VectorSet(Arena* arena);
57 ~VectorSet() {}
58
59 NONCOPYABLE(VectorSet);
60 VectorSet& operator=(VectorSet&&) = delete;
61 // Allow move constructor for && (eg. capture return of function)
62 VectorSet(VectorSet&&) = default;
63
64 void insert(uint elem);
65 bool is_empty() const;
66 void reset() {
67 _size = 0;
68 }
99 }
100
101 void remove(uint elem) {
102 uint32_t word = elem >> word_bits;
103 if (word >= _size) {
104 return;
105 }
106 uint32_t mask = 1U << (elem & bit_mask);
107 _data[word] &= ~mask; // Clear bit
108 }
109
110 // Fast inlined set
111 void set(uint elem) {
112 uint32_t word = elem >> word_bits;
113 if (word >= _size) {
114 grow(word);
115 }
116 uint32_t mask = 1U << (elem & bit_mask);
117 _data[word] |= mask;
118 }
119
120 #ifndef PRODUCT
121 void print_on(outputStream* st) const override;
122 #endif // PRODUCT
123 };
124
125 VectorSet intersect(const VectorSet& lhs, const VectorSet& rhs);
126 #endif // SHARE_LIBADT_VECTSET_HPP
|