Skip to content

Instantly share code, notes, and snippets.

@markpapadakis
Created May 9, 2014 19:28
Show Gist options
  • Select an option

  • Save markpapadakis/674be15985e8a9cd6349 to your computer and use it in GitHub Desktop.

Select an option

Save markpapadakis/674be15985e8a9cd6349 to your computer and use it in GitHub Desktop.
static int8_t TryAppend(const ColumnFamily *__restrict const self, const ColumnFamily *__restrict const cf, colNameCmpProc_t cmpProc)
{
const uint32_t cfColumnsCnt = cf->columns.Size();
if (unlikely(cfColumnsCnt == 0))
return 0;
const uint32_t selfColumnsCnt = self->columns.Size();
if (unlikely(selfColumnsCnt == 0))
return 1; // Should append cf->columns to self->columns
const column_name *const sn = &self->columns.LastValueUnsafe()->name, *const cn = &cf->columns[0]->name;
const auto r = cmpProc(cn->Name(), cn->Length(), sn->Name(), sn->Length());
if (r > 0)
{
// Yes, we can just append all cf->columns[] to self->columns#endif
return 1;
}
else
{
const column_name *const snFirst = &self->columns[0]->name, *const cnLast = &cf->columns.LastValueUnsafe()->name;
const auto r = cmpProc(cnLast->Name(), cnLast->Length(), snFirst->Name(), snFirst->Length());
if (r < 0)
{
// Yes, we can just insert all cf->columns[] at self->columns[0]
return -1;
}
else if (cfColumnsCnt < 32)
{
#pragma mark arbitrary
if (cfColumnsCnt < 8)
{
// We almost always end up updating/setting the same columns anyway
return 2;
}
#pragma mark arbitrary
const int32_t index = Max<int32_t>(0, ((int32_t)selfColumnsCnt) - 8);
const column_name *const boundaryName = &self->columns.Values()[index]->name;
if (cmpProc(cnLast->Name(), cnLast->Length(), boundaryName->Name(), boundaryName->Length()) >= 0)
{
// Yes, we should perform in-place updates
return 2;
}
}
}
// Overlapping names, cannot append or insert, cannot advice in-place updates
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment