本文整理汇总了C++中Cmp函数的典型用法代码示例。如果您正苦于以下问题:C++ Cmp函数的具体用法?C++ Cmp怎么用?C++ Cmp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Cmp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
CmpResult NameKey::objCmp(const NameKey &obj) const
{
if( CmpResult ret=Cmp(hash,obj.hash) ) return ret;
Cur a=getCur();
Cur b=obj.getCur();
while( a.next() )
{
if( b.next() )
{
if( CmpResult ret=Cmp(*a,*b) ) return ret;
}
else
{
return CmpGreater;
}
}
if( b.next() )
{
return CmpLess;
}
else
{
return CmpEqual;
}
}
示例2: main
int main()
{
#if STXXL_PARALLEL_MULTIWAY_MERGE
LOG1 << "STXXL_PARALLEL_MULTIWAY_MERGE";
#endif
// special parameter type
using InputType = stxxl::stream::from_sorted_sequences<value_type>;
using CreateRunsAlg = stxxl::stream::runs_creator<
InputType, Cmp, 4096, foxxll::random_cyclic>;
using SortedRunsType = CreateRunsAlg::sorted_runs_type;
unsigned input_size = (10 * megabyte / sizeof(value_type));
Cmp c;
CreateRunsAlg SortedRuns(c, 10 * megabyte);
value_type checksum_before(0);
std::mt19937_64 randgen;
std::uniform_int_distribution<unsigned> distr_value;
for (unsigned cnt = input_size; cnt > 0; )
{
std::uniform_int_distribution<unsigned> distr_size(1, cnt);
unsigned run_size = distr_size(randgen); // random run length
cnt -= run_size;
LOG1 << "current run size: " << run_size;
std::vector<unsigned> tmp(run_size); // create temp storage for current run
// fill with random numbers
std::generate(tmp.begin(), tmp.end(), std::bind(distr_value, std::ref(randgen)) _STXXL_FORCE_SEQUENTIAL);
std::sort(tmp.begin(), tmp.end(), c); // sort
for (unsigned j = 0; j < run_size; ++j)
{
checksum_before += tmp[j];
SortedRuns.push(tmp[j]); // push sorted values to the current run
}
SortedRuns.finish(); // finish current run
}
SortedRunsType Runs = SortedRuns.result(); // get sorted_runs data structure
die_unless(check_sorted_runs(Runs, Cmp()));
// merge the runs
stxxl::stream::runs_merger<SortedRunsType, Cmp> merger(Runs, Cmp(), 10 * megabyte);
stxxl::vector<value_type, 4, stxxl::lru_pager<8> > array;
LOG1 << input_size << " " << Runs->elements;
LOG1 << "checksum before: " << checksum_before;
value_type checksum_after(0);
for (unsigned i = 0; i < input_size; ++i)
{
checksum_after += *merger;
array.push_back(*merger);
++merger;
}
LOG1 << "checksum after: " << checksum_after;
die_unless(stxxl::is_sorted(array.cbegin(), array.cend(), Cmp()));
die_unless(checksum_before == checksum_after);
die_unless(merger.empty());
return 0;
}
示例3: insert
/*!
This method returns 'true' if the element has
successfully been inserted into the tree. And
'false' otherwise
*/
bool insert(const _Tp& element) {
std::cout << "\n**********************" << std::endl;
std::cout << "Inserting : " << element << std::endl;
if( not get_root() ) {
assert(mSentinel->add_child(element, Direction::RIGHT));
mSize += 1;
return true;
}
// Get the pointer to the root node, and call it
// 'currentNode'. Get a pointer to the root node's parent
// and call it 'currentParent'
node_ptr_t currentNode = avl_node<_Tp>::get_link(get_root());
node_ptr_t currentParent = currentNode;
Direction dir = Direction::NULL_DIRECTION;
// Walk down the tree
while( currentNode != nullptr) {
std::cout << "Current node : " << currentNode->mNodeValue << std::endl;
std::cout << "Current node at : " << currentNode << std::endl;
std::cout << "Current root at : " << get_root() << std::endl;
// Check to see if 'element' lies to the left or to
// the right of 'currentNode'
if( Cmp()(element, currentNode->mNodeValue) ) {
// Go left
currentParent = currentNode;
currentNode = avl_node<_Tp>::get_link(currentNode->left);
dir = Direction::LEFT;
std::cout << "Going left" << std::endl;
} else if( Cmp()(currentNode->mNodeValue, element) ) {
// Go right
currentParent = currentNode;
currentNode = avl_node<_Tp>::get_link(currentNode->right);
dir = Direction::RIGHT;
std::cout << "Going right" << std::endl;
} else {
// (a < b = false) and (b < a = false) => (a == b)
// 'element' already exists in the tree. return 'false'
return false;
}
}
mSize += 1;
// 'currentParent' points to a leaf node. and 'dir' records
// if we went left or right from that leaf node
assert(currentParent->add_child(element, dir));
std::cout << "Number of elements in tree = " << mSize << std::endl;
std::cout << "Element at root before re-balance = " << avl_node<_Tp>::get_link(get_root())->mNodeValue << std::endl;
std::cout << "Height of tree before re-balance = " << height() << std::endl;
std::cout << "location of root before rebalance = " << get_root() << std::endl;
rebalance(currentParent);
std::cout << "Element at root after re-balance = " << avl_node<_Tp>::get_link(get_root())->mNodeValue << std::endl;
std::cout << "Height of tree after re-balance = " << height() << std::endl;
std::cout << "location of root after rebalance = " << get_root() << std::endl;
std::cout << "**********************" << std::endl;
return true;
}
示例4: CheckMsg
void CheckMsg(zn_t *zn1, zn_t *zn2, zn_t *znd)//header_t **d, source_t *who, int start, int end)
{
header_t *c, *t;
// compare the message with dest
for (t = znd->start; t != znd->end; NextMsg(t))
if (Cmp(zn1->end, t))
break;
if (t != znd->end)
{
int size = ((byte*)zn1->end - (byte*)zn1->start);
// make room
memmove((byte*)t + size, t, (byte*)znd->end - (byte*)t);
znd->end += size;
// copy
for (c = zn1->start; c != zn1->end; NextMsg(c), NextMsg(t))
Cpy(t, c);
Mrg(zn1->end, t, t, true);
NextMsg(zn1->end);
zn1->start = zn1->end;
return;
}
for (t = zn2->start; t != zn2->end; NextMsg(t))
if (Cmp(zn1->end, t))
break;
if (t != zn2->end)
{
for (c = zn2->start; c != t; NextMsg(c), NextMsg(znd->end))
Cpy(znd->end, c);
for (c = zn1->start; c != zn1->end; NextMsg(c), NextMsg(znd->end))
Cpy(znd->end, c);
Mrg(zn1->end, t, znd->end, false);
NextMsg(znd->end);
NextMsg(zn1->end);
NextMsg(t);
zn1->start = zn1->end;
zn2->start = t;
}
else
{
NextMsg(zn1->end);
}
}
示例5: if
bool hatch::RegistryParser::Parse( Registry& registry )
{
if( !SkipEndLines() )
return false;
bool process = true;
do
{
if( m_tokenizer.IsWord() )
{
const char* key = m_tokenizer.GetWord();
if( Cmp( "new_version", key ) )
{
if( !ParseStringValue( registry.newVersion ) )
{
m_errorMessage << "for new_version";
return false;
}
}
else if( Cmp( "old_version", key ) )
{
if( !ParseStringValue( registry.oldVersion ) )
{
m_errorMessage << "for old_version";
return false;
}
}
else if( Cmp( "file", key ) )
{
if( !SkipEndLines() || !m_tokenizer.IsSymbol() || m_tokenizer.GetSymbol() != '{' )
{
m_errorMessage << "'{' expected after 'file'";
return false;
}
RegistryAction* pAction = SCARAB_NEW RegistryAction;
registry.actions.push_back( pAction );
if( !ParseFile( registry, *pAction ) )
return false;
}
}
if( !m_tokenizer.ParseNext() )
process = false;
} while( process );
return true;
}
示例6: OnInitDialog
BOOL CAddScript::OnInitDialog()
{
CDialog::OnInitDialog();
m_editBoxEnter.SetWindowTextA( m_instanceGeo->m_enterScript );
m_editBoxExit.SetWindowTextA( m_instanceGeo->m_exitScript );
if( !Cmp(m_instanceGeo->m_enterScript, "\n" ) )
m_strTriggerEnterScriptName = m_instanceGeo->m_enterScript;
if( !Cmp(m_instanceGeo->m_exitScript, "\n" ) )
m_strTriggerExitScriptName = m_instanceGeo->m_exitScript;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
示例7: OnOK
void CAddWater::OnOK()
{
CBool compare = CFalse;
if( !m_strWaterName.IsEmpty() )
{
compare = CTrue;
if( m_editMode )
if( m_strWaterName == m_strTempWaterName )
compare = CFalse;
}
else
compare = CFalse;
if( compare )
{
for( std::vector<std::string>::iterator it = g_engineObjectNames.begin(); it != g_engineObjectNames.end();it++ )
{
if( Cmp((LPCSTR)m_strWaterName, (*it).c_str() ) )
{
MessageBox( "This name already exist. Please select another name!", "Vanda Engine Error", MB_OK | MB_ICONERROR );
return;
}
}
}
// TODO: Add your specialized code here and/or call the base class
if( m_strNormalMap.IsEmpty() || m_strDuDvMap.IsEmpty() || m_strWaterName.IsEmpty() || m_strWaterHeight.IsEmpty() ||
m_strWaterSpeed.IsEmpty() || m_strWaterUV.IsEmpty() || m_strWaterScale.IsEmpty() || m_strWaterCX.IsEmpty() ||
m_strWaterCY.IsEmpty() || m_strWaterCZ.IsEmpty() || m_strWaterLX.IsEmpty() || m_strWaterLY.IsEmpty() ||
m_strWaterLZ.IsEmpty() )
MessageBox( "Please enter the valid data for all the required fields", "Vanda Engine Error", MB_OK | MB_ICONERROR );
else
CDialog::OnOK();
}
示例8: GetComponents
void SCH_SHEET_PATH::GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols )
{
// Search to sheet path number:
int sheetnumber = 1; // 1 = root
SCH_SHEET_LIST sheetList;
for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext(), sheetnumber++ )
{
if( Cmp( *path ) == 0 )
break;
}
for( SCH_ITEM* item = LastDrawList(); item; item = item->Next() )
{
if( item->Type() == SCH_COMPONENT_T )
{
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
// Skip pseudo components, which have a reference starting with #. This mainly
// affects power symbols.
if( !aIncludePowerSymbols && component->GetRef( this )[0] == wxT( '#' ) )
continue;
LIB_PART* part = aLibs->FindLibPart( component->GetPartName() );
if( part )
{
SCH_REFERENCE reference = SCH_REFERENCE( component, part, *this );
reference.SetSheetNumber( sheetnumber );
aReferences.AddItem( reference );
}
}
}
}
示例9: Work
void Work()
{
int i,j,k,l,r;
r=Min(n,m);l=1;
while (l<=r)
{
k=l+r>>1;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
{
if (i<k) f[i][j]=f[i-1][j]*p+a[i][j]&524287;
else f[i][j]=((f[i-1][j]-a[i-k][j]*s[k-1]&524287)+524288&524287)*p+a[i][j]&524287;//减去最高位,加上最低位
}//f[i][j]存下第j列第i行往上长度为k的串的HASH值
memset(start,0,sizeof(start));tot=0;
for (j=1;j<=m&&i>n;j++)
for (i=k;i<=n;i++)
{
if (j<k) g[i][j]=g[i][j-1]*p+f[i][j]&524287;
else
{
g[i][j]=((g[i][j-1]-f[i][j-k]*s[k-1]&524287)+524288&524287)*p+f[i][j]&524287;
if (Cmp(g[a1.x=i][a1.y=j],k)) break;
Insert(g[i][j],a1);
}
}//g[i][j]存下右下角为第i行第j列长度为k的矩阵的HASH值
if (j<=m) l=k+1;else r=k-1;
}
/*
if (ans) printf("%d\n%d %d\n%d %d\n",ans,x1-ans+1,y1-ans+1,x2-ans+1,y2-ans+1);
else printf("0\n");
*/
printf("%d\n" , ans );
}
示例10: IPCmp
bool static IPCmp(const UserListItem * l, const UserListItem * r){
if (l->isOp != r->isOp)
return l->isOp;
else if (!(l->ip.isEmpty() || r->ip.isEmpty())){
QString ip1 = l->ip;
QString ip2 = r->ip;
quint32 l_ip = ip1.section('.',0,0).toULong();
l_ip <<= 8;
l_ip |= ip1.section('.',1,1).toULong();
l_ip <<= 8;
l_ip |= ip1.section('.',2,2).toULong();
l_ip <<= 8;
l_ip |= ip1.section('.',3,3).toULong();
quint32 r_ip = ip2.section('.',0,0).toULong();
r_ip <<= 8;
r_ip |= ip2.section('.',1,1).toULong();
r_ip <<= 8;
r_ip |= ip2.section('.',2,2).toULong();
r_ip <<= 8;
r_ip |= ip2.section('.',3,3).toULong();
return Cmp(l_ip, r_ip);
}
return false;
}
示例11: operator
void operator()() {
Graph::iterator ii = graph.begin(), ei = graph.end();
if (ii != ei) { // Ensure there is at least one node in the graph.
Galois::for_each_ordered(ii, ei, Cmp(), NhFunc(), *this);
//Galois::for_each(ii, ei, *this);
}
}
示例12: L3RecvArp
// Received an ARP packet
void L3RecvArp(L3IF *f, PKT *p)
{
ARPV4_HEADER *a;
// Validate arguments
if (f == NULL || p == NULL)
{
return;
}
a = p->L3.ARPv4Header;
if (Endian16(a->HardwareType) != ARP_HARDWARE_TYPE_ETHERNET ||
Endian16(a->ProtocolType) != MAC_PROTO_IPV4 ||
a->HardwareSize != 6 || a->ProtocolSize != 4)
{
return;
}
if (Cmp(a->SrcAddress, p->MacAddressSrc, 6) != 0)
{
return;
}
switch (Endian16(a->Operation))
{
case ARP_OPERATION_REQUEST:
// ARP request arrives
L3RecvArpRequest(f, p);
break;
case ARP_OPERATION_RESPONSE:
// ARP response arrives
L3RecvArpResponse(f, p);
break;
}
}
示例13: OnOK
void CSceneProperties::OnOK()
{
CInt checkState;
checkState = m_checkBoxPlayAnimation.GetCheck();
if( checkState == BST_CHECKED )
m_scene->m_playAnimation = CTrue;
else
m_scene->m_playAnimation = CFalse;
checkState = m_checkBoxLoopAnimation.GetCheck();
if( checkState == BST_CHECKED )
m_scene->m_loopAnimationAtStartup = CTrue;
else
m_scene->m_loopAnimationAtStartup = CFalse;
for( CInt i = 0; i < m_scene->GetNumClips(); i++ )
{
if( Cmp( m_scene->m_animationClips[m_currentAnimClip]->GetName(), m_scene->m_animationClips[i]->GetName() ) )
{
m_scene->SetClipIndexForStartup(i);
}
}
CDialog::OnOK();
}
示例14: main
int main()
{
#if STXXL_PARALLEL_MULTIWAY_MERGE
STXXL_MSG("STXXL_PARALLEL_MULTIWAY_MERGE");
#endif
// special parameter type
typedef stxxl::stream::use_push<value_type> InputType;
typedef stxxl::stream::runs_creator<InputType, Cmp, 4096, stxxl::RC> CreateRunsAlg;
typedef CreateRunsAlg::sorted_runs_type SortedRunsType;
unsigned input_size = (50 * megabyte / sizeof(value_type));
Cmp c;
CreateRunsAlg SortedRuns(c, 1 * megabyte / 64);
value_type checksum_before(0);
stxxl::random_number32 rnd;
for (unsigned cnt = input_size; cnt > 0; --cnt)
{
const value_type element = rnd();
checksum_before += element;
SortedRuns.push(element); // push into the sorter
}
SortedRunsType& Runs = SortedRuns.result(); // get sorted_runs data structure
assert(stxxl::stream::check_sorted_runs(Runs, Cmp()));
// merge the runs
stxxl::stream::runs_merger<SortedRunsType, Cmp> merger(Runs, Cmp(), 1 * megabyte);
stxxl::vector<value_type, 4, stxxl::lru_pager<8>, block_size, STXXL_DEFAULT_ALLOC_STRATEGY> array;
STXXL_MSG(input_size << " " << Runs->elements);
STXXL_MSG("checksum before: " << checksum_before);
value_type checksum_after(0);
for (unsigned i = 0; i < input_size; ++i)
{
checksum_after += *merger;
array.push_back(*merger);
++merger;
}
STXXL_MSG("checksum after: " << checksum_after);
assert(stxxl::is_sorted(array.begin(), array.end(), Cmp()));
assert(checksum_before == checksum_after);
assert(merger.empty());
return 0;
}
示例15: AttrCmp
bool static AttrCmp(const UserListItem * l, const UserListItem * r) {
if (l->isOp != r->isOp)
return l->isOp;
else if (l->fav != r->fav)
return l->fav;
else
return Cmp(l->*attr, r->*attr);;
}