git-svn-id: svn://db.shs.com.ru/pip@468 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2017-04-24 19:57:30 +00:00
parent 0051d4cde9
commit 7f2fa410cf
5 changed files with 96 additions and 87 deletions

View File

@@ -35,32 +35,32 @@
template <typename T>
class PIDeque {
public:
PIDeque(): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
inline PIDeque(): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
PIINTROSPECTION_CONTAINER_NEW()
//printf("new vector 1 %p (%s) ... !{\n", this, typeid(T).name());
//printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data);
}
PIDeque(const PIDeque<T> & other): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
inline PIDeque(const PIDeque<T> & other): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
PIINTROSPECTION_CONTAINER_NEW()
//printf("new vector 2 %p (%s) ... !{\n", this, typeid(T).name());
alloc(other.pid_size, true);
newT(pid_data + pid_start, other.pid_data + other.pid_start, pid_size);
//printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data);
}
PIDeque(const T * data, size_t size): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
inline PIDeque(const T * data, size_t size): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
PIINTROSPECTION_CONTAINER_NEW()
//printf("new vector 2 %p (%s) ... !{\n", this, typeid(T).name());
alloc(size, true);
newT(pid_data + pid_start, data, pid_size);
//printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data);
}
PIDeque(size_t pid_size, const T & f = T()): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
inline PIDeque(size_t pid_size, const T & f = T()): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) {
PIINTROSPECTION_CONTAINER_NEW()
//printf("new vector 3 %p (%s) ... !{\n", this, typeid(T).name());
resize(pid_size, f);
//printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data);
}
~PIDeque() {
inline ~PIDeque() {
PIINTROSPECTION_CONTAINER_DELETE()
PIINTROSPECTION_CONTAINER_FREE((pid_rsize)*sizeof(T))
//printf("delete deque %p (%s) (s=%d, rs=%d, st=%d, d=%p) ... ~{\n", this, typeid(T).name(), int(pid_size), int(pid_rsize), int(pid_start), pid_data);
@@ -71,7 +71,7 @@ public:
//printf("}~\n");
}
PIDeque<T> & operator =(const PIDeque<T> & other) {
inline PIDeque<T> & operator =(const PIDeque<T> & other) {
if (this == &other) return *this;
deleteT(pid_data + pid_start, pid_size);
alloc(other.pid_size, true);
@@ -184,8 +184,8 @@ public:
T * data(size_t index = 0) {return &(pid_data[pid_start + index]);}
const T * data(size_t index = 0) const {return &(pid_data[pid_start + index]);}
PIDeque<T> & clear() {resize(0); return *this;}
PIDeque<T> & fill(const T & f = T()) {
inline PIDeque<T> & clear() {resize(0); return *this;}
inline PIDeque<T> & fill(const T & f = T()) {
//if (sizeof(T) == 1) memset(pid_data, f, pid_size);
deleteT(pid_data + pid_start, pid_size);
//zeroRaw(pid_data, pid_size);
@@ -193,9 +193,10 @@ public:
elementNew(pid_data + i, f);
return *this;
}
PIDeque<T> & assign(const T & f = T()) {return fill(f);}
PIDeque<T> & assign(size_t new_size, const T & f) {resize(new_size); return fill(f);}
PIDeque<T> & resize(size_t new_size, const T & f = T()) {
inline PIDeque<T> & assign(const T & f = T()) {return fill(f);}
inline PIDeque<T> & assign(size_t new_size, const T & f) {resize(new_size); return fill(f);}
inline PIDeque<T> & resize(size_t new_size, const T & f = T()) {
if (new_size < pid_size) {
deleteT(&(pid_data[new_size + pid_start]), pid_size - new_size);
pid_size = new_size;
@@ -210,7 +211,13 @@ public:
}
return *this;
}
PIDeque<T> & reserve(size_t new_size) {
inline PIDeque<T> & _resizeRaw(size_t new_size) {
piCout << "Error, \"resizeRaw()\" only allowed for simple type declared with __PIDEQUE_SIMPLE_TYPE__ macro!";
assert(0);
return *this;
}
inline PIDeque<T> & reserve(size_t new_size) {
if (new_size <= pid_rsize) return *this;
size_t os = pid_size;
alloc(new_size, true);
@@ -218,7 +225,7 @@ public:
return *this;
}
PIDeque<T> & insert(size_t index, const T & v = T()) {
inline PIDeque<T> & insert(size_t index, const T & v = T()) {
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
//piCout << "insert" << dir << index << pid_size << pid_rsize << pid_start << "!<";
if (dir) {
@@ -238,7 +245,7 @@ public:
elementNew(pid_data + pid_start + index, v);
return *this;
}
PIDeque<T> & insert(size_t index, const PIDeque<T> & other) {
inline PIDeque<T> & insert(size_t index, const PIDeque<T> & other) {
if (other.isEmpty()) return *this;
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
//piCout << this << "insert" << dir << index << pid_size << pid_rsize << pid_start << " <- " << other.size() << "!<";
@@ -261,7 +268,7 @@ public:
return *this;
}
PIDeque<T> & remove(size_t index, size_t count = 1) {
inline PIDeque<T> & remove(size_t index, size_t count = 1) {
if (count == 0) return *this;
if (index + count >= pid_size) {
resize(index);
@@ -280,7 +287,7 @@ public:
return *this;
}
void swap(PIDeque<T> & other) {
inline void swap(PIDeque<T> & other) {
piSwap<T*>(pid_data, other.pid_data);
piSwap<size_t>(pid_size, other.pid_size);
piSwap<size_t>(pid_rsize, other.pid_rsize);
@@ -384,7 +391,7 @@ private:
}
inline void elementNew(T * to, const T & from) {new(to)T(from);}
inline void elementDelete(T & from) {from.~T();}
void dealloc() {deleteRaw(pid_data);}
inline void dealloc() {deleteRaw(pid_data);}
inline void checkMove(bool direction) {
if (pid_size >= 4) {
if (pid_size < pid_rsize / 6) {
@@ -474,15 +481,19 @@ private:
}
T * pid_data;
volatile size_t pid_size, pid_rsize;
volatile ssize_t pid_start;
size_t pid_size, pid_rsize;
ssize_t pid_start;
};
#define __PIDEQUE_SIMPLE_TYPE__(T) \
template<> inline void PIDeque<T>::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(s*sizeof(T)); memcpy(dst, src, s * sizeof(T));} \
template<> inline void PIDeque<T>::deleteT(T * d, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(sz*sizeof(T));} \
template<> inline void PIDeque<T>::elementNew(T * to, const T & from) {(*to) = from;} \
template<> inline void PIDeque<T>::elementDelete(T & from) {;}
template<> inline void PIDeque<T>::elementDelete(T & from) {;} \
template<> inline PIDeque<T> & PIDeque<T>::_resizeRaw(size_t new_size) {if (new_size > pid_size) alloc(new_size, true); return *this;} \
template<> inline PIDeque<T> & PIDeque<T>::clear() {pid_size = 0; return *this;} \
template<> inline PIDeque<T> & PIDeque<T>::assign(size_t new_size, const T & f) {_resizeRaw(new_size); return fill(f);}
#else