< prev index next > src/hotspot/share/libadt/vectset.cpp
Print this page
/*
! * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
/*
! * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
}
void VectorSet::init(Arena* arena) {
_size = 2;
_data = NEW_ARENA_ARRAY(arena, uint32_t, 2);
- _data_size = 2;
_set_arena = arena;
_data[0] = 0;
_data[1] = 0;
}
// Expand the existing set to a bigger size
void VectorSet::grow(uint new_word_capacity) {
assert(new_word_capacity < (1U << 30), "");
uint x = next_power_of_2(new_word_capacity);
! if (x > _data_size) {
_data = REALLOC_ARENA_ARRAY(_set_arena, uint32_t, _data, _size, x);
! _data_size = x;
}
- Copy::zero_to_bytes(_data + _size, (x - _size) * sizeof(uint32_t));
- _size = x;
}
// Insert a member into an existing Set.
void VectorSet::insert(uint elem) {
uint32_t word = elem >> word_bits;
}
void VectorSet::init(Arena* arena) {
_size = 2;
_data = NEW_ARENA_ARRAY(arena, uint32_t, 2);
_set_arena = arena;
_data[0] = 0;
_data[1] = 0;
}
// Expand the existing set to a bigger size
void VectorSet::grow(uint new_word_capacity) {
assert(new_word_capacity < (1U << 30), "");
uint x = next_power_of_2(new_word_capacity);
! if (x > _size) {
_data = REALLOC_ARENA_ARRAY(_set_arena, uint32_t, _data, _size, x);
! Copy::zero_to_bytes(_data + _size, (x - _size) * sizeof(uint32_t));
+ _size = x;
}
}
// Insert a member into an existing Set.
void VectorSet::insert(uint elem) {
uint32_t word = elem >> word_bits;
return false;
}
}
return true;
}
+
+ #ifndef PRODUCT
+ void VectorSet::print_on(outputStream* st) const {
+ st->print("VectorSet(" PTR_FORMAT ")", p2i(this));
+ if (is_empty()) {
+ st->print_cr(" empty");
+ return;
+ }
+
+ bool first = false;
+ for (uint i = 0; i < (_size << word_bits); ++i) {
+ if (test(i)) {
+ if (!first) {
+ st->print(" [%u", i);
+ first = true;
+ } else {
+ st->print(",%u", i);
+ }
+ }
+ }
+ st->print_cr("]");
+ }
+ #endif
+
+ VectorSet intersect(const VectorSet& lhs, const VectorSet& rhs) {
+ VectorSet result;
+ uint min;
+ if (lhs._size > rhs._size) {
+ result.grow(lhs._size);
+ min = rhs._size;
+ } else {
+ result.grow(rhs._size);
+ min = lhs._size;
+ }
+ for (uint i = 0; i < min; ++i) {
+ result._data[i] = lhs._data[i] & rhs._data[i];
+ }
+ return result;
+ }
< prev index next >