Ported sort() for poolVectors from 7b8b91f505 .

This commit is contained in:
Relintai 2022-07-29 21:18:44 +02:00
parent 8107f6fea6
commit 9af3a7a709
11 changed files with 76 additions and 0 deletions

View File

@ -462,6 +462,7 @@ public:
}
void invert();
void sort();
void operator=(const PoolVector &p_pool_vector) {
_reference(p_pool_vector);
@ -718,4 +719,16 @@ void PoolVector<T>::invert() {
}
}
template <class T>
void PoolVector<T>::sort() {
int len = size();
if (len == 0) {
return;
}
Write w = write();
SortArray<T> sorter;
sorter.sort(w.ptr(), len);
}
#endif // POOL_VECTOR_H

View File

@ -771,6 +771,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(PoolByteArray, count);
VCALL_LOCALMEM1R(PoolByteArray, has);
VCALL_LOCALMEM0(PoolByteArray, clear);
VCALL_LOCALMEM0(PoolByteArray, sort);
VCALL_LOCALMEM0R(PoolIntArray, size);
VCALL_LOCALMEM0R(PoolIntArray, empty);
@ -790,6 +791,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(PoolIntArray, count);
VCALL_LOCALMEM1R(PoolIntArray, has);
VCALL_LOCALMEM0(PoolIntArray, clear);
VCALL_LOCALMEM0(PoolIntArray, sort);
VCALL_LOCALMEM0R(PoolRealArray, size);
VCALL_LOCALMEM0R(PoolRealArray, empty);
@ -809,6 +811,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(PoolRealArray, count);
VCALL_LOCALMEM1R(PoolRealArray, has);
VCALL_LOCALMEM0(PoolRealArray, clear);
VCALL_LOCALMEM0(PoolRealArray, sort);
VCALL_LOCALMEM0R(PoolStringArray, size);
VCALL_LOCALMEM0R(PoolStringArray, empty);
@ -829,6 +832,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(PoolStringArray, count);
VCALL_LOCALMEM1R(PoolStringArray, has);
VCALL_LOCALMEM0(PoolStringArray, clear);
VCALL_LOCALMEM0(PoolStringArray, sort);
VCALL_LOCALMEM0R(PoolVector2Array, size);
VCALL_LOCALMEM0R(PoolVector2Array, empty);
@ -848,6 +852,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(PoolVector2Array, count);
VCALL_LOCALMEM1R(PoolVector2Array, has);
VCALL_LOCALMEM0(PoolVector2Array, clear);
VCALL_LOCALMEM0(PoolVector2Array, sort);
VCALL_LOCALMEM0R(PoolVector2iArray, size);
VCALL_LOCALMEM0R(PoolVector2iArray, empty);
@ -867,6 +872,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(PoolVector2iArray, count);
VCALL_LOCALMEM1R(PoolVector2iArray, has);
VCALL_LOCALMEM0(PoolVector2iArray, clear);
VCALL_LOCALMEM0(PoolVector2iArray, sort);
VCALL_LOCALMEM0R(PoolVector3Array, size);
VCALL_LOCALMEM0R(PoolVector3Array, empty);
@ -886,6 +892,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(PoolVector3Array, count);
VCALL_LOCALMEM1R(PoolVector3Array, has);
VCALL_LOCALMEM0(PoolVector3Array, clear);
VCALL_LOCALMEM0(PoolVector3Array, sort);
VCALL_LOCALMEM0R(PoolVector3iArray, size);
VCALL_LOCALMEM0R(PoolVector3iArray, empty);
@ -905,6 +912,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(PoolVector3iArray, count);
VCALL_LOCALMEM1R(PoolVector3iArray, has);
VCALL_LOCALMEM0(PoolVector3iArray, clear);
VCALL_LOCALMEM0(PoolVector3iArray, sort);
VCALL_LOCALMEM0R(PoolColorArray, size);
VCALL_LOCALMEM0R(PoolColorArray, empty);
@ -924,6 +932,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(PoolColorArray, count);
VCALL_LOCALMEM1R(PoolColorArray, has);
VCALL_LOCALMEM0(PoolColorArray, clear);
VCALL_LOCALMEM0(PoolColorArray, sort);
#define VCALL_PTR0(m_type, m_method) \
static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { \
@ -2303,6 +2312,7 @@ void register_variant_methods() {
ADDFUNC1R(POOL_BYTE_ARRAY, INT, PoolByteArray, count, INT, "value", varray());
ADDFUNC1R(POOL_BYTE_ARRAY, BOOL, PoolByteArray, has, INT, "value", varray());
ADDFUNC0(POOL_BYTE_ARRAY, NIL, PoolByteArray, clear, varray());
ADDFUNC0(POOL_BYTE_ARRAY, NIL, PoolByteArray, sort, varray());
ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_ascii, varray());
ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_utf8, varray());
@ -2328,6 +2338,7 @@ void register_variant_methods() {
ADDFUNC1R(POOL_INT_ARRAY, INT, PoolIntArray, count, INT, "value", varray());
ADDFUNC1R(POOL_INT_ARRAY, BOOL, PoolIntArray, has, INT, "value", varray());
ADDFUNC0(POOL_INT_ARRAY, NIL, PoolIntArray, clear, varray());
ADDFUNC0(POOL_INT_ARRAY, NIL, PoolIntArray, sort, varray());
ADDFUNC0R(POOL_REAL_ARRAY, INT, PoolRealArray, size, varray());
ADDFUNC0R(POOL_REAL_ARRAY, BOOL, PoolRealArray, empty, varray());
@ -2346,6 +2357,7 @@ void register_variant_methods() {
ADDFUNC1R(POOL_REAL_ARRAY, INT, PoolRealArray, count, REAL, "value", varray());
ADDFUNC1R(POOL_REAL_ARRAY, BOOL, PoolRealArray, has, REAL, "value", varray());
ADDFUNC0(POOL_REAL_ARRAY, NIL, PoolRealArray, clear, varray());
ADDFUNC0(POOL_REAL_ARRAY, NIL, PoolRealArray, sort, varray());
ADDFUNC0R(POOL_STRING_ARRAY, INT, PoolStringArray, size, varray());
ADDFUNC0R(POOL_STRING_ARRAY, BOOL, PoolStringArray, empty, varray());
@ -2365,6 +2377,7 @@ void register_variant_methods() {
ADDFUNC1R(POOL_STRING_ARRAY, INT, PoolStringArray, count, STRING, "value", varray());
ADDFUNC1R(POOL_STRING_ARRAY, BOOL, PoolStringArray, has, STRING, "value", varray());
ADDFUNC0(POOL_STRING_ARRAY, NIL, PoolStringArray, clear, varray());
ADDFUNC0(POOL_STRING_ARRAY, NIL, PoolStringArray, sort, varray());
ADDFUNC0R(POOL_VECTOR2_ARRAY, INT, PoolVector2Array, size, varray());
ADDFUNC0R(POOL_VECTOR2_ARRAY, BOOL, PoolVector2Array, empty, varray());
@ -2383,6 +2396,7 @@ void register_variant_methods() {
ADDFUNC1R(POOL_VECTOR2_ARRAY, INT, PoolVector2Array, count, VECTOR2, "value", varray());
ADDFUNC1R(POOL_VECTOR2_ARRAY, BOOL, PoolVector2Array, has, VECTOR2, "value", varray());
ADDFUNC0(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, clear, varray());
ADDFUNC0(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, sort, varray());
ADDFUNC0R(POOL_VECTOR2I_ARRAY, INT, PoolVector2iArray, size, varray());
ADDFUNC0R(POOL_VECTOR2I_ARRAY, BOOL, PoolVector2iArray, empty, varray());
@ -2401,6 +2415,7 @@ void register_variant_methods() {
ADDFUNC1R(POOL_VECTOR2I_ARRAY, INT, PoolVector2iArray, count, VECTOR2I, "value", varray());
ADDFUNC1R(POOL_VECTOR2I_ARRAY, BOOL, PoolVector2iArray, has, VECTOR2I, "value", varray());
ADDFUNC0(POOL_VECTOR2I_ARRAY, NIL, PoolVector2iArray, clear, varray());
ADDFUNC0(POOL_VECTOR2I_ARRAY, NIL, PoolVector2iArray, sort, varray());
ADDFUNC0R(POOL_VECTOR3_ARRAY, INT, PoolVector3Array, size, varray());
ADDFUNC0R(POOL_VECTOR3_ARRAY, BOOL, PoolVector3Array, empty, varray());
@ -2419,6 +2434,7 @@ void register_variant_methods() {
ADDFUNC1R(POOL_VECTOR3_ARRAY, INT, PoolVector3Array, count, VECTOR3, "value", varray());
ADDFUNC1R(POOL_VECTOR3_ARRAY, BOOL, PoolVector3Array, has, VECTOR3, "value", varray());
ADDFUNC0(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, clear, varray());
ADDFUNC0(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, sort, varray());
ADDFUNC0R(POOL_VECTOR3I_ARRAY, INT, PoolVector3iArray, size, varray());
ADDFUNC0R(POOL_VECTOR3I_ARRAY, BOOL, PoolVector3iArray, empty, varray());
@ -2437,6 +2453,7 @@ void register_variant_methods() {
ADDFUNC1R(POOL_VECTOR3I_ARRAY, INT, PoolVector3iArray, count, VECTOR3I, "value", varray());
ADDFUNC1R(POOL_VECTOR3I_ARRAY, BOOL, PoolVector3iArray, has, VECTOR3I, "value", varray());
ADDFUNC0(POOL_VECTOR3I_ARRAY, NIL, PoolVector3iArray, clear, varray());
ADDFUNC0(POOL_VECTOR3I_ARRAY, NIL, PoolVector3iArray, sort, varray());
ADDFUNC0R(POOL_COLOR_ARRAY, INT, PoolColorArray, size, varray());
ADDFUNC0R(POOL_COLOR_ARRAY, BOOL, PoolColorArray, empty, varray());
@ -2455,6 +2472,7 @@ void register_variant_methods() {
ADDFUNC1R(POOL_COLOR_ARRAY, INT, PoolColorArray, count, COLOR, "value", varray());
ADDFUNC1R(POOL_COLOR_ARRAY, BOOL, PoolColorArray, has, COLOR, "value", varray());
ADDFUNC0(POOL_COLOR_ARRAY, NIL, PoolColorArray, clear, varray());
ADDFUNC0(POOL_COLOR_ARRAY, NIL, PoolColorArray, sort, varray());
//pointerbased

View File

@ -178,6 +178,11 @@
Returns the number of elements in the array.
</description>
</method>
<method name="sort">
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
<method name="subarray">
<return type="PoolByteArray" />
<argument index="0" name="from" type="int" />

View File

@ -129,6 +129,11 @@
Returns the number of elements in the array.
</description>
</method>
<method name="sort">
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>

View File

@ -131,6 +131,11 @@
Returns the number of elements in the array.
</description>
</method>
<method name="sort">
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>

View File

@ -131,6 +131,11 @@
Returns the number of elements in the array.
</description>
</method>
<method name="sort">
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>

View File

@ -137,6 +137,11 @@
Returns the number of elements in the array.
</description>
</method>
<method name="sort">
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>

View File

@ -130,6 +130,11 @@
Returns the number of elements in the array.
</description>
</method>
<method name="sort">
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>

View File

@ -65,6 +65,11 @@
<description>
</description>
</method>
<method name="sort">
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>

View File

@ -129,6 +129,11 @@
Returns the number of elements in the array.
</description>
</method>
<method name="sort">
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>

View File

@ -65,6 +65,11 @@
<description>
</description>
</method>
<method name="sort">
<description>
Sorts the elements of the array in ascending order.
</description>
</method>
</methods>
<constants>
</constants>