Пример #1
0
Файл: gx.c Проект: LWSS/gx
static void destroy_ship(struct GameState *game_state, struct Ship *ship)
{
    struct UIntHashPair *pair = find_pair(&game_state->ship_id_map, ship->id);
    ASSERT_NOT_NULL(pair);

    uint32 array_index = pair->value;
    ASSERT(array_index < game_state->ship_count);

    remove_pair(&game_state->ship_id_map, ship->id);

    // Ship is already at the end of the array.
    if (array_index == game_state->ship_count - 1)
    {
        --game_state->ship_count;
        return;
    }

    // Swap the destroyed ship with the last active ship in the array.
    struct Ship last = game_state->ships[game_state->ship_count - 1];
    game_state->ships[array_index] = last;

    --game_state->ship_count;

    // Update the ship ID map with the swapped ship's new array index.
    struct UIntHashPair *last_pair = find_pair(&game_state->ship_id_map, last.id);
    ASSERT_NOT_NULL(last_pair);
    last_pair->value = array_index;
}
Пример #2
0
/*
 *	Searches a tree of pairs for a specific parameter
 */
static ini_pair *find_pair(ini_pair *root, const char *name) {
	int c;
	
	if(!root) return NULL;
		
	c = my_stricmp(root->param, name);
	if(c == 0) 
		return root;
	else if(c < 0)
		return find_pair(root->left, name);
	else
		return find_pair(root->right, name);
}
Пример #3
0
Файл: gx.c Проект: LWSS/gx
static void emplace(struct UIntHashMap *map, uint32 key, uint32 value)
{
    struct UIntHashPair *pair = find_pair(map, key);
    ASSERT(pair == NULL);

    uint32 hash_map_size = ARRAY_SIZE(map->buckets);

    uint32 hash = key;
    uint32 bucket = hash % hash_map_size;

    pair = &map->buckets[bucket];
    while ((pair->key != NULL_UINT_HASH_KEY) && (pair->key != key))
    {
        bucket = (bucket + 1) % hash_map_size;
        pair = &map->buckets[bucket];

        if (pair->key == NULL_UINT_HASH_KEY)
        {
            pair->key = key;
            pair->value = value;
            return;
        }
    }

    pair->key = key;
    pair->value = value;
}
Пример #4
0
bool insert_uniq(std::multimap<K, V>& map, const std::pair<K, V>& pair)
{
	 if (find_pair(map, pair) == map.end()) {
		  map.insert(pair);
		  return true;
	 }
	 return false;
}
Пример #5
0
Файл: gx.c Проект: LWSS/gx
static void remove_pair(struct UIntHashMap *map, uint32 key)
{
    struct UIntHashPair *pair = find_pair(map, key);
    ASSERT(pair != NULL);

    // Mark the pair as null.
    pair->key = NULL_UINT_HASH_KEY;
    pair->value = 0;
}
Пример #6
0
static pl_ini_pair* locate(const pl_ini_file *file,
                           const char *section_name,
                           const char *key_name)
{
  pl_ini_section *section;
  if (!(section = find_section(file, section_name)))
    return NULL;

  return find_pair(section, key_name);
}
Пример #7
0
Файл: gx.c Проект: LWSS/gx
static struct Ship *get_ship_by_id(struct GameState *game_state, uint32 id)
{
    struct UIntHashPair *pair = find_pair(&game_state->ship_id_map, id);
    if (pair == NULL)
        return NULL;

    uint32 array_index = pair->value;
    ASSERT(array_index < game_state->ship_count);

