79 Array() : N(0), NMax(0), Vals(nullptr) { }
89 Array(
Index init_N,
const T &init_val) : N(0), NMax(0), Vals(nullptr) {
103 template<
typename Iterator>
107 N(0), NMax(0), Vals(nullptr) {
109 reserve(std::distance(begin, end));
111 for(; it !=
end; ++it)
116 Array(std::initializer_list<T> in) :
117 N(0), NMax(0), Vals(nullptr) {
120 auto it = in.begin();
121 for(; it != in.end(); ++it)
133 operator delete(
Vals);
158 assert(ind >= 0 && ind < N);
163 assert(ind >= 0 && ind < N);
168 assert(ind >= 0 && ind < N);
173 assert(ind >= 0 && ind < N);
213 if(N) Vals[--
N].~T();
215 void remove(
Index ind);
217 while(N) Vals[--
N].~T();
224 template <
typename CompareType>
243 const T &
max()
const;
244 const T &
min()
const;
261 return !((*this) == RHS);
263 bool operator<(const Array<T> &RHS)
const;
265 bool operator<=(const Array<T> &RHS)
const {
266 return !((*this) > RHS);
269 return !((*this) < RHS);
282 return find(test_elem) <
N;
289 void print_column(std::ostream &stream,
const std::string &indent =
"")
const;
305 for(
int i = 0; i < json.
size(); i++)
318 class ReturnArray :
public Array<T> {
345 if(!(initial <=
final))
350 while(seq.
back() <
final) {
366 if(seq[0] < seq[1]) {
369 if(
final < initial) {
375 while(seq.
back() <
final) {
377 seq.
back() += increment;
379 if(
final < seq.
back())
383 else if(seq[1] < seq[0]) {
386 if(initial <
final) {
392 while(
final < seq.
back()) {
394 seq.
back() += increment;
396 if(seq.
back() <
final)
402 if(initial <
final ||
final < initial)
418 if(NMax < RHS.
size()) {
421 for(i = 0; i < RHS.
size(); i++)
426 while(N > RHS.
size())
431 while(N < RHS.
size())
450 if(
this == &RHS)
return;
452 Index tN(N), tNMax(NMax);
473 new(Vals + (N++)) T();
485 new(Vals + (N++)) T(fill_val);
493 if(new_max <= N)
return;
497 tVal =
static_cast<T *
>(
operator new(new_max *
sizeof(T)));
498 for(
Index i = 0; i < N; i++) {
499 new(tVal + i) T(Vals[i]);
504 operator delete(Vals);
517 Index new_Max = (N * ARRAY_EXTENSION_FACTOR() > N + ARRAY_MIN_EXTRA_SPACE()) ?
518 (
Index)(N * ARRAY_EXTENSION_FACTOR()) : N + ARRAY_MIN_EXTRA_SPACE();
522 tVal =
static_cast<T *
>(
operator new(new_Max *
sizeof(T)));
525 new(tVal + N) T(toPush);
526 for(
Index i = 0; i < N; i++) {
527 new(tVal + i) T(Vals[i]);
532 operator delete(Vals);
539 new(Vals + (N++)) T(toPush);
548 for(
Index i = ind + 1; i < N; i++)
563 for(i = 0; i < N; i++) {
564 if(!(at(i) == RHS[i])) {
575 if(size() != RHS.
size())
576 return size() < RHS.
size();
578 for(
Index i = 0; i < size(); i++) {
581 else if(at(i) > RHS[i])
590 if(size() != RHS.
size())
591 return size() > RHS.
size();
593 for(
Index i = 0; i < size(); i++) {
596 else if(at(i) < RHS[i])
606 std::cerr <<
"ERROR: Tried to find maximum value of empty array! Exiting...\n";
613 for(
Index i = 1; i < size(); i++) {
625 std::cerr <<
"ERROR: Tried to find minimum value of empty array! Exiting...\n";
631 for(
Index i = 1; i < size(); i++) {
643 for(
Index i = 0; i < size(); i++) {
653 assert(ind_begin <= ind_end && ind_end < size() &&
"Array::operator() indices out of bounds!");
655 sub.
reserve(ind_end - ind_begin);
656 while(ind_begin <= ind_end) {
665 for(
Index i = 0; i < N; i++) {
681 for(
Index i = 0; i < N; i++) {
692 template<
typename T>
695 for(
Index i = 0; i < N; i++) {
696 if(at(i) == test_elem) {
706 template<
typename T>
708 for(
Index i = 0; i < N; i++) {
709 if(at(i) == test_elem) {
719 template<
typename T>
721 for(
Index i = N - 1; i >= 0; i--) {
722 if(at(i) == test_elem) {
732 template<
typename T>
734 for(
Index i = 0; i < N; i++) {
744 template<
typename T>
746 for(
Index i = 0; i < N; i++)
747 stream << indent << at(i) << std::endl;
751 template<
typename T>
753 for(
Index i = N - 1; i >= 0; i--) {
764 template<
typename T>
765 template <
typename CompareType>
772 int left, right, middle, pivot, curr, i;
776 int cap = (int) 3 * (
log(size()) /
log(2));
788 left = queue_left[0];
789 right = queue_right[0];
799 middle = left + (right - left) / 2;
802 if(comp.compare(at(left), at(middle))) {
803 if(comp.compare(at(middle), at(right))) pivot = middle;
805 if(comp.compare(at(left), at(right))) pivot = right;
810 if(comp.compare(at(right), at(middle))) pivot = middle;
812 if(comp.compare(at(right), at(left))) pivot = right;
819 swap_elem(pivot, right);
823 for(i = left; i < right; i++) {
824 if(comp.compare(at(i) , at(right))) {
831 swap_elem(curr, right);
837 if(left != curr - 1) {
844 if(curr + 1 != right) {
852 if(queue_left.
size() > max_q)
853 max_q = queue_left.
size();
857 while(queue_left.
size() > 0);
868 for(
Index i = 0; i < size(); i++)
871 for(
Index i = 0; i < size(); i++) {
872 for(
Index j = i + 1; j < size(); j++) {
886 for(
Index i = 0; i < size(); i++) {
887 for(
Index j = i + 1; j < size(); j++) {
898 reserve(size() + new_tail.
size());
900 for(
Index i = 0; i < Nadd; i++)
901 push_back(new_tail[i]);
910 for(
Index i = 0; i < Nadd; i++) {
912 push_back(new_tail[i]);
924 assert(perm_array.
size() == size());
927 for(
Index i = 0; i < perm_array.
size(); i++)
928 after_array.push_back(at(perm_array[i]));
941 assert(perm_array.
size() == size());
944 for(
Index i = 0; i < perm_array.
size(); i++) {
945 if(i != perm_array[i]) {
946 after_array[perm_array[i]] = at(i);
957 Index i(N - 2), j(N - 1);
958 bool is_valid =
true;
963 while(at(j) <= at(i))
988 for(
Index i = 0; i < size(); i++) {
989 iperm_array[at(i)] = i;
1003 template<
typename T>
1005 return ((trans_perm.
as_perm_inverse()).permute(*
this)).permute(trans_perm);
1010 template<
typename T>
1012 for(
Index i = 0; i < N - 1; i++) {
1013 if(at(i + 1) < at(i))
1022 template<
typename T>
1024 for(
Index i = 0; i < N - 1; i++) {
1025 if(at(i) < at(i + 1))
1034 template<
typename T>
1036 for(
Index i = 0; i < N - 1; i++) {
1037 if(!(at(i) == at(i + 1)))
1048 template<
typename T>
1050 for(
Index i = 0; i < size(); i++) {
1051 if(at(i) < 0 || at(i) >= size() ||
find(at(i)) < i)
1060 template<
typename T>
1062 for(
Index i = 0; i < size(); i++) {
1079 std::ostream &operator<<(std::ostream &out, const Array<T> &array_out) {
1080 if(array_out.size() == 0)
1082 for(
Index i = 0; i < array_out.size(); i++) {
1083 out << array_out[i] <<
" ";
1105 template<
typename T>
1115 template <
typename T>
const T & operator[](Index ind) const
size_type size() const
Returns array size if *this is a JSON array, object size if *this is a JSON object, 1 otherwise.
ReturnArray & operator=(Array< T > &RHS)
static Index ARRAY_MIN_EXTRA_SPACE()
bool contains(const T &test_elem) const
void from_json(ClexDescription &desc, const jsonParser &json)
bool has_fixed_points() const
Checks whether any values are equal to their index – only valid for Array ...
ReturnArray< Index > as_perm_transform_by(const Array< Index > &trans_perm) const
bool almost_contains(const T &test_elem, double tol_val=TOL) const
Index coincidence(const Array &superset) const
void push_back(const T &toPush)
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
static double ARRAY_EXTENSION_FACTOR()
bool operator<(const Array< T > &RHS) const
Array(Iterator begin, Iterator end, typename CASM_TMP::enable_if_iterator< Iterator >::type *=nullptr)
Eigen::VectorXd comp(const Configuration &config)
Returns parametric composition, as calculated using PrimClex::param_comp.
void swap(Array< T > &RHS)
static ReturnArray< T > sequence(const T &initial, const T &final)
Returns an array with the sequence (initial, ++initial, ..., final), inclusive.
Array & operator=(const Array &RHS)
Index almost_reverse_find(const T &test_elem, double tol_val=TOL) const
Same as almost_find, but start from the last element of the Array.
Array(std::initializer_list< T > in)
void swap(ConfigDoF &A, ConfigDoF &B)
bool operator!=(const Array< T > &RHS) const
Index reverse_find(const T &test_elem) const
Same as find, but starts from the last element of the Array.
EigenIndex Index
For long integer indexing:
Array & append_unique(const Array &new_tail)
Array & ipermute(const Array< Index > &perm_array)
Iterator find(Iterator begin, Iterator end, const T &value, BinaryCompare q)
Equivalent to std::find(begin, end, value), but with custom comparison.
void swap(Array< T > &A1, Array< T > &A2)
T & operator[](Index ind)
void swap_elem(Index i, Index j)
Index find(const T &test_elem) const
bool operator>(const Array< T > &RHS) const
Array & append(const Array &new_tail)
bool operator>=(const Array< T > &RHS) const
bool compare(const Array< T > &a, const Array< T > &b) const
bool all_in(const Array &superset) const
bool is_ascending() const
Index incidences(const T &test_elem) const
void reserve(Index new_max)
ReturnArray< T > sub_array(Index ind_begin, Index ind_end) const
jsonParser & push_back(const T &value)
Puts new valued element at end of array of any type T for which 'jsonParser& to_json( const T &value...
void print_column(std::ostream &stream, const std::string &indent="") const
Index almost_find(const T &test_elem, double tol_val=TOL) const
bool is_descending() const
ReturnArray(Array< T > &init_tens)
const T & at(Index ind) const
std::enable_if< is_iterator< T >::type::value, void > enable_if_iterator
Template alias to enable a template function via SFINAE for any iterator.
Array(Index init_N, const T &init_val)
bool contains(const Container &container, const T &value)
Equivalent to container.end() != std::find(container.begin(), container.end(), value) ...
Array< T > array_cat(const Array< T > &A1, const Array< T > &A2)
Basic std::vector like container (deprecated)
jsonParser & put_array()
Puts new empty JSON array.
bool operator==(const Array< T > &RHS) const
ReturnArray< Index > as_perm_inverse() const
bool almost_equal(const GenericCluster< CoordType > &LHS, const GenericCluster< CoordType > &RHS, double tol)
Array & permute(const Array< Index > &perm_array)
bool valid_index(Index i)