mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
update localvector
This commit is contained in:
parent
189b2725a0
commit
a8f83dd6f0
@ -9,6 +9,10 @@
|
|||||||
namespace Limonp
|
namespace Limonp
|
||||||
{
|
{
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
/*
|
||||||
|
* LocalVector<T> : T must be primitive type (char , int, size_t), if T is struct or class, LocalVector<T> may be dangerous..
|
||||||
|
* LocalVector<T> is simple and not well-tested.
|
||||||
|
*/
|
||||||
const size_t LOCAL_VECTOR_BUFFER_SIZE = 16;
|
const size_t LOCAL_VECTOR_BUFFER_SIZE = 16;
|
||||||
template <class T>
|
template <class T>
|
||||||
class LocalVector
|
class LocalVector
|
||||||
@ -92,13 +96,11 @@ namespace Limonp
|
|||||||
}
|
}
|
||||||
void push_back(const T& t)
|
void push_back(const T& t)
|
||||||
{
|
{
|
||||||
if(!full())
|
if(_size == _capacity)
|
||||||
{
|
{
|
||||||
_ptr[_size++] = t;
|
assert(_capacity);
|
||||||
return ;
|
reserve(_capacity * 2);
|
||||||
}
|
}
|
||||||
assert(_capacity);
|
|
||||||
reserve(_capacity * 2);
|
|
||||||
_ptr[_size ++ ] = t;
|
_ptr[_size ++ ] = t;
|
||||||
}
|
}
|
||||||
void reserve(size_t size)
|
void reserve(size_t size)
|
||||||
@ -118,10 +120,6 @@ namespace Limonp
|
|||||||
free(old);
|
free(old);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool full() const
|
|
||||||
{
|
|
||||||
return size() == capacity();
|
|
||||||
}
|
|
||||||
bool empty() const
|
bool empty() const
|
||||||
{
|
{
|
||||||
return 0 == size();
|
return 0 == size();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user