コード例 #1
0
ファイル: dict.cpp プロジェクト: fatman2021/myforthprocessor
//------------------------------Insert---------------------------------------
// Insert or replace a key/value pair in the given dictionary.	If the
// dictionary is too full, it's size is doubled.  The prior value being
// replaced is returned (NULL if this is a 1st insertion of that key).	If
// an old value is found, it's swapped with the prior key-value pair on the
// list.  This moves a commonly searched-for value towards the list head.
void *Dict::Insert(void *key, void *val) {
  uint hash = _hash( key );	// Get hash key
  uint i = hash & (_size-1);	// Get hash key, corrected for size
  bucket *b = &_bin[i];		// Handy shortcut
  for( uint j=0; j<b->_cnt; j++ )
    if( !_cmp(key,b->_keyvals[j+j]) ) {
      void *prior = b->_keyvals[j+j+1];
      b->_keyvals[j+j  ] = key;	// Insert current key-value
      b->_keyvals[j+j+1] = val;
      return prior;		// Return prior
    } 

  if( ++_cnt > _size ) {	// Hash table is full
    doubhash();			// Grow whole table if too full
    i = hash & (_size-1);	// Rehash
    b = &_bin[i];		// Handy shortcut
  }
  if( b->_cnt == b->_max ) {	// Must grow bucket?
    if( !b->_keyvals ) {
      b->_max = 2;		// Initial bucket size
      b->_keyvals = (void**)_arena->Amalloc_4(sizeof(void*) * b->_max * 2);
    } else {
      b->_keyvals = (void**)_arena->Arealloc(b->_keyvals, sizeof(void*) * b->_max * 2, sizeof(void*) * b->_max * 4);
      b->_max <<= 1;		// Double bucket
    }
  }
  b->_keyvals[b->_cnt+b->_cnt  ] = key;
  b->_keyvals[b->_cnt+b->_cnt+1] = val;
  b->_cnt++;
  return NULL;			// Nothing found prior
}
コード例 #2
0
ファイル: extsort.cpp プロジェクト: kapouer/mongo-debian
    BSONObjExternalSorter::Data BSONObjExternalSorter::Iterator::next(){
        
        if ( _in ){
            Data& d = *_it;
            ++_it;
            return d;
        }
        
        Data best;
        int slot = -1;
        
        for ( unsigned i=0; i<_stash.size(); i++ ){

            if ( ! _stash[i].second ){
                if ( _files[i]->more() )
                    _stash[i] = pair<Data,bool>( _files[i]->next() , true );
                else
                    continue;
            }
            
            if ( slot == -1 || _cmp( best , _stash[i].first ) == 0 ){
                best = _stash[i].first;
                slot = i;
            }
                
        }
        
        assert( slot >= 0 );
        _stash[slot].second = false;

        return best;
    }