    struct Ship *ship = &game_state->ships[array_index];
    return ship;
}
Пример #8
0
//validation
template<class X> void splay_forest<X>::test_find (Pos eqn)
{
    //test find_pair
    Pos pos = find_pair(get_root(eqn), get_key(eqn), get_val(eqn));
    POMAGMA_ASSERT(pos, "invalid: eqn not found in own " << nameof<X>() << " tree");
    POMAGMA_ASSERT(pos == eqn,
            "invalid: wrong eqn found in own " << nameof<X>() << " tree");

    //test find_key
    pos = find_key(get_root(eqn), get_key(eqn));
    POMAGMA_ASSERT(pos, "invalid: key not found in own " << nameof<X>() << " tree");
    POMAGMA_ASSERT(get_key(pos) == get_key(eqn),
            "invalid: wrong key found in own " << nameof<X>() << " tree");
}
Пример #9
0
static pl_ini_pair* locate_or_create(pl_ini_file *file,
                                     const char *section_name,
                                     const char *key_name)
{
  pl_ini_section *section = find_section(file, section_name);
  pl_ini_pair *pair = NULL;

  if (section)
    pair = find_pair(section, key_name);
  else
  {
    /* Create section */
    section = create_section(section_name);

    if (!file->head)
      file->head = section;
    else
    {
      pl_ini_section *s;
      for (s = file->head; s->next; s = s->next); /* Find the tail */
      s->next = section;
    }
  }

  if (!pair)
  {
    /* Create pair */
    pair = (pl_ini_pair*)malloc(sizeof(pl_ini_pair));
    pair->key = strdup(key_name);
    pair->value = NULL;
    pair->next = NULL;

    if (!section->head)
      section->head = pair;
    else
    {
      pl_ini_pair *p;
      for (p = section->head; p->next; p = p->next); /* Find the tail */
      p->next = pair;
    }
  }

  return pair;
}
Пример #10
0
/*
 *	Finds a specific parameter-value pair in the configuration file
 */
static ini_pair *find_param(const struct ini_file *ini, 
							const char *sec, 
							const char *par) {
	ini_section *s;
	ini_pair *p;
	
	if(!ini) return NULL;
	
	if(sec) {
		s = find_section(ini->sections, sec);
		if(!s) return NULL;	
		p = s->fields;
	} else
		p = ini->globals;
	
	if(!p) return NULL;
		
	return find_pair(p, par);	
}
Пример #11
0
    std::pair<int,int> KeyBindings::GetEventPair(QKeySequence sequence)
    {
        std::pair<int,int> find_pair(0,0);
        KeyBindingList::const_iterator iter = bindings_.begin();
        KeyBindingList::const_iterator end = bindings_.end();

        while (iter != end)
        {
            Binding binding = (*iter);
            if (binding.sequence == sequence)
            {
                find_pair.first = binding.event_ids.enter_id;
                find_pair.second = binding.event_ids.leave_id;
                break;
            }
            iter++;
        }

        return find_pair;
    }
