Beispiel #1
0
void chain_pair_alg_update_init(struct DotList *dots, int *num, struct kdnode *tree, struct perm_pt *p_pts, int size1, int size2, struct DotList *init_algns)
{
	struct slist *sorted;
	int i = 0;
	int num_lines = 0;
	int xval = 0, yval = 0;
	int w_sid = 0, w_fid = 0, h_sid = 0, h_fid = 0;
	int opt_id = -1;
	bool *is_x;

	is_x = (bool *) malloc(sizeof(bool));
	num_lines = *num;

	sorted = (struct slist *) ckalloc((*num) * sizeof(struct slist));

	if( num_lines > 0 ) sort_list(sorted, dots, num_lines);

	for( i = 0; i < num_lines; i++ )
	{
		opt_id = -1;
		if( dots[sorted[i].id].sign == DELETED )
		{
		}
		else
		{
			xval = dots[sorted[i].id].x.lower;
			if( dots[sorted[i].id].sign == 0 )
			{
				yval = dots[sorted[i].id].y.lower;
			}
			else 
			{
				yval = dots[sorted[i].id].y.upper;
			}	
			
			w_sid = find_id(dots, tree, size1, sorted[i].id, xval, yval, W_SID);
			w_fid = find_id(dots, tree, size1, sorted[i].id, xval, yval, W_FID);
			h_sid = find_id(dots, tree, size2, sorted[i].id, xval, yval, H_SID);
			h_fid = find_id(dots, tree, size2, sorted[i].id, xval, yval, H_FID);

			opt_id = find_opt_ch_alg(dots, num_lines, sorted[i].id, p_pts, w_sid, w_fid, h_sid, h_fid);
		}

		if( opt_id != -1 ) 
		{
			if( debug_mode == TRUE ) {
				printf("Combined: %d-%d,%d-%d\n", dots[opt_id].x.lower, dots[opt_id].x.upper, dots[opt_id].y.lower, dots[opt_id].y.upper);
				printf("%d-%d,%d-%d\n", dots[sorted[i].id].x.lower, dots[sorted[i].id].x.upper, dots[sorted[i].id].y.lower, dots[sorted[i].id].y.upper); 
			}

			mark_chain(dots, opt_id, sorted[i].id, init_algns);
			merging_step(dots, opt_id, sorted[i].id);
		}	
	}
	overwrite_dots(num, dots);

	free(sorted);
	free(is_x);
}
Beispiel #2
0
/**
* return value as the model suggested. The history state must be historified
* or the history's level should be 0. when level == 0 but idx != 0, the
* history is a psuedo unigram state used for this model to combine another
* bigram cache language model
*/
double
CThreadSlm::rawTransfer(TState history, unsigned int wid, TState& result)
{
    unsigned int lvl = history.getLevel();
    unsigned int pos = history.getIdx();

    double cost = (m_UseLogPr)?0.0:1.0;

    // NON_Word id must be dealed with special, let it transfer to root
    // without any cost
    if (ID_NOT_WORD == wid) {
        result = 0;
        return cost;
    }

    while (true) {
        //for psuedo cache model unigram state
        TNode* pn = ((TNode *)m_Levels[lvl]) + ((lvl)?pos:0);

        unsigned int t = (pn+1)->ch();

        if (lvl < m_N-1) {
            TNode* pBase =(TNode*)m_Levels[lvl+1];
            unsigned int idx = find_id(pBase, pn->ch(), t, wid);
            if (idx != t) {
                result.setIdx(idx);
                result.setLevel(lvl+1);
                double pr = m_prTable[pBase[idx].pr()];
                return (m_UseLogPr)?(cost+pr):(cost*pr);
            }

        } else {
            TLeaf* pBase =(TLeaf*)m_Levels[lvl+1];
            unsigned int idx = find_id(pBase, pn->ch(), t, wid);
            if (idx != t) {
                result.setIdx(idx);
                result.setLevel(lvl+1);
                double pr = m_prTable[pBase[idx].pr()];
                return (m_UseLogPr)?(cost+pr):(cost*pr);
            }

        }

        if (m_UseLogPr)
            cost += m_bowTable[pn->bow()];
        else
            cost *= m_bowTable[pn->bow()];
        if (lvl == 0)
            break;
        lvl = pn->bol();
        pos = pn->bon();
    }
    result.setLevel(0);
    result.setIdx(0);
    if (m_UseLogPr)
        return cost + m_prTable[((TNode *)m_Levels[0])->pr()];
    else
        return cost * m_prTable[((TNode *)m_Levels[0])->pr()];
}
void key_trigger(int key)
{
	(key == (R + DU)) ? change_menu_status(BASE), waitKeyChange(key) : key + 0;
	(key == (L + R + DU)) ? change_menu_status(ADDING) : key + 0;
	(key == (R + DL)) ? change_state(find_id(BASE, "Monster #1 Infinite HP (R + Left)")), waitKeyChange(key) : key + 0;
	(key == (R + DR)) ? change_state(find_id(BASE, "Monster #2 Infinite HP (R + Right)")), waitKeyChange(key) : key + 0;
	(key == (R + DD)) ? change_state(find_id(BASE, "Monster #3 Infinite HP (R + Down)")), waitKeyChange(key) : key + 0;
	
}
int main() 
{
	std::cout << " f(-3) : " << f(-3) << " f(2) : " << f(2) << std::endl;

	std::vector<record> roster = { 	{"mark",1},
									{"bill",2},
									{"ted",3}};
	std::cout << find_id(roster,"bill") << "\n";
	std::cout << find_id(roster,"ron") << "\n";
	
}
Beispiel #5
0
static int
me_sasl(struct Client *client_p, struct Client *source_p,
	int parc, const char *parv[])
{
	struct Client *target_p, *agent_p;

	/* Let propagate if not addressed to us, or if broadcast.
	 * Only SASL agents can answer global requests.
	 */
	if(strncmp(parv[2], me.id, 3))
		return 0;

	if((target_p = find_id(parv[2])) == NULL)
		return 0;

	if(target_p->preClient == NULL)
		return 0;

	if((agent_p = find_id(parv[1])) == NULL)
		return 0;

	if(source_p != agent_p->servptr) /* WTF?! */
		return 0;

	/* We only accept messages from SASL agents; these must have umode +S
	 * (so the server must be listed in a service{} block).
	 */
	if(!IsService(agent_p))
		return 0;

	/* Reject if someone has already answered. */
	if(*target_p->preClient->sasl_agent && strncmp(parv[1], target_p->preClient->sasl_agent, IDLEN))
		return 0;
	else if(!*target_p->preClient->sasl_agent)
		rb_strlcpy(target_p->preClient->sasl_agent, parv[1], IDLEN);

	if(*parv[3] == 'C')
		sendto_one(target_p, "AUTHENTICATE %s", parv[4]);
	else if(*parv[3] == 'D')
	{
		if(*parv[4] == 'F')
			sendto_one(target_p, form_str(ERR_SASLFAIL), me.name, EmptyString(target_p->name) ? "*" : target_p->name);
		else if(*parv[4] == 'S') {
			sendto_one(target_p, form_str(RPL_SASLSUCCESS), me.name, EmptyString(target_p->name) ? "*" : target_p->name);
			target_p->preClient->sasl_complete = 1;
			ServerStats.is_ssuc++;
		}
		*target_p->preClient->sasl_agent = '\0'; /* Blank the stored agent so someone else can answer */
	}
	
	return 0;
}
Beispiel #6
0
static inline bool pair_pointer_fixup_func(size_t idx,
		obs_hotkey_pair_t *pair, void *data)
{
	UNUSED_PARAMETER(idx);
	UNUSED_PARAMETER(data);

	if (find_id(pair->id[0], &idx))
		obs->hotkeys.hotkeys.array[idx].data = pair;

	if (find_id(pair->id[1], &idx))
		obs->hotkeys.hotkeys.array[idx].data = pair;

	return true;
}
void switch_mode()
{
	if (mode)
	{
		change_text(BASE, find_id(BASE, "Switch mode") + 1, "  Current mode: 1");
		mode = 0;
	}
	else
	{
		change_text(BASE, find_id(BASE, "Switch mode") + 1, "  Current mode: 2");
		mode = 1;
	}
	show_base();
}
Beispiel #8
0
ulong bootstage_add_record(enum bootstage_id id, const char *name,
			   int flags, ulong mark)
{
	struct bootstage_data *data = gd->bootstage;
	struct bootstage_record *rec;

	/*
	 * initf_bootstage() is called very early during boot but since hang()
	 * calls bootstage_error() we can be called before bootstage is set up.
	 * Add a check to avoid this.
	 */
	if (!data)
		return mark;
	if (flags & BOOTSTAGEF_ALLOC)
		id = data->next_id++;

	/* Only record the first event for each */
	rec = find_id(data, id);
	if (!rec && data->rec_count < RECORD_COUNT) {
		rec = &data->record[data->rec_count++];
		rec->time_us = mark;
		rec->name = name;
		rec->flags = flags;
		rec->id = id;
	}

	/* Tell the board about this progress */
	show_boot_progress(flags & BOOTSTAGEF_ERROR ? -id : id);

	return mark;
}
Beispiel #9
0
int main()
{
	int array[11] = {1,1,1,2,2,2,3,3,3,4,5};
	three_id id = find_id(array,11);
	printf("the three  ids is:%d %d %d \n",id.id,id.id_2,id.id_3);
	return 0;
}
Beispiel #10
0
int Cpkt_ts_ini_reader::process_key(const string& name, const string& value)
{
    switch (m_section)
    {
    case sei_multi_maps:
        m_map_list[to_lower_copy(value)];
        break;
    case sei_unknown:
        switch (find_id(name, map_code, mai_unknown))
        {
        case mai_description:
            m_map_list[m_current_map].m_description = value;
            break;
        case mai_cd:
            m_map_list[m_current_map].m_cd = value;
            break;
        case mai_minplayers:
            m_map_list[m_current_map].m_min_players = atoi(value.c_str());
            break;
        case mai_maxplayers:
            m_map_list[m_current_map].m_max_players = atoi(value.c_str());
            break;
        case mai_gamemode:
            m_map_list[m_current_map].m_gamemode = value;
            break;
        default:
            return 1;
        }
    }
    return 0;
}
/*
 * Detect any quirks the device has, and do any housekeeping for it if needed.
 */
