Skip to content

Commit

Permalink
std::input_iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Nov 16, 2024
1 parent 5edace9 commit d862554
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
23 changes: 13 additions & 10 deletions include/momo/DataSelection.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace internal
};

template<typename DataRowIterator, typename RowReference>
concept conceptDataRowIterator = conceptIterator17<DataRowIterator, std::input_iterator_tag> &&
concept conceptDataRowIterator = std::input_iterator<DataRowIterator> &&
requires (DataRowIterator iter) { { *iter } -> std::convertible_to<RowReference>; };

template<typename TRawIterator, typename TRowReference>
Expand Down Expand Up @@ -599,11 +599,12 @@ namespace internal
mColumnList->GetOffset(column));
}

template<conceptDataRowIterator<RowReference> RowIterator>
void Assign(RowIterator begin, RowIterator end)
template<conceptDataRowIterator<RowReference> RowIterator,
conceptSentinel<RowIterator> RowSentinel>
void Assign(RowIterator begin, RowSentinel end)
{
size_t initCount = GetCount();
Add(begin, end); //?
Add(std::move(begin), std::move(end)); //?
mRaws.Remove(0, initCount);
}

Expand All @@ -614,13 +615,14 @@ namespace internal
mRaws.AddBack(RowReferenceProxy::GetRaw(rowRef));
}

template<conceptDataRowIterator<RowReference> RowIterator>
void Add(RowIterator begin, RowIterator end)
template<conceptDataRowIterator<RowReference> RowIterator,
conceptSentinel<RowIterator> RowSentinel>
void Add(RowIterator begin, RowSentinel end)
{
size_t initCount = GetCount();
try
{
for (RowIterator iter = begin; iter != end; ++iter)
for (RowIterator iter = std::move(begin); iter != end; ++iter)
{
RowReference rowRef = *iter;
MOMO_CHECK(&rowRef.GetColumnList() == mColumnList);
Expand All @@ -642,12 +644,13 @@ namespace internal
mRaws.Insert(index, RowReferenceProxy::GetRaw(rowRef));
}

template<conceptDataRowIterator<RowReference> RowIterator>
void Insert(size_t index, RowIterator begin, RowIterator end)
template<conceptDataRowIterator<RowReference> RowIterator,
conceptSentinel<RowIterator> RowSentinel>
void Insert(size_t index, RowIterator begin, RowSentinel end)
{
size_t initCount = GetCount();
MOMO_CHECK(index <= initCount);
Add(begin, end);
Add(std::move(begin), std::move(end));
std::rotate(UIntMath<>::Next(mRaws.GetBegin(), index),
UIntMath<>::Next(mRaws.GetBegin(), initCount), mRaws.GetEnd());
}
Expand Down
42 changes: 24 additions & 18 deletions include/momo/DataTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,16 +662,18 @@ class DataTable
return pvTryUpdate(rowRef, column, newItem);
}

template<internal::conceptDataRowIterator<ConstRowReference> RowIterator>
void Assign(RowIterator begin, RowIterator end)
template<internal::conceptDataRowIterator<ConstRowReference> RowIterator,
internal::conceptSentinel<RowIterator> RowSentinel>
void Assign(RowIterator begin, RowSentinel end)
{
pvAssign(begin, end);
pvAssign(std::move(begin), std::move(end));
}

template<internal::conceptDataRowIterator<ConstRowReference> RowIterator>
void Remove(RowIterator begin, RowIterator end)
template<internal::conceptDataRowIterator<ConstRowReference> RowIterator,
internal::conceptSentinel<RowIterator> RowSentinel>
void Remove(RowIterator begin, RowSentinel end)
{
pvRemove(begin, end);
pvRemove(std::move(begin), std::move(end));
}

template<internal::conceptPredicate<ConstRowReference> RowFilter>
Expand Down Expand Up @@ -1099,8 +1101,9 @@ class DataTable
return { pvMakeRowReference(raw), UniqueHashIndex::empty };
}

template<internal::conceptDataRowIterator<ConstRowReference> RowIterator>
void pvAssign(RowIterator begin, RowIterator end)
template<internal::conceptDataRowIterator<ConstRowReference> RowIterator,
internal::conceptSentinel<RowIterator> RowSentinel>
void pvAssign(RowIterator begin, RowSentinel end)
requires (Settings::keepRowNumber)
{
const ColumnList& columnList = GetColumnList();
Expand All @@ -1109,7 +1112,7 @@ class DataTable
size_t count = 0;
try
{
for (RowIterator iter = begin; iter != end; ++iter)
for (RowIterator iter = std::move(begin); iter != end; ++iter)
{
ConstRowReference rowRef = *iter;
MOMO_CHECK(&rowRef.GetColumnList() == &columnList);
Expand Down Expand Up @@ -1139,16 +1142,17 @@ class DataTable
}
}

template<internal::conceptDataRowIterator<ConstRowReference> RowIterator>
void pvAssign(RowIterator begin, RowIterator end)
template<internal::conceptDataRowIterator<ConstRowReference> RowIterator,
internal::conceptSentinel<RowIterator> RowSentinel>
void pvAssign(RowIterator begin, RowSentinel end)
requires (!Settings::keepRowNumber)
{
typedef HashMap<void*, size_t, HashTraits<void*>, MemManagerPtr,
HashMapKeyValueTraits<void*, size_t, MemManagerPtr>,
internal::NestedHashMapSettings> RawMap;
RawMap rawMap((HashTraits<void*>()), MemManagerPtr(GetMemManager()));
size_t count = 0;
for (RowIterator iter = begin; iter != end; ++iter)
for (RowIterator iter = std::move(begin); iter != end; ++iter)
{
ConstRowReference rowRef = *iter;
MOMO_CHECK(&rowRef.GetColumnList() == &GetColumnList());
Expand All @@ -1172,14 +1176,15 @@ class DataTable
}
}

template<internal::conceptDataRowIterator<ConstRowReference> RowIterator>
void pvRemove(RowIterator begin, RowIterator end)
template<internal::conceptDataRowIterator<ConstRowReference> RowIterator,
internal::conceptSentinel<RowIterator> RowSentinel>
void pvRemove(RowIterator begin, RowSentinel end)
requires (Settings::keepRowNumber)
{
const ColumnList& columnList = GetColumnList();
try
{
for (RowIterator iter = begin; iter != end; ++iter)
for (RowIterator iter = std::move(begin); iter != end; ++iter)
{
ConstRowReference rowRef = *iter;
MOMO_CHECK(&rowRef.GetColumnList() == &columnList);
Expand All @@ -1195,14 +1200,15 @@ class DataTable
pvSetNumbers();
}

template<internal::conceptDataRowIterator<ConstRowReference> RowIterator>
void pvRemove(RowIterator begin, RowIterator end)
template<internal::conceptDataRowIterator<ConstRowReference> RowIterator,
internal::conceptSentinel<RowIterator> RowSentinel>
void pvRemove(RowIterator begin, RowSentinel end)
requires (!Settings::keepRowNumber)
{
typedef HashSet<void*, HashTraits<void*>, MemManagerPtr,
HashSetItemTraits<void*, MemManagerPtr>, internal::NestedHashSetSettings> RawSet;
RawSet rawSet((HashTraits<void*>()), MemManagerPtr(GetMemManager()));
for (RowIterator iter = begin; iter != end; ++iter)
for (RowIterator iter = std::move(begin); iter != end; ++iter)
{
ConstRowReference rowRef = *iter;
MOMO_CHECK(&rowRef.GetColumnList() == &GetColumnList());
Expand Down

0 comments on commit d862554

Please sign in to comment.