Skip to content

Commit

Permalink
Merge pull request #19285 from ghalliday/issue32971
Browse files Browse the repository at this point in the history
HPCC-32971 Add removeAndSwapLast(n) to the array classes

Reviewed-by: Mark Kelly [email protected]
Reviewed-by: Jake Smith <[email protected]>
Merged-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday authored Nov 28, 2024
2 parents 3f7492d + a1a957f commit 294a5fd
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 294a5fd

Please sign in to comment.