void usb_detect_quirks(struct usb_device *udev)
{
	const struct usb_device_id *id = usb_quirk_list;

	id = find_id(udev);
	if (id)
		udev->quirks = (u32)(id->driver_info);
	if (udev->quirks)
		dev_dbg(&udev->dev, "USB quirks for this device: %x\n",
				udev->quirks);

	/* By default, disable autosuspend for all non-hubs */
#ifdef	CONFIG_USB_SUSPEND
	if (udev->descriptor.bDeviceClass != USB_CLASS_HUB)
		udev->autosuspend_disabled = 1;
#endif

	/* For the present, all devices default to USB-PERSIST enabled */
#if 0		/* was: #ifdef CONFIG_PM */
	/* Hubs are automatically enabled for USB-PERSIST */
	if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
		udev->persist_enabled = 1;

#else
	/* In the absence of PM, we can safely enable USB-PERSIST
	 * for all devices.  It will affect things like hub resets
	 * and EMF-related port disables.
	 */
	udev->persist_enabled = 1;
#endif	/* CONFIG_PM */
}
Beispiel #12
0
/* return a pointer to the `symbol' in DLL */
void *dlsym(void *handle, char *symbol)
{
    int rc = 0;
    PFN addr;
    char *errtxt;
    int symord = 0;
    DLLchain tmp = find_id(handle);

    if (!tmp)
        goto inv_handle;

    if (*symbol == '#')
        symord = atoi(symbol + 1);

    switch (rc = DosQueryProcAddr(tmp->handle, symord, symbol, &addr))
    {
        case NO_ERROR:
            return (void *)addr;
        case ERROR_INVALID_HANDLE:
inv_handle:
            errtxt = "invalid module handle";
            break;
        case ERROR_PROC_NOT_FOUND:
        case ERROR_INVALID_NAME:
            errtxt = "no symbol `%s' in module";
            break;
        default:
            errtxt = "symbol `%s', error code = %d";
            break;
    }
    snprintf(dlerr, sizeof(dlerr), errtxt, symbol, rc);
    return NULL;
}
Beispiel #13
0
/** Generate a query based on class, type and name.
 * @param[in] name Domain name to look up.
 * @param[in] query_class Query class (see RFC 1035).
 * @param[in] type Query type (see RFC 1035).
 * @param[in] request DNS request structure.
 */
