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 <gavin.halliday@lexisnexis.com>
  • Loading branch information
ghalliday committed Nov 8, 2024
1 parent ac7dd63 commit 2967017
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions system/jlib/jarray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,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 2967017

Please sign in to comment.