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;
    }
 }
Beispiel #2
0
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;
}
Beispiel #3
0
        /*!
            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;

        }
Beispiel #4
0
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);
	}
}
Beispiel #5
0
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;
}
Beispiel #6
0
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
}
Beispiel #7
0
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();
}
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 );
            }
        }
    }
}
Beispiel #9
0
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 );
}
Beispiel #10
0
        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;
        }
 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);
   }
 }
Beispiel #12
0
// 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;
	}
}
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();
}
Beispiel #14
0
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;
}
Beispiel #15
0
 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);;
 }
Beispiel #16
0
int
checkAttribute(Node *n, const String_or_char *name, const String_or_char *value) {
  String *v;
  v = Getattr(n,name);
  if (!v) return 0;
  if (Cmp(v,value) == 0) return 1;
  return 0;
}
Beispiel #17
0
PHBTreeBase HBTreeBase::Locate( HANDLE nm )
  {  maCmp cmp = Cmp(nm);
     if ( cmp == masEqual ) return this;
     if ( cmp == masMore )
       return (Left)?Left->Locate(nm):NULL;
      else
       return (Right)?Right->Locate(nm):NULL;
}
Beispiel #18
0
 void itemRemoved(const std::string& file)
 {
     auto it = std::lower_bound(m_dirEntries.begin(), m_dirEntries.end(), file, Cmp());
     if (it != m_dirEntries.end() && it->name == file) {
         m_dirEntries.erase(it);
         q->itemRemoved(it - m_dirEntries.begin());
     }
 }
Beispiel #19
0
void SummaryCommand :: DoMinMax( IOManager & io ) {
	CSVRow r = mRows.at(0);

	for ( unsigned int i = 1; i < mRows.size(); i++ ) {
		if ( mType == Min && Cmp( mRows.at(i), r ) < 0 ) {
			r = mRows.at(i);
		}
		else if ( mType == Max && Cmp( mRows.at(i), r ) > 0 ) {
			r = mRows.at(i);
		}
	}

	for ( unsigned int i = 0; i < mRows.size(); i++ ) {
		if ( Cmp( r, mRows.at(i) ) == 0 ) {
			io.WriteRow( mRows.at(i) );
		}
	}
}
// Set current configuration to VPN Azure client
void AcApplyCurrentConfig(AZURE_CLIENT *ac, DDNS_CLIENT_STATUS *ddns_status)
{
	bool disconnect_now = false;
	SOCK *disconnect_sock = NULL;
	// Validate arguments
	if (ac == NULL)
	{
		return;
	}

	// Get current DDNS configuration
	Lock(ac->Lock);
	{
		if (ddns_status != NULL)
		{
			if (StrCmpi(ac->DDnsStatus.CurrentHostName, ddns_status->CurrentHostName) != 0)
			{
				// If host name is changed, disconnect current data connection
				disconnect_now = true;
			}

			if (Cmp(&ac->DDnsStatus.InternetSetting, &ddns_status->InternetSetting, sizeof(INTERNET_SETTING)) != 0)
			{
				// If proxy setting is changed, disconnect current data connection
				disconnect_now = true;
			}

			Copy(&ac->DDnsStatus, ddns_status, sizeof(DDNS_CLIENT_STATUS));
		}

		if (ac->IsEnabled == false)
		{
			// If VPN Azure client is disabled, disconnect current data connection
			disconnect_now = true;
		}

		if (disconnect_now)
		{
			if (ac->CurrentSock != NULL)
			{
				disconnect_sock = ac->CurrentSock;
				AddRef(disconnect_sock->ref);
			}
		}
	}
	Unlock(ac->Lock);

	if (disconnect_sock != NULL)
	{
		Disconnect(disconnect_sock);
		ReleaseSock(disconnect_sock);
	}

	Set(ac->Event);
}
Beispiel #21
0
	void Decreas(int64* &a, int64* &b) {
		bool less = Cmp(b, a);
		if (!less) std::swap(a, b);
		for (int i = 1; i <= a[0]; i++) a[i] -= b[i];
		for (int i = 1; i <= a[0]; i++)
			if (a[i] < 0) {
				a[i + 1]--;
				a[i] += M10;
			}
		int64& l = a[0];
		while (!a[l] && l > 1) l--;
	}
Beispiel #22
0
// Process the Layer 2 packet
void L3RecvL2(L3IF *f, PKT *p)
{
	// Validate arguments
	if (f == NULL || p == NULL)
	{
		return;
	}

	// Ignore any packets except a unicast packet which is destinated other
	// or a packet which I sent
	if (Cmp(p->MacAddressSrc, f->MacAddress, 6) == 0 ||
		(p->BroadcastPacket == false && Cmp(p->MacAddressDest, f->MacAddress, 6) != 0))
	{
		// Release the packet
		Free(p->PacketData);
		FreePacket(p);
		return;
	}

	if (p->TypeL3 == L3_ARPV4)
	{
		// Received an ARP packet
		L3RecvArp(f, p);

		// Release the packet
		Free(p->PacketData);
		FreePacket(p);
	}
	else if (p->TypeL3 == L3_IPV4)
	{
		// Received an IP packet
		L3RecvIp(f, p, false);
	}
	else
	{
		// Release the packet
		Free(p->PacketData);
		FreePacket(p);
	}
}
Node *Swig_directormap(Node *module, String *type) {
  int is_void = !Cmp(type, "void");
  if (!is_void && module) {
    /* ?? follow the inheritance hierarchy? */

    String *base = SwigType_base(type);

    Node *directormap = Getattr(module, k_wrapdirectormap);
    if (directormap)
      return Getattr(directormap, base);
  }
  return 0;
}
Beispiel #24
0
BOOL HBTreeBase::Insert( PHBTreeBase p )
  {  maCmp cmp = Cmp(p);
     if ( cmp == masEqual ) return FALSE;
     if ( cmp == masMore ) {
       if ( Left ) return Left->Insert(p);
       Left = p;
       Left->Parent = this;
     } else {
       if ( Right ) return Right->Insert(p);
       Right = p;
       Right->Parent = this;
     }
 return TRUE;
}
Beispiel #25
0
Expression *CmpExp::optimize(int result)
{   Expression *e;

    //printf("CmpExp::optimize() %s\n", toChars());
    e1 = e1->optimize(result);
    e2 = e2->optimize(result);
    if (e1->isConst() == 1 && e2->isConst() == 1)
    {
        e = Cmp(op, type, this->e1, this->e2);
    }
    else
        e = this;
    return e;
}
static inline void
inssort_cache_block(Cacheblock<CachedChars>* cache, int n)
{
	Cacheblock<CachedChars> *pi, *pj;
	for (pi = cache + 1; --n > 0; ++pi) {
		Cacheblock<CachedChars> tmp = *pi;
		for (pj = pi; pj > cache; --pj) {
			if (Cmp()(*(pj-1), tmp) <= 0)
				break;
			*pj = *(pj-1);
		}
		*pj = tmp;
	}
}
Beispiel #27
0
void sort_by_key(float* keys, int* values, int count)
{
  std::vector<KeyVal_t> pairs(count);
#pragma omp parallel for
  for (int i = 0; i < count; i++)
    pairs[i] = std::make_pair(keys[i], values[i]);
  __gnu_parallel::sort(pairs.begin(), pairs.end(), Cmp());
#pragma omp parallel for
  for (int i = 0; i < count; i++)
  {
    keys  [i] = pairs[i].first;
    values[i] = pairs[i].second;
  }
}
Beispiel #28
0
int main()
{
    typedef stxxl::stream::runs_creator<Input, Cmp, 4096 * MULT, stxxl::RC> CreateRunsAlg;
    typedef CreateRunsAlg::sorted_runs_type SortedRunsType;

    stxxl::stats * s = stxxl::stats::get_instance();

    std::cout << *s;

    STXXL_MSG("Size of block type " << sizeof(CreateRunsAlg::block_type));
    unsigned size = MULT * 1024 * 128 / (sizeof(Input::value_type) * 2);
    Input in(size + 1);
    CreateRunsAlg SortedRuns(in, Cmp(), 1024 * 128 * MULT);
    SortedRunsType& Runs = SortedRuns.result();
    assert(stxxl::stream::check_sorted_runs(Runs, Cmp()));
    // merge the runs
    stxxl::stream::runs_merger<SortedRunsType, Cmp> merger(Runs, Cmp(), MULT * 1024 * 128);
    stxxl::vector<Input::value_type> array;
    STXXL_MSG(size << " " << Runs->elements);
    STXXL_MSG("CRC: " << in.crc);
    Input::value_type crc(0);
    for (unsigned i = 0; i < size; ++i)
    {
        //STXXL_MSG(*merger<< " must be "<< i+2 << ((*merger != i+2)?" WARNING":""));
        //assert(*merger == i+2);
        crc += *merger;
        array.push_back(*merger);
        ++merger;
    }
    STXXL_MSG("CRC: " << crc);
    assert(stxxl::is_sorted(array.begin(), array.end(), Cmp()));
    assert(merger.empty());

    std::cout << *s;

    return 0;
}
Beispiel #29
0
void Swig_extend_append_previous(Node *cls, Node *am) {
  Node *n, *ne;
  Node *pe = 0;
  Node *ae = 0;

  if (!am) return;
  
  n = firstChild(am);
  while (n) {
    ne = nextSibling(n);
    set_nextSibling(n,0);
    /* typemaps and fragments need to be prepended */
    if (((Cmp(nodeType(n),"typemap") == 0) || (Cmp(nodeType(n),"fragment") == 0)))  {
      if (!pe) pe = Swig_cparse_new_node("extend");
      appendChild(pe, n);
    } else {
      if (!ae) ae = Swig_cparse_new_node("extend");
      appendChild(ae, n);
    }    
    n = ne;
  }
  if (pe) prependChild(cls,pe);
  if (ae) appendChild(cls,ae);
}
Beispiel #30
0
Expression *CmpExp::optimize(int result)
{   Expression *e;

    //printf("CmpExp::optimize() %s\n", toChars());
    e1 = e1->optimize(WANTvalue | (result & WANTinterpret));
    e2 = e2->optimize(WANTvalue | (result & WANTinterpret));

    Expression *e1 = fromConstInitializer(result, this->e1);
    Expression *e2 = fromConstInitializer(result, this->e2);

    e = Cmp(op, type, e1, e2);
    if (e == EXP_CANT_INTERPRET)
	e = this;
    return e;
}