static void
query_name(const char *name, int query_class, int type,
           struct reslist *request)
{
  char buf[MAXPACKET];
  int request_len = 0;

  memset(buf, 0, sizeof(buf));

  if ((request_len = irc_res_mkquery(name, query_class, type,
      (unsigned char *)buf, sizeof(buf))) > 0)
  {
    HEADER *header = (HEADER *)buf;

    /*
     * generate an unique id
     * NOTE: we don't have to worry about converting this to and from
     * network byte order, the nameserver does not interpret this value
     * and returns it unchanged
     */
    do
    {
      header->id = (header->id + ircrandom()) & 0xffff;
    } while (find_id(header->id));
    request->id = header->id;
    ++request->sends;

    request->sent += send_res_msg(buf, request_len, request->sends);
    check_resolver_timeout(request->sentat + request->timeout);
  }
}
/*!
    Sets a What's This help text for the accelerator item \a id to \a
    text.

    The text will be shown when the application is in What's This mode
    and the user hits the accelerator key.

    To set What's This help on a menu item (with or without an
    accelerator key), use QMenuData::setWhatsThis().

    \sa whatsThis(), QWhatsThis::inWhatsThisMode(),
    QMenuData::setWhatsThis(), QAction::setWhatsThis()
*/
void QAccel::setWhatsThis( int id, const QString& text )
{

    QAccelItem *item = find_id( d->aitems, id);
    if ( item )
	item->whatsthis = text;
}
Beispiel #15
0
/* If the client never finished authenticating but is
 * registering anyway, abort the exchange.
 */
static void
abort_sasl(struct Client *data)
{
	if(data->localClient->sasl_out == 0 || data->localClient->sasl_complete)
		return;

	data->localClient->sasl_out = data->localClient->sasl_complete = 0;
	ServerStats.is_sbad++;

	if(!IsClosing(data))
		sendto_one(data, form_str(ERR_SASLABORTED), me.name, EmptyString(data->name) ? "*" : data->name);

	if(*data->localClient->sasl_agent)
	{
		struct Client *agent_p = find_id(data->localClient->sasl_agent);
		if(agent_p)
		{
			sendto_one(agent_p, ":%s ENCAP %s SASL %s %s D A", me.id, agent_p->servptr->name,
					data->id, agent_p->id);
			return;
		}
	}

	sendto_server(NULL, NULL, CAP_TS6|CAP_ENCAP, NOCAPS, ":%s ENCAP * SASL %s * D A", me.id,
			data->id);
}
Beispiel #16
0
static inline bool unregister_hotkey(obs_hotkey_id id)
{
	if (id >= obs->hotkeys.next_id)
		return false;

	size_t idx;
	if (!find_id(id, &idx))
		return false;

	obs_hotkey_t *hotkey = &obs->hotkeys.hotkeys.array[idx];

	hotkey_signal("hotkey_unregister", hotkey);

	release_registerer(hotkey);

	bfree(hotkey->name);
	bfree(hotkey->description);

	if (hotkey->registerer_type == OBS_HOTKEY_REGISTERER_SOURCE)
		obs_weak_source_release(hotkey->registerer);

	da_erase(obs->hotkeys.hotkeys, idx);
	remove_bindings(id);

	return obs->hotkeys.hotkeys.num >= idx;
}
Beispiel #17
0
/* free dynamically-linked library */
int dlclose(void *handle)
{
    int rc;
    DLLchain tmp = find_id(handle);

    if (!tmp)
        goto inv_handle;

    switch (rc = DosFreeModule(tmp->handle))
    {
        case NO_ERROR:
            free(tmp->name);
            dlload = tmp->next;
            free(tmp);
            return 0;
        case ERROR_INVALID_HANDLE:
inv_handle:
            strcpy(dlerr, "invalid module handle");
            return -1;
        case ERROR_INVALID_ACCESS:
            strcpy(dlerr, "access denied");
            return -1;
        default:
            return -1;
    }
}
Beispiel #18
0
/*
 * Detect any quirks the device has, and do any housekeeping for it if needed.
 */
void usb_detect_quirks(struct usb_device *udev)
{
	const struct usb_device_id *id = usb_quirk_list;

	id = find_id(udev);
	if (id)
		udev->quirks = (u32)(id->driver_info);
	if (udev->quirks)
		dev_dbg(&udev->dev, "USB quirks for this device: %x\n",
				udev->quirks);

	/* For the present, all devices default to USB-PERSIST enabled */






	/* In the absence of PM, we can safely enable USB-PERSIST
	 * for all devices.  It will affect things like hub resets
	 * and EMF-related port disables.
	 */
	if (!(udev->quirks & USB_QUIRK_RESET_MORPHS))
		udev->persist_enabled = 1;

}
bool QAccel::disconnectItem( int id, const QObject *receiver,
			     const char *member )
{
    QAccelItem *item = find_id( d->aitems, id);
    if ( item && item->signal )
	return item->signal->disconnect( receiver, member );
    return FALSE;
}
Beispiel #20
0
void list_char_rem(struct _list_char *list, const char *string)
{
	int id = find_id(list, string, BY_PLAIN);
	if (id == -1)
		return;

	rem_by_id(list, id);
}
Beispiel #21
0
struct _list_char_data* list_char_find(struct _list_char *list, const char *string, int mode)
{
	int id = find_id(list, string, mode);
	if (id == -1)
		return NULL;

