本文整理汇总了C++中Items::cend方法的典型用法代码示例。如果您正苦于以下问题:C++ Items::cend方法的具体用法?C++ Items::cend怎么用?C++ Items::cend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Items
的用法示例。
在下文中一共展示了Items::cend方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: replace
// Algorithm to calculate the edit operations to allow
//_ replaceing items without model reset
inline void replace(const Items &newItems, int from = 0)
{
using namespace kamd::utils::member_matcher;
#if 0
QDBG << "===\nOld items {";
for (const auto& item: m_items) {
QDBG << item;
}
QDBG << "}";
QDBG << "New items to be added at " << from << " {";
for (const auto& item: newItems) {
QDBG << item;
}
QDBG << "}";
#endif
// Based on 'The string to string correction problem
// with block moves' paper by Walter F. Tichy
//
// In essence, it goes like this:
//
// Take the first element from the new list, and try to find
// it in the old one. If you can not find it, it is a new item
// item - send the 'inserted' event.
// If you did find it, test whether the following items also
// match. This detects blocks of items that have moved.
//
// In this example, we find 'b', and then detect the rest of the
// moved block 'b' 'c' 'd'
//
// Old items: a[b c d]e f g
// ^
// /
// New items: [b c d]a f g
//
// After processing one block, just repeat until the end of the
// new list is reached.
//
// Then remove all remaining elements from the old list.
//
// The main addition here compared to the original papers is that
// our 'strings' can not hold two instances of the same element,
// and that we support updating from arbitrary position.
auto newBlockStart = newItems.cbegin();
// How many items should we add?
// This should remove the need for post-replace-trimming
// in the case where somebody called this with too much new items.
const int maxToReplace = m_countLimit - from;
if (maxToReplace <= 0) return;
const auto newItemsEnd =
newItems.size() <= maxToReplace ? newItems.cend() :
newItems.cbegin() + maxToReplace;
// Finding the blocks until we reach the end of the newItems list
//
// from = 4
// Old items: X Y Z U a b c d e f g
// ^ oldBlockStart points to the first element
// of the currently processed block in the old list
//
// New items: _ _ _ _ b c d a f g
// ^ newBlockStartIndex is the index of the first
// element of the block that is currently being
// processed (with 'from' offset)
while (newBlockStart != newItemsEnd) {
const int newBlockStartIndex
= from + std::distance(newItems.cbegin(), newBlockStart);
const auto oldBlockStart = std::find_if(
m_items.begin() + from, m_items.end(),
member(&ResultSet::Result::resource) == newBlockStart->resource());
if (oldBlockStart == m_items.end()) {
// This item was not found in the old cache, so we are
// inserting a new item at the same position it had in
// the newItems array
d->q->beginInsertRows(QModelIndex(), newBlockStartIndex,
newBlockStartIndex);
m_items.insert(newBlockStartIndex, *newBlockStart);
d->q->endInsertRows();
// This block contained only one item, move on to find
// the next block - it starts from the next item
++newBlockStart;
} else {
// We are searching for a block of matching items.
//.........这里部分代码省略.........