本文整理汇总了C++中DataArray::push_front方法的典型用法代码示例。如果您正苦于以下问题:C++ DataArray::push_front方法的具体用法?C++ DataArray::push_front怎么用?C++ DataArray::push_front使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataArray
的用法示例。
在下文中一共展示了DataArray::push_front方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LRem
int Ardb::LRem(Context& ctx, RedisCommandFrame& cmd)
{
int64 count;
if (!GetInt64Value(ctx, cmd.GetArguments()[1], count))
{
return 0;
}
int64 toremove = std::abs(count);
ValueObject meta;
int err = GetMetaValue(ctx, cmd.GetArguments()[0], LIST_META, meta);
CHECK_ARDB_RETURN_VALUE(ctx.reply, err);
if (0 != err)
{
fill_int_reply(ctx.reply, 0);
return 0;
}
Data element;
element.SetString(cmd.GetArguments()[2], true);
KeyLockerGuard lock(m_key_lock, ctx.currentDB, cmd.GetArguments()[0]);
if (meta.meta.Encoding() == COLLECTION_ENCODING_ZIPLIST)
{
uint32 oldlen = meta.meta.ziplist.size();
int64 removed = 0;
DataArray newzip;
if (count >= 0)
{
for (uint32 i = 0; i < oldlen; i++)
{
if (meta.meta.ziplist[i] == element)
{
if (toremove == 0 || removed < toremove)
{
removed++;
continue;
}
}
newzip.push_back(meta.meta.ziplist[i]);
}
}
else
{
for (uint32 i = 0; i < oldlen; i++)
{
if (meta.meta.ziplist[oldlen - 1 - i] == element)
{
if (toremove == 0 || removed < toremove)
{
removed++;
continue;
}
}
newzip.push_front(meta.meta.ziplist[i]);
}
}
if (removed > 0)
{
meta.meta.ziplist = newzip;
SetKeyValue(ctx, meta);
}
fill_int_reply(ctx.reply, removed);
return 0;
}
BatchWriteGuard guard(GetKeyValueEngine());
ListIterator iter;
ListIter(ctx, meta, iter, count < 0);
int64 remove = 0;
while (iter.Valid())
{
if (iter.Element()->Compare(element) == 0)
{
meta.meta.len--;
meta.meta.SetFlag(COLLECTION_FLAG_NORMAL);
DelRaw(ctx, iter.CurrentRawKey());
//DelKeyValue(ctx, k);
remove++;
if (remove == toremove)
{
break;
}
}
if (count < 0)
{
iter.Prev();
}
else
{
iter.Next();
}
}
if (remove > 0)
{
SetKeyValue(ctx, meta);
}
fill_int_reply(ctx.reply, remove);
return 0;
}