	return &list->data[id];
}
Beispiel #22
0
                TValue get(const TId id) const final {
                    const auto result = find_id(id);
                    if (result == m_vector.end() || result->first != id) {
                        throw osmium::not_found{id};
                    }

                    return result->second;
                }
Beispiel #23
0
                TValue get_noexcept(const TId id) const noexcept final {
                    const auto result = find_id(id);
                    if (result == m_vector.end() || result->first != id) {
                        return osmium::index::empty_value<TValue>();
                    }

                    return result->second;
                }
Beispiel #24
0
id_rec *
find_id (id_rec *tree, const char *id)
{
  int cmp_result;
  
  /* Check for an empty tree. */
  if (tree == NULL)
    return NULL;

  /* Recursively search the tree. */
  cmp_result = strcmp (id, tree->id);
  if (cmp_result == 0)
    return tree;  /* This is the item. */
  else if (cmp_result < 0)
    return find_id (tree->left, id);
  else
    return find_id (tree->right, id);  
}
Beispiel #25
0
int Cpkt_ts_ini_reader::process_section_start(const string& line)
{
    m_section = static_cast<t_section_id>(find_id(line, section_code, sei_unknown));
    if (m_section != sei_unknown)
        return 0;
    if (!m_map_list.count(line))
        return 1;
    m_current_map = line;
    return 0;
}
Beispiel #26
0
static int
mr_authenticate(struct Client *client_p, struct Client *source_p,
	int parc, const char *parv[])
{
	struct Client *agent_p = NULL;

	/* They really should use CAP for their own sake. */
	if(!IsCapable(source_p, CLICAP_SASL))
		return 0;

	if (strlen(client_p->id) == 3)
	{
		exit_client(client_p, client_p, client_p, "Mixing client and server protocol");
		return 0;
	}

	if(source_p->preClient->sasl_complete)
	{
		sendto_one(source_p, form_str(ERR_SASLALREADY), me.name, EmptyString(source_p->name) ? "*" : source_p->name);
		return 0;
	}

	if(strlen(parv[1]) > 400)
	{
		sendto_one(source_p, form_str(ERR_SASLTOOLONG), me.name, EmptyString(source_p->name) ? "*" : source_p->name);
		return 0;
	}

	if(!*source_p->id)
	{
		/* Allocate a UID. */
		strcpy(source_p->id, generate_uid());
		add_to_id_hash(source_p->id, source_p);
	}

	if(*source_p->preClient->sasl_agent)
		agent_p = find_id(source_p->preClient->sasl_agent);

	if(agent_p == NULL)
	{
		if (!strcmp(parv[1], "EXTERNAL") && source_p->certfp != NULL)
			sendto_server(NULL, NULL, CAP_TS6|CAP_ENCAP, NOCAPS, ":%s ENCAP * SASL %s * S %s %s", me.id,
					source_p->id, parv[1],
					source_p->certfp);
		else
			sendto_server(NULL, NULL, CAP_TS6|CAP_ENCAP, NOCAPS, ":%s ENCAP * SASL %s * S %s", me.id,
					source_p->id, parv[1]);
	}
	else
		sendto_one(agent_p, ":%s ENCAP %s SASL %s %s C %s", me.id, agent_p->servptr->name,
				source_p->id, agent_p->id, parv[1]);
	source_p->preClient->sasl_out++;

	return 0;
}
Beispiel #27
0
int is_match(struct entry *entries, uint seed) {
	int visited[6] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};
	int i;
	for (i = 0; i < 6; i ++) {
		int id = SEED_TO_RAND(seed);
		int index = find_id(id, entries, visited);
		if (index == -1) return FALSE;
		seed = step_pid(seed, entries[index].nature);
	}
	return TRUE;
}
Beispiel #28
0
int buffer_share_rm_id(struct buffer_share *mix, unsigned int id)
{
	struct id_offset *o;

	o = find_id(mix, id);
	if (!o)
		return -ENOENT;
	o->used = 0;
	o->data = NULL;

	return 0;
}
int main(void) {
    /// read data to array
    TYPE count = 0;
    while(count < MAX_COUNT && scanf("%u\n", array + count) == 1) {
        ++count;
    }
    /// find id
    TYPE id = find_id(array, count);
    /// output result
    printf("max repeat count element is %d.\n", id);
    return EXIT_SUCCESS;
}
bool QAccel::connectItem( int id, const QObject *receiver, const char *member )
{
    QAccelItem *item = find_id( d->aitems, id);
    if ( item ) {
	if ( !item->signal ) {
	    item->signal = new QSignal;
	    Q_CHECK_PTR( item->signal );
	}
	return item->signal->connect( receiver, member );
    }
    return FALSE;
}