コード例 #3
0
bool ProxyData::operator == (const ProxyData &d) const
{
    if (Type.value != d.Type.value)
        return false;
    if (Type.value == PROXY_NONE)
        return true;
    if ((Port.value != d.Port.value) && !_cmp(Host.ptr, d.Host.ptr))
        return false;
    if (Type.value == PROXY_SOCKS4)
        return true;
    if (Auth.bValue != d.Auth.bValue)
        return false;
    if (!d.Auth.bValue)
        return true;
    return _cmp(User.ptr, d.User.ptr) && _cmp(Password.ptr, d.Password.ptr);
}
コード例 #4
0
bool ProxyData::operator == (const ProxyData &d) const
{
    if (Type != d.Type)
        return false;
    if (Type == PROXY_NONE)
        return true;
    if ((Port != d.Port) && !_cmp(Host, d.Host))
        return false;
    if (Type == PROXY_SOCKS4)
        return true;
    if (Auth != d.Auth)
        return false;
    if (d.Auth == 0)
        return true;
    return _cmp(User, d.User) && _cmp(Password, d.Password);
}
コード例 #5
0
ファイル: dict.cpp プロジェクト: fatman2021/myforthprocessor
//------------------------------FindDict-------------------------------------
// Find a key-value pair in the given dictionary.  If not found, return NULL.
// If found, move key-value pair towards head of list.
void *Dict::operator [](const void *key) const {
  uint i = _hash( key ) & (_size-1);	// Get hash key, corrected for size
  bucket *b = &_bin[i];		// Handy shortcut
  for( uint j=0; j<b->_cnt; j++ )
    if( !_cmp(key,b->_keyvals[j+j]) ) 
      return b->_keyvals[j+j+1];
  return NULL;
}
コード例 #6
0
void YahooClient::processStatus(unsigned short service, const char *id,
                                const char *_state, const char *_msg,
                                const char *_away, const char *_idle)
{
    Contact *contact;
    YahooUserData *data = findContact(id, NULL, contact);
    if (data == NULL)
        return;
    unsigned state = 0;
    unsigned away  = 0;
    unsigned idle  = 0;
    if (_state)
        state = atol(_state);
    if (_away)
        away  = atol(_away);
    if (_idle)
        idle  = atol(_idle);
    if (service == YAHOO_SERVICE_LOGOFF)
        state = YAHOO_STATUS_OFFLINE;
    if ((state != data->Status.value) ||
            ((state == YAHOO_STATUS_CUSTOM) &&
             (((away != 0) != data->bAway.bValue) || _cmp(_msg, data->AwayMessage.ptr)))) {

        unsigned long old_status = STATUS_UNKNOWN;
        unsigned style  = 0;
        const char *statusIcon = NULL;
        contactInfo(data, old_status, style, statusIcon);

        time_t now;
        time(&now);
        now -= idle;
        if (data->Status.value == YAHOO_STATUS_OFFLINE)
            data->OnlineTime.value = now;
        data->Status.value = state;
        data->bAway.bValue = (away != 0);
        data->StatusTime.value = now;

        unsigned long new_status = STATUS_UNKNOWN;
        contactInfo(data, old_status, style, statusIcon);

        if (old_status != new_status) {
            StatusMessage m;
            m.setContact(contact->id());
            m.setClient(dataName(data).c_str());
            m.setFlags(MESSAGE_RECEIVED);
            m.setStatus(STATUS_OFFLINE);
            Event e(EventMessageReceived, &m);
            e.process();
            if ((new_status == STATUS_ONLINE) && !contact->getIgnore()) {
                Event e(EventContactOnline, contact);
                e.process();
            }
        } else {
            Event e(EventContactStatus, contact);
            e.process();
        }
    }
}
コード例 #7
0
ファイル: gbtree.cpp プロジェクト: ABratovic/open-watcom-v2
bool CL_GenericBTreeNode::Search (CL_VoidPtr itm, short& index) const
{
    if (!_item)
        return FALSE;
    long i;
    short result;
    if (_keyCount <= 7) { // Small number of keys, do a linear search
        if (_keyCount == 0) {
            index = -1;
            return FALSE;
        }
        for (i = 0; i < _keyCount; i++) {
            result = _cmp (_item[i], itm);
            if (result >= 0)
                break;
        }
        if (result == 0) {
            index = i;
            return TRUE;
        }
        else  {
            index = i-1;
            return FALSE;
        }
    }

    // Do a binary search
    long lo = 0, hi = _keyCount-1, mid;
    while (lo <= hi) {
        mid = (lo + hi)/2;
        result = _cmp (_item[mid], itm);
        if (result == 0) {
            index = mid;
            return TRUE;
        }
        if (result < 0)
            lo = mid+1;
        else
            hi = mid-1;
    }
    index = (result <= 0) ? (mid) :  mid-1;
    return FALSE;
}
コード例 #8
0
ファイル: args.cpp プロジェクト: CasualX/ExtPlugin
NOINLINE const char* CmdLineArgs::GetArg( const char* id ) const
{
	typedef char** iterator;
	for ( iterator it = argv, end = it+argc; it!=end; ++it )
	{
		if ( const char* arg = _cmp( *it, id ) )
			return arg;
	}
	return nullptr;
}
コード例 #9
0
ファイル: dict.cpp プロジェクト: fatman2021/myforthprocessor
//------------------------------Delete---------------------------------------
// Find & remove a value from dictionary. Return old value.
void *Dict::Delete(void *key) {
  uint i = _hash( key ) & (_size-1);	// Get hash key, corrected for size
  bucket *b = &_bin[i];		// Handy shortcut
  for( uint j=0; j<b->_cnt; j++ )
    if( !_cmp(key,b->_keyvals[j+j]) ) {
      void *prior = b->_keyvals[j+j+1];
      b->_cnt--;		// Remove key/value from lo bucket
      b->_keyvals[j+j  ] = b->_keyvals[b->_cnt+b->_cnt  ];
      b->_keyvals[j+j+1] = b->_keyvals[b->_cnt+b->_cnt+1];
      _cnt--;			// One less thing in table
      return prior;
    }
  return NULL;
}
コード例 #10
0
ファイル: print.cpp プロジェクト: TomFrost/scummvm
void DreamGenContext::printchar(const Frame *charSet, uint16* x, uint16 y, uint8 c, uint8 nextChar, uint8 *width, uint8 *height) {
	if (c == 255)
		return;
	push(si);
	push(di);
	if (data.byte(kForeignrelease) != 0)
		y -= 3;
	uint16 tmp = c - 32 + data.word(kCharshift);
	showframe(charSet, *x, y, tmp & 0x1ff, (tmp >> 8) & 0xfe, width, height);
	di = pop();
	si = pop();
	_cmp(data.byte(kKerning), 0);
	if (flags.z())
		*width = kernchars(c, nextChar, *width);
	(*x) += *width;
}
コード例 #11
0
ファイル: stubs.cpp プロジェクト: TomFrost/scummvm
void DreamGenContext::dosreturn() {

	_cmp(data.byte(kCommandtype), 250);
	if (!flags.z()) {
		data.byte(kCommandtype) = 250;
		al = 46;
		commandonly();
	}

	ax = data.word(kMousebutton);
	_and(ax, 1);
	if (flags.z())
		return;

	data.word(kMousebutton) = 0;
	engine->quit();
}
コード例 #12
0
bool BSONIteratorSorted::ElementFieldCmp::operator()(const char* s1, const char* s2) const {
    // Skip the type byte and compare field names.
    return _cmp(s1 + 1, s2 + 1);
}
コード例 #13
0
static void _verify_get(void) {
  if (!_cmp(_get, ONES)) {
    exit(-1);
  }
}
コード例 #14
0
ファイル: vm_assembler.cpp プロジェクト: SenchaK/ScriptEngine
void VMDriver::execute(){
	if( this->m_state == STATE_IDLE ){
		printf( "Error: state is idle. \n");
		return;
	}

	assert( this->currentAssembly() );
	while( this->isActive() ){
		if( this->isBreak() ){
			break;
		}
		unsigned char content = this->getByte( m_funcAddr , m_pc );
		m_pc++;
		switch( content ){
			case EMnemonic::MovPtr :
				_mov_ptr();
				break;
			case EMnemonic::Mov :
				_mov();
				break;
			case EMnemonic::Add :
				_add();
				break;
			case EMnemonic::Sub :
				_sub();
				break;
			case EMnemonic::Mul :
				_mul();
				break;
			case EMnemonic::Div :
				_div();
				break;
			case EMnemonic::Rem :
				_rem();
				break;
			case EMnemonic::Inc :
				_inc();
				break;
			case EMnemonic::Dec :
				_dec();
				break;
			case EMnemonic::Push :
				_push();
				break;
			case EMnemonic::PushPtr :
				_push_ptr();
				break;
			case EMnemonic::Pop :
				_pop();
				break;
			case EMnemonic::Call :
				_call();
				break;
			case EMnemonic::ST :
				_st();
				break;
			case EMnemonic::LD :
				_ld();
				break;
			case EMnemonic::EndFunc :
				_endFunc();
				break;

			case EMnemonic::CmpGeq : 
			case EMnemonic::CmpG :
			case EMnemonic::CmpLeq : 
			case EMnemonic::CmpL :
			case EMnemonic::CmpEq : 
			case EMnemonic::CmpNEq :
				_cmp( content );
				break;
			case EMnemonic::Not :
				_not();
				break;
			case EMnemonic::Minus :
				_minus();
				break;
			case EMnemonic::LogOr :
			case EMnemonic::LogAnd :
				_log( content );
				break;
			case EMnemonic::Jmp :
				_jmp();
				break;
			case EMnemonic::JumpZero :
				_jumpzero();
				break;
			case EMnemonic::JumpNotZero :
				_jumpnotzero();
				break;
			case EMnemonic::RET :
				_ret();
				break;
		}
	}
}