コード例 #1
0
ファイル: set.cpp プロジェクト: ckyang/GoogleCodeJam
void Set_C::Union(__int64_t x, __int64_t y)
{
	if(x == y)
		return;

	if(IsSameGroup(x, y))
		return;

	if(-1 == pnGroupIdx[x] || -1 == pnGroupIdx[y])
		return;

	__int64_t rootX = GetGroupIdx(x);
	__int64_t rootY = GetGroupIdx(y);

	if(pnGroupSize[rootX] < pnGroupSize[rootY])
	{
		pnGroupIdx[rootX] = rootY;
		pnGroupSize[rootY] += pnGroupSize[rootX];
		pnGroupSize[rootX] = 0;
	}
	else
	{
		pnGroupIdx[rootY] = rootX;
		pnGroupSize[rootX] += pnGroupSize[rootY];
		pnGroupSize[rootY] = 0;
	}

	--nGroupNum;
}
コード例 #2
0
ファイル: kv_paxos.cpp プロジェクト: BLiYing/phxpaxos
int PhxKV :: KVPropose(const std::string & sKey, const std::string & sPaxosValue, PhxKVSMCtx & oPhxKVSMCtx)
{
    int iGroupIdx = GetGroupIdx(sKey);

    SMCtx oCtx;
    //smid must same to PhxKVSM.SMID().
    oCtx.m_iSMID = 1;
    oCtx.m_pCtx = (void *)&oPhxKVSMCtx;

    uint64_t llInstanceID = 0;
    int ret = m_poPaxosNode->Propose(iGroupIdx, sPaxosValue, llInstanceID, &oCtx);
    if (ret != 0)
    {
        PLErr("paxos propose fail, key %s groupidx %d ret %d", iGroupIdx, ret);
        return ret;
    }

    return 0;
}
コード例 #3
0
ファイル: kv_paxos.cpp プロジェクト: BLiYing/phxpaxos
const bool PhxKV :: IsIMMaster(const std::string & sKey)
{
    int iGroupIdx = GetGroupIdx(sKey);
    return m_poPaxosNode->IsIMMaster(iGroupIdx);
}
コード例 #4
0
ファイル: kv_paxos.cpp プロジェクト: BLiYing/phxpaxos
const phxpaxos::NodeInfo PhxKV :: GetMaster(const std::string & sKey)
{
    int iGroupIdx = GetGroupIdx(sKey);
    return m_poPaxosNode->GetMaster(iGroupIdx);
}
コード例 #5
0
ファイル: set.cpp プロジェクト: ckyang/GoogleCodeJam
bool Set_C::IsSameGroup(__int64_t x, __int64_t y)
{
	return GetGroupIdx(x) == GetGroupIdx(y);
}