< prev index next > src/hotspot/share/utilities/growableArray.hpp
Print this page
#ifndef SHARE_UTILITIES_GROWABLEARRAY_HPP
#define SHARE_UTILITIES_GROWABLEARRAY_HPP
#include "memory/allocation.hpp"
+ #include "oops/array.hpp"
+ #include "oops/oop.hpp"
#include "memory/iterator.hpp"
#include "utilities/debug.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/ostream.hpp"
#include "utilities/powerOfTwo.hpp"
for (int i = 0; i < l->length(); i++) {
this->at_put_grow(this->_len, l->at(i), E());
}
}
+ void appendAll(const Array<E>* l) {
+ for (int i = 0; i < l->length(); i++) {
+ this->at_put_grow(this->_len, l->at(i), E());
+ }
+ }
+
// Binary search and insertion utility. Search array for element
// matching key according to the static compare function. Insert
// that element if not already in the list. Assumes the list is
// already sorted according to compare function.
template <int compare(const E&, const E&)> E insert_sorted(const E& key) {
const GrowableArrayView<E>* _array; // GrowableArray we iterate over
int _position; // Current position in the GrowableArray
UnaryPredicate _predicate; // Unary predicate the elements of the GrowableArray should satisfy
public:
! GrowableArrayFilterIterator(const GrowableArrayIterator<E>& begin, UnaryPredicate filter_predicate) :
! _array(begin._array), _position(begin._position), _predicate(filter_predicate) {
// Advance to first element satisfying the predicate
! while(_position != _array->length() && !_predicate(_array->at(_position))) {
++_position;
}
}
GrowableArrayFilterIterator<E, UnaryPredicate>& operator++() {
do {
// Advance to next element satisfying the predicate
++_position;
! } while(_position != _array->length() && !_predicate(_array->at(_position)));
return *this;
}
E operator*() { return _array->at(_position); }
const GrowableArrayView<E>* _array; // GrowableArray we iterate over
int _position; // Current position in the GrowableArray
UnaryPredicate _predicate; // Unary predicate the elements of the GrowableArray should satisfy
public:
! GrowableArrayFilterIterator(const GrowableArray<E>* array, UnaryPredicate filter_predicate) :
! _array(array), _position(0), _predicate(filter_predicate) {
// Advance to first element satisfying the predicate
! while(!at_end() && !_predicate(_array->at(_position))) {
++_position;
}
}
GrowableArrayFilterIterator<E, UnaryPredicate>& operator++() {
do {
// Advance to next element satisfying the predicate
++_position;
! } while(!at_end() && !_predicate(_array->at(_position)));
return *this;
}
E operator*() { return _array->at(_position); }
bool operator!=(const GrowableArrayFilterIterator<E, UnaryPredicate>& rhs) {
assert(_array == rhs._array, "iterator belongs to different array");
return _position != rhs._position;
}
+
+ bool at_end() const {
+ return _array == nullptr || _position == _array->end()._position;
+ }
};
// Arrays for basic types
typedef GrowableArray<int> intArray;
typedef GrowableArray<int> intStack;
< prev index next >