git-svn-id: svn://db.shs.com.ru/pip@283 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
/*! \file pideque.h
|
||||
* \brief Dynamic array of any type
|
||||
*
|
||||
*
|
||||
* This file declares PIDeque
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Dynamic array of any type
|
||||
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Dynamic array of any type
|
||||
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIDEQUE_H
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
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);
|
||||
//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) {
|
||||
PIINTROSPECTION_CONTAINER_NEW()
|
||||
@@ -278,7 +278,7 @@ public:
|
||||
pid_size -= count;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void swap(PIDeque<T> & other) {
|
||||
piSwap<T*>(pid_data, other.pid_data);
|
||||
piSwap<size_t>(pid_size, other.pid_size);
|
||||
@@ -291,7 +291,7 @@ public:
|
||||
PIDeque<T> & sort(CompareFunc compare = compare_func) {qsort(pid_data + pid_start, pid_size, sizeof(T), (int(*)(const void * , const void * ))compare); return *this;}
|
||||
|
||||
PIDeque<T> & enlarge(llong pid_size) {llong ns = size_s() + pid_size; if (ns <= 0) clear(); else resize(size_t(ns)); return *this;}
|
||||
|
||||
|
||||
PIDeque<T> & removeOne(const T & v) {for (size_t i = 0; i < pid_size; ++i) if (pid_data[i + pid_start] == v) {remove(i); return *this;} return *this;}
|
||||
PIDeque<T> & removeAll(const T & v) {for (llong i = 0; i < pid_size; ++i) if (pid_data[i + pid_start] == v) {remove(i); --i;} return *this;}
|
||||
|
||||
@@ -310,13 +310,13 @@ public:
|
||||
|
||||
PIDeque<T> & pop_back() {if (pid_size == 0) return *this; resize(pid_size - 1); return *this;}
|
||||
PIDeque<T> & pop_front() {if (pid_size == 0) return *this; remove(0); return *this;}
|
||||
|
||||
|
||||
T take_back() {T t(back()); pop_back(); return t;}
|
||||
T take_front() {T t(front()); pop_front(); return t;}
|
||||
|
||||
|
||||
template <typename ST>
|
||||
PIDeque<ST> toType() const {PIDeque<ST> ret(pid_size); for (uint i = 0; i < pid_size; ++i) ret[i] = ST(pid_data[i + pid_start]); return ret;}
|
||||
|
||||
|
||||
private:
|
||||
void _reset() {pid_size = pid_rsize = pid_start = 0; pid_data = 0;}
|
||||
/*void * qmemmove(void * dst, void * src, size_t size) {
|
||||
@@ -457,7 +457,7 @@ private:
|
||||
//checkMove(direction);
|
||||
//printf("%X alloc new start %d\n", this, pid_start);
|
||||
}
|
||||
|
||||
|
||||
T * pid_data;
|
||||
volatile size_t pid_size, pid_rsize;
|
||||
volatile ssize_t pid_start;
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
/*! \file pivector.h
|
||||
* \brief Dynamic array of any type
|
||||
*
|
||||
*
|
||||
* This file declares PIVector
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Dynamic array of any type
|
||||
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Dynamic array of any type
|
||||
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIVECTOR_H
|
||||
@@ -258,7 +258,7 @@ public:
|
||||
piv_size -= count;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void swap(PIVector<T> & other) {
|
||||
piSwap<T*>(piv_data, other.piv_data);
|
||||
piSwap<size_t>(piv_size, other.piv_size);
|
||||
@@ -270,7 +270,7 @@ public:
|
||||
PIVector<T> & sort(CompareFunc compare = compare_func) {qsort(piv_data, piv_size, sizeof(T), (int(*)(const void * , const void * ))compare); return *this;}
|
||||
|
||||
PIVector<T> & enlarge(llong piv_size) {llong ns = size_s() + piv_size; if (ns <= 0) clear(); else resize(size_t(ns)); return *this;}
|
||||
|
||||
|
||||
PIVector<T> & removeOne(const T & v) {for (size_t i = 0; i < piv_size; ++i) if (piv_data[i] == v) {remove(i); return *this;} return *this;}
|
||||
PIVector<T> & removeAll(const T & v) {for (llong i = 0; i < piv_size; ++i) if (piv_data[i] == v) {remove(i); --i;} return *this;}
|
||||
|
||||
@@ -289,13 +289,13 @@ public:
|
||||
|
||||
PIVector<T> & pop_back() {if (piv_size == 0) return *this; resize(piv_size - 1); return *this;}
|
||||
PIVector<T> & pop_front() {if (piv_size == 0) return *this; remove(0); return *this;}
|
||||
|
||||
|
||||
T take_back() {T t(back()); pop_back(); return t;}
|
||||
T take_front() {T t(front()); pop_front(); return t;}
|
||||
|
||||
|
||||
template <typename ST>
|
||||
PIVector<ST> toType() const {PIVector<ST> ret(piv_size); for (uint i = 0; i < piv_size; ++i) ret[i] = ST(piv_data[i]); return ret;}
|
||||
|
||||
|
||||
private:
|
||||
void _reset() {piv_size = piv_rsize = 0; piv_data = 0;}
|
||||
size_t asize(size_t s) {
|
||||
@@ -354,7 +354,7 @@ private:
|
||||
piv_size = new_size;
|
||||
size_t as = asize(new_size);
|
||||
if (as == piv_rsize) return;
|
||||
|
||||
|
||||
//cout << std::hex << " ![("<<this<<")realloc " << piv_data << " data ... <\n" << endl;
|
||||
T * p_d = (T*)(realloc(piv_data, as*sizeof(T)));
|
||||
assert(p_d);
|
||||
@@ -441,7 +441,7 @@ class PIP_EXPORT PIVector: public vector<T, Allocator> {
|
||||
typedef PIVector<T, Allocator> _CVector;
|
||||
typedef vector<T, Allocator> _stlc;
|
||||
public:
|
||||
|
||||
|
||||
PIVector() {piMonitor.containers++;}
|
||||
PIVector(uint size, const T & value = T()) {piMonitor.containers++; _stlc::resize(size, value);}
|
||||
~PIVector() {piMonitor.containers--;}
|
||||
@@ -454,17 +454,17 @@ public:
|
||||
#ifdef DOXYGEN
|
||||
uint size() const;
|
||||
#endif
|
||||
|
||||
|
||||
int size_s() const {return static_cast<int>(_stlc::size());}
|
||||
bool isEmpty() const {return _stlc::empty();}
|
||||
bool has(const T & t) const {for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); ++i) if (t == *i) return true; return false;}
|
||||
int etries(const T & t) const {int ec = 0; for (typename _stlc::const_iterator i = _stlc::begin(); i != _stlc::end(); ++i) if (t == *i) ++ec; return ec;}
|
||||
|
||||
|
||||
typedef int (*CompareFunc)(const T * , const T * );
|
||||
|
||||
|
||||
static int compare_func(const T * t0, const T * t1) {return (*t0) == (*t1) ? 0 : ((*t0) < (*t1) ? -1 : 1);}
|
||||
#ifdef DOXYGEN
|
||||
|
||||
|
||||
void resize(uint size, const T & new_type = T());
|
||||
PIVector<T, Allocator> & enlarge(uint size);
|
||||
void clear();
|
||||
@@ -493,7 +493,7 @@ public:
|
||||
bool operator ==(const PIVector<T, Allocator> & t) {for (uint i = 0; i < _stlc::size(); ++i) if (t[i] != at(i)) return false; return true;}
|
||||
bool operator !=(const PIVector<T, Allocator> & t) {for (uint i = 0; i < _stlc::size(); ++i) if (t[i] != at(i)) return true; return false;}
|
||||
bool contains(const T & v) const {for (uint i = 0; i < _stlc::size(); ++i) if (v == at(i)) return true; return false;}
|
||||
|
||||
|
||||
#else
|
||||
_CVector & enlarge(int size_) {int ns = size_s() + size_; if (ns <= 0) _stlc::clear(); else _stlc::resize(ns); return *this;}
|
||||
_CVector & sort(CompareFunc compare = compare_func) {qsort(&at(0), _stlc::size(), sizeof(T), (int(*)(const void * , const void * ))compare); return *this;}
|
||||
|
||||
Reference in New Issue
Block a user