Пример #12
0
int
colmgr_get_pair(int fg, int bg)
{
	assert(initialized && "colmgr_init() must be called before this function!");

	if(fg < 0)
	{
		fg = -1;
	}

	if(bg < 0)
	{
		bg = -1;
	}

	int p = find_pair(fg, bg);
	if(p != -1)
	{
		return p;
	}

	p = allocate_pair(fg, bg);
	return (p == -1) ? 0 : p;
}
Пример #13
0
int
colmgr_get_pair(int fg, int bg)
{
	int p;

	if(fg < 0)
	{
		fg = -1;
	}

	if(bg < 0)
	{
		bg = -1;
	}

	p = find_pair(fg, bg);
	if(p != -1)
	{
		return p;
	}

	p = allocate_pair(fg, bg);
	return (p == -1) ? 0 : p;
}
Пример #14
0
int
colmgr_alloc_pair(int fg, int bg)
{
	const int pair_index = find_pair(fg, bg);
	return (pair_index != -1) ? pair_index : allocate_pair(fg, bg);
}
Пример #15
0
void print_disc_info(netmd_dev_handle* devh, minidisc* md)
{
    uint8_t i = 0;
    int size = 1;
    uint8_t g, group = 0, lastgroup = 0;
    unsigned char bitrate_id;
    unsigned char flags;
    unsigned char channel;
    char *name, buffer[256];
    struct netmd_track time;
    struct netmd_pair const *trprot, *bitrate;

    trprot = bitrate = 0;

    for(i = 0; size >= 0; i++)
    {
        size = netmd_request_title(devh, i, buffer, 256);

        if(size < 0)
        {
            break;
        }

        /* Figure out which group this track is in */
        for( group = 0, g = 1; g < md->group_count; g++ )
        {
            if( (md->groups[g].start <= i+1U) && (md->groups[g].finish >= i+1U ))
            {
                group = g;
                break;
            }
        }
        /* Different to the last group? */
        if( group != lastgroup )
        {
            lastgroup = group;
            if( group )			/* Group 0 is 'no group' */
            {
                printf("Group: %s\n", md->groups[group].name);
            }
        }
        /* Indent tracks which are in a group */
        if( group )
        {
            printf("  ");
        }

        netmd_request_track_time(devh, i, &time);
        netmd_request_track_flags(devh, i, &flags);
        netmd_request_track_bitrate(devh, i, &bitrate_id, &channel);

        trprot = find_pair(flags, trprot_settings);
        bitrate = find_pair(bitrate_id, bitrates);

        /* Skip 'LP:' prefix... the codec type shows up in the list anyway*/
        if( strncmp( buffer, "LP:", 3 ))
        {
            name = buffer;
        }
        else
        {
            name = buffer + 3;
        }

        printf("Track %2i: %-6s %6s - %02i:%02i:%02i - %s\n",
               i, trprot->name, bitrate->name, time.minute,
               time.second, time.tenth, name);
    }

    /* XXX - This needs a rethink with the above method */
    /* groups may not have tracks, print the rest. */
    printf("\n--Empty Groups--\n");
    for(group=1; group < md->group_count; group++)
    {
        if(md->groups[group].start == 0 && md->groups[group].finish == 0) {
            printf("Group: %s\n", md->groups[group].name);
        }

    }

    printf("\n\n");
}
Пример #16
0
    __normal_call void_type roll_back (
        list_type &_tnew,
        list_type &_told
        )
    {
        iptr_type _npos ;
        iptr_type _fpos ;
        for (auto _tpos  = _tnew.head();
                  _tpos != _tnew.tend();
                ++_tpos )
        {
        for (_npos = tria_pred::_dims+1; 
             _npos-- != +0 ; )
        {
            node(tria(*_tpos )
               ->node( _npos))
               ->next() = null_flag();
        }
        }
        
        for (auto _tpos  = _told.head();
                  _tpos != _told.tend();
                ++_tpos )
        {
        for (_npos = tria_pred::_dims+1; 
             _npos-- != +0 ; )
        {
            node(tria(*_tpos )
               ->node( _npos))
               ->next() = *_tpos ;
        }

        for (_fpos = tria_pred::_dims+1; 
             _fpos-- != +0 ; )
        {
            iptr_type  _tadj;
            iptr_type  _fadj;
            iptr_type  _flag;
            find_pair(*_tpos, _tadj , 
                _fpos, _fadj, _flag )  ;

            push_pair(*_tpos, _tadj , 
                       _fpos, _fadj , 
                       _flag) ;
        }
        }

        for (auto _tpos  = _tnew.head();
                  _tpos != _tnew.tend();
                ++_tpos )
        {
        for (_npos = tria_pred::_dims+1; 
             _npos-- != +0 ; )
        {
            if (node(tria(*_tpos )
                   ->node( _npos)) 
                   ->mark()>= +0 )
            if (node(tria(*_tpos )
                   ->node( _npos))
                   ->next() == null_flag())
            {
           _put_node(tria(*_tpos )
                   ->node( _npos)) ;
            }
        }
        }
        
        for (auto _tpos  = _tnew.head();
                  _tpos != _tnew.tend();
                ++_tpos )
        {
            _put_tria(*_tpos) ;
        }
    }
Пример #17
0
template<class X> bool splay_forest<X>::is_inserted (Pos p)
{
    Pos found = find_pair(get_root(p), get_key(p), get_val(p), false);
    POMAGMA_ASSERT5((!found) or (found==p), "two identical pos's have been inserted")
    return found;
}