Skip to content

Commit

Permalink
HPCC-32971 Add removeAndSwapLast(n) to the array classes
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday committed Nov 21, 2024
1 parent 92149e3 commit a1a957f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions system/jlib/jarray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define JARRAY_HPP

#include <new>
#include <utility>

#include "platform.h"
#include "jiface.hpp"
Expand Down Expand Up @@ -281,6 +282,18 @@ class ArrayOf : public AllocatorOf<sizeof(MEMBER)>
if (!nodestruct) SELF::destruct(pos);
SELF::_move( pos, pos + 1, ( SELF::used - pos ) );
}
//Remove the element at pos and move the last element to pos - to avoid moving all elements
void removeAndSwapLast(aindex_t pos, bool nodestruct = false)
{
assertex(pos < SELF::used);
SELF::used --;
if (!nodestruct) SELF::destruct(pos);
if (pos != SELF::used)
{
MEMBER * head = (MEMBER *)SELF::_head;
head[pos] = std::move(head[SELF::used]);
}
}
void removen(aindex_t pos, aindex_t num, bool nodestruct = false)
{
assertex(pos + num <= SELF::used);
Expand Down

0 comments on commit a1a957f

Please sign in to comment.