Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC-32971 Add removeAndSwapLast(n) to the array classes #19285

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading