/usr/include/gecode/support/dynamic-array.hpp is in libgecode-dev 5.1.0-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2002
*
* Last modified:
* $Date: 2016-06-18 14:20:49 +0200 (Sat, 18 Jun 2016) $ by $Author: schulte $
* $Revision: 15118 $
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <algorithm>
namespace Gecode { namespace Support {
/**
* \brief Array with arbitrary number of elements
*
* \ingroup FuncSupport
*/
template<class T, class A>
class DynamicArray {
private:
/// Memory allocator
A& a;
/// Size of array
int n;
/// Array elements
T* x;
/// Resize to at least \a n + 1 elements
void resize(int n);
public:
/// Initialize with size \a n
DynamicArray(A& a0, int n = 32);
/// Initialize with size \a n
DynamicArray(A& a0, unsigned int n);
/// Copy elements from array \a da
DynamicArray(const DynamicArray<T,A>& da);
/// Release memory
~DynamicArray(void);
/// Assign array (copy elements from \a a)
const DynamicArray<T,A>& operator =(const DynamicArray<T,A>& da);
/// Return element at position \a i (possibly resize)
T& operator [](int i);
/// Return element at position \a i (possibly resize)
T& operator [](unsigned int i);
/// Return element at position \a i
const T& operator [](int i) const;
/// Return element at position \a i
const T& operator [](unsigned int i) const;
/// Cast in to pointer of type \a T
operator T*(void);
};
template<class T, class A>
forceinline
DynamicArray<T,A>::DynamicArray(A& a0, int n0)
: a(a0), n(n0), x(a.template alloc<T>(n)) {}
template<class T, class A>
forceinline
DynamicArray<T,A>::DynamicArray(A& a0, unsigned int n0)
: a(a0), n(static_cast<int>(n0)), x(a.template alloc<T>(n)) {}
template<class T, class A>
forceinline
DynamicArray<T,A>::DynamicArray(const DynamicArray<T,A>& da)
: a(da.a), n(da.n), x(a.template alloc<T>(n)) {
(void) heap.copy<T>(x,da.x,n);
}
template<class T, class A>
forceinline
DynamicArray<T,A>::~DynamicArray(void) {
a.free(x,n);
}
template<class T, class A>
forceinline const DynamicArray<T,A>&
DynamicArray<T,A>::operator =(const DynamicArray<T,A>& da) {
if (this != &da) {
if (n < da.n) {
a.free(x,n); n = da.n; x = a.template alloc<T>(n);
}
(void) heap.copy(x,da.x,n);
}
return *this;
}
template<class T, class A>
void
DynamicArray<T,A>::resize(int i) {
int m = std::max(i+1, (3*n)/2);
x = a.realloc(x,n,m);
n = m;
}
template<class T, class A>
forceinline T&
DynamicArray<T,A>::operator [](int i) {
if (i >= n) resize(i);
assert(n > i);
return x[i];
}
template<class T, class A>
forceinline T&
DynamicArray<T,A>::operator [](unsigned int i) {
return operator [](static_cast<int>(i));
}
template<class T, class A>
forceinline const T&
DynamicArray<T,A>::operator [](int i) const {
assert(n > i);
return x[i];
}
template<class T, class A>
forceinline const T&
DynamicArray<T,A>::operator [](unsigned int i) const {
return operator [](static_cast<int>(i));
}
template<class T, class A>
forceinline
DynamicArray<T,A>::operator T*(void) {
return x;
}
}}
// STATISTICS: support-any
|