Esempio n. 1
0
/* =============================================================================
 * rbtree_insert
 * -- Returns TRUE on success
 * =============================================================================
 */
bool_t
rbtree_insert (rbtree_t* r, void* key, void* val)
{
    node_t* node = getNode();
    node_t* ex = INSERT(r, key, val, node);
    if (ex != NULL) {
        releaseNode(node);
    }
    return ((ex == NULL) ? TRUE : FALSE);
}
Esempio n. 2
0
void *
CrT_malloc(size_t size, const char *file, int line)
{
#if defined(HAVE_PTHREAD_H)
	LOCKCRT();
#endif
    Block b = block_find(file, line);

    Header m = (Header) malloc(size + CRT_OVERHEAD_BYTES);

    if (!m) {
        fprintf(stderr, "CrT_malloc(): Out of Memory!\n");
        abort();
    }

    m->b = b;
    m->size = size;



#ifdef CRT_DEBUG_ALSO
    /* Look around for trashed ram blocks: */
    CrT_check(file, line);

    /* Remember where end of block is: */
    m->end = &((char *) m)[size + (CRT_OVERHEAD_BYTES - 1)];

    /* Write a sacred value at end of block: */
    *m->end = CRT_MAGIC;

    /* Thread m into linklist of allocated blocks: */
    INSERT(m);

    /* Remember we've touched 'm' recently: */
    just_touched[++next_touched & (CRT_NEW_TO_CHECK - 1)] = m;

#endif


    b->tot_bytes_alloc += size;
    b->tot_allocs_done++;
    b->live_blocks++;
    b->live_bytes += size;

    if (b->live_bytes > b->max_bytes) {
        b->max_bytes = b->live_bytes;
        b->max_bytes_time = time(NULL);
    }
    if (b->live_blocks > b->max_blocks)
        b->max_blocks = b->live_blocks;
#if defined(HAVE_PTHREAD_H)
	UNLOCKCRT();
#endif
    return (void *) (m + 1);
}
static bool testHashRemove(){
	bool result = true;

	ESSENTIAL_VARIABLES();

	// Insert and remove all 0-99
	for (int i=0 ; i<100 ; ++i){
		INSERT(hash, i, 2*i);
	}
	for (int i=0 ; i<99 ; ++i){
		REMOVE(hash, i);
	}
	REMOVE_LAST(hash, 99);

	// Insert and remove all odd keys 1-999
	for (int i=1 ; i<1000 ; i+=2){
		INSERT(hash, i, 2*i);
	}
	for (int i=1 ; i<999 ; i+=2){
		REMOVE(hash, i);
	}
	REMOVE_LAST(hash, 999);

	// Insert all 0-999
	for (int i=0 ; i<1000 ; ++i){
		INSERT(hash, i, 2*i);
	}

	// Remove all even
	for (int i=998 ; i>=0 ; i-=2){
		REMOVE(hash, i);
	}

	// Remove all odd
	for (int i=1 ; i<999 ; i+=2){
		REMOVE(hash, i);
	}
	REMOVE_LAST(hash, 999);


	return result;
}
Esempio n. 4
0
/* =============================================================================
 * rbtree_update
 * -- Return FALSE if had to insert node first
 * =============================================================================
 */
bool_t
rbtree_update (rbtree_t* r, void* key, void* val)
{
    node_t* nn = getNode();
    node_t* ex = INSERT(r, key, val, nn);
    if (ex != NULL) {
        STF(ex, v, val);
        releaseNode(nn);
        return TRUE;
    }
    return FALSE;
}
Esempio n. 5
0
void INSERT(node *root, int i)//working correctly
{
    if(root==NULL)
        return;
    if(i<root->lower)
        INSERT(root->lChild,i);
    else if(i>root->upper)
        INSERT(root->rChild,i);
    else
    {
        list *templist = (list*)malloc(sizeof(list));
        templist=root->listptr;
        while(templist->next!=NULL&&templist->data<=i)
            templist=templist->next;
        if(templist->next!=NULL)//sorting needed
        {
            int j,k,shifts=1;
            list *tempsort = (list*)malloc(sizeof(list));
            tempsort=templist->next;
            while(tempsort->next!=NULL)//count shifts
            {
                tempsort=tempsort->next;
                shifts++;
            }
            for (j=shifts;j>0;j--)
            {
                tempsort=templist;
                for (k=1;k<j;++k)
                    tempsort=tempsort->next;
                tempsort->next->data=tempsort->data;
            }
        }
        templist->data=i;
        list *newnode = (list*)malloc(sizeof(list));
        newnode->next=NULL;
        while(templist->next!=NULL)
            templist=templist->next;
        templist->next=newnode;
    }
}
Esempio n. 6
0
//inst : db . string . instaux
void inst(){
Test_Symbole(DB_TOKEN,DB_ERR);
Test_Symbole(POINT_TOKEN,POINT_ERR);
Test_Symbole(STRING_TOKEN,STRING_ERR);
Test_Symbole(POINT_TOKEN,POINT_ERR);
    switch(sym_cour.code){
        case FIND_TOKEN : sym_suiv(); Test_Symbole(PARO_TOKEN,PARO_ERR);QUERY();break;
        case UPDATE_TOKEN : sym_suiv(); Test_Symbole(PARO_TOKEN,PARO_ERR);UPDATE();break;
        case INSERT_TOKEN :sym_suiv(); Test_Symbole(PARO_TOKEN,PARO_ERR);INSERT();break;
        default :  Error(INST_ERR) ; break;
    }
Test_Symbole(PARF_TOKEN,PARF_ERR);
}
Esempio n. 7
0
main() {
	LIST L, p, p2;
	char ans, element;

	MAKENULL(&L);

	do {
		clrscr();
		printf("\n	MENU\n");
		printf("[1] Insert\n");
		printf("[2] Delete\n");
		printf("[3] Display\n");
		printf("[4] Search\n");
		printf("[5] Quit\n\n");
		printf("Enter chosen number: ");
		ans = toupper(getche());
		switch (ans) {
			case '1':
				/* case 1 has an approximated running time of 3n + 12 */
				printf("\n\nEnter an element to insert: ");
				element = getche();
				p = INS_POS(element, L);
				INSERT(element, p);
				break;
			case '2' :
				/* case 2 has an approximated running time of 8n + 10 */
				printf("\n\nEnter element to delete: ");
				element = getche();
				p = LOCATE(element,L);
				DELETE(element, p);
				break;
			case '3' :
				/* case 3 has an approximated running time of 3n + 4 */
				printf("\n\n");
				PRINTLIST(L);
				break;
			case '4' :
				/* case 4 has an approximated running time of 4n + 14 */
				printf("\n\nEnter element to search: ");
				element = getch();
				p = LOCATE(element,L);
				SEARCH(element, p);
				break;
			case '5' :
				break;
		}
	} while (ans != '5');
	DELETEALL(p); /* DELETEALL has an approximated runnning time of 4n + 1 */
}
Esempio n. 8
0
/*
 - p_ere - ERE parser top level, concatenation and alternation
 == static void p_ere(struct parse *p, int stop, size_t reclimit);
 */
static void
p_ere(
    struct parse *p,
    int stop,			/* character this ERE should end at */
    size_t reclimit)
{
	char c;
	sopno prevback = 0;	/* pacify gcc */
	sopno prevfwd = 0; 	/* pacify gcc */
	sopno conc;
	int first = 1;		/* is this the first alternative? */

	_DIAGASSERT(p != NULL);

	if (reclimit++ > RECLIMIT || p->error == REG_ESPACE) {
		p->error = REG_ESPACE;
		return;
	}

	for (;;) {
		/* do a bunch of concatenated expressions */
		conc = HERE();
		while (MORE() && (c = PEEK()) != '|' && c != stop)
			p_ere_exp(p, reclimit);
		REQUIRE(HERE() != conc, REG_EMPTY);	/* require nonempty */

		if (!EAT('|'))
			break;		/* NOTE BREAK OUT */

		if (first) {
			INSERT(OCH_, conc);	/* offset is wrong */
			prevfwd = conc;
			prevback = conc;
			first = 0;
		}
		ASTERN(OOR1, prevback);
		prevback = THERE();
		AHEAD(prevfwd);			/* fix previous offset */
		prevfwd = HERE();
		EMIT(OOR2, 0);			/* offset is very wrong */
	}

	if (!first) {		/* tail-end fixups */
		AHEAD(prevfwd);
		ASTERN(O_CH, prevback);
	}

	assert(!MORE() || SEE(stop));
}
Esempio n. 9
0
void link_chquest( CHAR_DATA *ch, CHQUEST_DATA * chquest )
{
    CHQUEST_DATA           *tmp;

    if ( !chquest || !ch || !ch->pcdata )
        return;

    for ( tmp = ch->pcdata->first_quest; tmp; tmp = tmp->next ) {
        if ( chquest->questnum < tmp->questnum ) {
            INSERT( chquest, tmp, ch->pcdata->first_quest, next, prev );
            return;
        }
    }
    LINK( chquest, ch->pcdata->first_quest, ch->pcdata->last_quest, next, prev );
}
static bool testHashSearch(){
	bool result = true;

	ESSENTIAL_VARIABLES();

	for (int i=0 ; i<1000 ; ++i){
		INSERT(hash, i, 2*i);
	}

	for (int key=0 ; key<1000 ; ++key){
		Data data = hash.search(key);
		ASSERT_TEST(data == 2*key);
	}

	return result;
}
Esempio n. 11
0
void
_PyStackless_Init(void)
{
	PyObject *dict;
	PyObject *modules;
	char *name = "stackless";
	PySlpModuleObject *m;

	if (init_slpmoduletype())
		return;

	/* record the thread state for thread support */
	slp_initial_tstate = PyThreadState_GET();

	/* smuggle an instance of our module type into modules */
	/* this is a clone of PyImport_AddModule */

	modules = PyImport_GetModuleDict();
	slp_module = slpmodule_new(name);
	if (slp_module == NULL || PyDict_SetItemString(modules, name, slp_module)) {
		Py_DECREF(slp_module);
		return;
	}
	Py_DECREF(slp_module); /* Yes, it still exists, in modules! */

	/* Create the module and add the functions */
	slp_module = Py_InitModule3("stackless", stackless_methods, stackless__doc__);
	if (slp_module == NULL)
		return; /* errors handled by caller */

	if (init_prickelpit()) return;

	dict = PyModule_GetDict(slp_module);

#define INSERT(name, object) \
	if (PyDict_SetItemString(dict, name, (PyObject*)object) < 0) return

	INSERT("slpmodule", PySlpModule_TypePtr);
	INSERT("cframe",    &PyCFrame_Type);
	INSERT("cstack",    &PyCStack_Type);
	INSERT("bomb",	    &PyBomb_Type);
	INSERT("tasklet",   &PyTasklet_Type);
	INSERT("channel",   &PyChannel_Type);
	INSERT("stackless", slp_module);

	m = (PySlpModuleObject *) slp_module;
	slpmodule_set__tasklet__(m, &PyTasklet_Type, NULL);
	slpmodule_set__channel__(m, &PyChannel_Type, NULL);
}
Esempio n. 12
0
/*
 * Parse "interface" keyword.
 */
static int
InterfaceFunc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
	struct mystate *softc;
	struct iface *iface;
	Jim_Obj *ipobj;
	const char *ip;
	const char *name;
	int error;

	iface = NULL;
	ipobj = NULL;
	ip = name = NULL;
	error = 0;

	if (argc != 3)
		return (JIM_ERR);

	softc = Jim_CmdPrivData(interp);

	/* Name of the interface. */
	name = Jim_GetString(argv[1], NULL);

	softc->block_parsing = 1;
	/* Body of the block */
	error = Jim_EvalObj(interp, argv[2]);
	if (error) {
		printf("couldn't evaluate\n");
		return (JIM_ERR);
	}
	softc->block_parsing = 0;

	/* Take our hidden variable */
	ipobj = Jim_GetVariableStr(interp, JCONF_VAR_IP, JIM_NONE);
	assert(ipobj != NULL);

	ip = Jim_GetString(ipobj, NULL);
	if (ip == NULL) {
		Jim_fprintf(interp, interp->cookie_stdout, "NULL!\n");
		return (JIM_ERR);
	}
	iface = iface_alloc(ip, name);
	assert(iface != NULL);
	INSERT(softc->head, iface);
	return (JIM_OK);
}
Esempio n. 13
0
//inst : db . string . instaux
void inst(){
collection=(char*)malloc(1024*sizeof(char));
Test_Symbole(DB_TOKEN,DB_ERR);
Test_Symbole(POINT_TOKEN,POINT_ERR);
strcpy(collection,sym_cour.nom);
strcat(collection,".txt");
Test_Symbole(STRING_TOKEN,STRING_ERR);
Test_Symbole(POINT_TOKEN,POINT_ERR);
    switch(sym_cour.code){
        case FIND_TOKEN : sym_suiv(); Test_Symbole(PARO_TOKEN,PARO_ERR);QUERY();break;
        case UPDATE_TOKEN : sym_suiv(); Test_Symbole(PARO_TOKEN,PARO_ERR);UPDATE();break;
        case INSERT_TOKEN :sym_suiv(); Test_Symbole(PARO_TOKEN,PARO_ERR);INSERT();break;
        case REMOVE_TOKEN :sym_suiv(); Test_Symbole(PARO_TOKEN,PARO_ERR);REMOVE();break;
        default :  Error(INST_ERR) ; break;
    }
Test_Symbole(PARF_TOKEN,PARF_ERR);
}
Esempio n. 14
0
int main()
{
	int l=1,up=20,n=8,i;
	//printf("%d %d %d  \n",l,up,n);
	int length= ceil((up-l)/(n*1.00));
	Node* root=malloc(sizeof(Node));
	//int upper=16;
	//printf("%d %d %d  \n",l,upper,n);
	//printf(">> %d \n",length);
	_CREATE_INTERVAL_TREE(root,l,up,n,length,1);

	structure(root,2);

	for(i=l;i<=up;i++)
	{
		INSERT(root,i);
	}
	// INSERT(root,5);
	// INSERT(root,1);
	// INSERT(root,2);
	// INSERT(root,3);
	// INSERT(root,5);

	structureList(root,2);


	// printf("\n\nMERGE PROCESSS STARTED \n");
	// MERGE(root,1,9,NULL,NULL);
	//MERGE(root,16,25,NULL,NULL);
	//structure(root,2);
	//Q_MERGE(&root,1,4);
	//Q_MERGE(&root,1,3);

	//CHANGE_TREE(&root,l,up,4);
	printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n");
	structure(root,2);

	//structureList(root,2);



	//structureList(root,2);

}
Esempio n. 15
0
static int process_cmd (const char *line)
{
    RESULT[0] = '\0';
    if      (matchstr (&line, "EJECT"))        return EJECT (line);
    else if (matchstr (&line, "INSERT"))       return INSERT (line);
    else if (matchstr (&line, "QUERY"))        return QUERY (line);
    else if (matchstr (&line, "FEEDBACK"))     return FEEDBACK (line);
    else if (matchstr (&line, "VERSION"))      return GET_VERSION (line);
    else if (matchstr (&line, "BYE"))          QUIT ();
    else if (matchstr (&line, "QUIT"))         QUIT ();
    else if (matchstr (&line, "DEBUG"))        return DEBUG ();
    else if (matchstr (&line, "RESET"))        m68k_reset (0);
    else if (matchstr (&line, "DISPLAY"))      return DISPLAY (line);
    else if (matchstr (&line, "FRAMERATE"))    return FRAMERATE( line);
    else if (matchstr (&line, "FAKEJOYSTICK")) return FAKEJOYSTICK (line);
    else if (matchstr (&line, "SOUND"))        return SOUND (line);
    else if (matchstr (&line, "UAEEXE"))       return UAEEXE (line);
    else return RC_ERROR;
    return RC_OK;
}
Esempio n. 16
0
void add_chapter( QUEST_DATA * quest, CHAP_DATA * chap )
{
    CHAP_DATA              *tmp;

    if ( !chap ) {
        bug( "%s", "Add_chapter: NULL chap" );
        return;
    }
    if ( !quest ) {
        bug( "%s", "ADD_chapter: NULL quest" );
        return;
    }

    for ( tmp = quest->first_chapter; tmp; tmp = tmp->next ) {
        if ( chap->number < tmp->number ) {
            INSERT( chap, tmp, quest->first_chapter, next, prev );
            return;
        }
    }
    LINK( chap, quest->first_chapter, quest->last_chapter, next, prev );
}
Esempio n. 17
0
bool DataMapper<Subclass, T, I>::save(T * model)
{
    if (!model)
    {
        return false;
    }

    Identity id = idOf(model);
    QVariantMap record;
    buildRecordFrom(model, record);

    QList<QString> variables = record.keys();

    if (isValidId(id))
    {
        record[identityFieldName()] = id;

        QSqlQuery query = getDatabase().build(UPDATE(table()).SET(variables).WHERE(identityFieldName() + " = :" + identityFieldName()), record);

        query.exec();
    }
    else
    {
        QSqlQuery query = getDatabase().build(INSERT().INTO(table()).SET(variables, true), record);

        if (query.exec())
        {
            Identity id = query.lastInsertId().value<Identity>();

            if (isValidId(id))
            {
                m_identities.registerModel(id, model);
            }
        }
    }

    saveRelationsOf(model);

    return true;
}
Esempio n. 18
0
File: MMFX.c Progetto: brawer/afdko
/* Add metric data */
static unsigned addMetric(MMFXCtx h, long id, FWord *metric) {
    Metric *dst;
    size_t index;
    MetricLookup met;
    char cstr[64];
    int found;

    met.ctx = h;
    met.cstr = cstr;
    met.length = hotMakeMetric(h->g, metric, met.cstr);
    found = ctuLookup(&met, h->metrics.array, h->metrics.cnt, sizeof(Metric),
                      matchMetric, &index, h);
    if (id == -1) {
        /* Unnamed metric */
        if (found) {
            /* Already in list; return its id */
            return h->metrics.array[index].id;
        }
        else {
            /* Not in list; allocate id */
            id = h->nextUnnamedId++;
        }
    }

    /* Insert id in list */
    dst = INSERT(h->metrics, index);
    dst->id = (unsigned short)id;
    dst->length = met.length;
    if (found) {
        /* Record index of charstring already in pool */
        dst->index = h->metrics.array[index].index;
    }
    else {
        /* Add new charstring to pool */
        dst->index = h->cstrs.cnt;
        memcpy(dnaEXTEND(h->cstrs, met.length), met.cstr, met.length);
    }

    return (unsigned)id;
}
Esempio n. 19
0
/*
 - p_ere - ERE parser top level, concatenation and alternation
 */
static void
p_ere(struct parse *p, int stop)	/* character this ERE should end at */
{
	char c;
	sopno prevback;
	sopno prevfwd;
	sopno conc;
	int first = 1;		/* is this the first alternative? */

	for (;;) {
		/* do a bunch of concatenated expressions */
		conc = HERE();
		while (MORE() && (c = PEEK()) != '|' && c != stop)
			p_ere_exp(p);
		REQUIRE(HERE() != conc, REG_EMPTY);	/* require nonempty */

		if (!EAT('|'))
			break;		/* NOTE BREAK OUT */

		if (first) {
			INSERT(OCH_, conc);	/* offset is wrong */
			prevfwd = conc;
			prevback = conc;
			first = 0;
		}
		ASTERN(OOR1, prevback);
		prevback = THERE();
		AHEAD(prevfwd);			/* fix previous offset */
		prevfwd = HERE();
		EMIT(OOR2, 0);			/* offset is very wrong */
	}

	if (!first) {		/* tail-end fixups */
		AHEAD(prevfwd);
		ASTERN(O_CH, prevback);
	}

	assert(!MORE() || SEE(stop));
}
Esempio n. 20
0
/* FIRST VERSION!!!!!   WARNING
*/
void INSERT(Subgraph* sg, int z, int r, int* t, int* oldNodes) {
    //printf("\t\tINSERT: z is %d, r is %d, t is %d\n", z, r, *t);
    oldNodes[r] = 1; // mark as 'old'
    int m = r; // aresta (r,z);
    int k;

    // for each vertex w adjacent to 'r'
    Set *w = sg->node[r].incAdj;
    while (w != NULL) {
    	// if adjacent node is new and of same label
    	if (!oldNodes[w->elem]) {
    		INSERT(sg, z, w->elem, t, oldNodes); // insert on w->elem
    		
    		double costWR = opf_ArcWeight(sg->node[w->elem].feat, sg->node[r].feat, sg->nfeats);
    		double costT  = opf_ArcWeight(sg->node[*t].feat, sg->node[z].feat, sg->nfeats);
    		double costK, costM;

    		// max edge (t, (w,r))
    		if (costT > costWR) {
    			// insert WR
       			InsertSet(&sg->node[r].incAdj, w->elem);
    		 	sg->node[r].pred = w->elem;
    			k = *t;
    			costK = opf_ArcWeight(sg->node[*t].feat, sg->node[z].feat, sg->nfeats);
    		} else {
    			// insert TZ
    	 		InsertSet(&sg->node[z].incAdj, *t);
    		 	sg->node[z].pred = *t;
    			k = w->elem;
    			costK = opf_ArcWeight(sg->node[w->elem].feat, sg->node[z].feat, sg->nfeats);
    		}	
    		costM = opf_ArcWeight(sg->node[m].feat, sg->node[z].feat, sg->nfeats);

    		if (costK < costM) m = k; // deixa a outra para avaliar depois
    	}
          w = w->next;
    }
    *t = m;
}
Esempio n. 21
0
// パスを読み込み
void HERE::loadPaths( string _path )
{
	HERE::m_path.clear();
	ifstream ifs( _path );
	//1行分のバッファ
	string line;
	//最初の1行は捨てる
	getline( ifs, line );
	int lineCount = -1;
	while( ifs && getline( ifs, line ) ){
		lineCount++;
		vector<string> cells;
		HERE::cutLine( line, cells );
		int i=0;
		if( cells.size() <= 1 ){ 
			continue;
		}
		string ailias = getcell(i++,cells);
		string path   = getcell(i++,cells);
		INSERT( HERE::m_path, ailias, path );
	}
}
Esempio n. 22
0
void main()
{
	clrscr();
	int a[20],n,insert,Delete,choice;
	cout<<"\nEnter the no of terms:";
	cin>>n;
	cout<<"\nEnter the elements:";
	for(int i=0;i<n;i++)
     {  cout<<"\nElement["<<i<<"]:";
	cin>>a[i];
     }
	cout<<"\nArray is:";
	for(i=0;i<n;i++)
	cout<<a[i]<<" ";
	cout<<"\n1.Insert\n2.Delete"<<endl;
	cin>>choice;
	if(choice==1)
     {
	 cout<<"\nEnter the no to insert:";
	 cin>>insert;
	 INSERT(a,n,insert);
     }
Esempio n. 23
0
void eat(node* T, node* N, int check, int flag)
{
    if (T==NULL)
        return;
    if(T->lower>=N->lower&&T->upper<=N->upper)
    {
        list *listdata = (list*)malloc(sizeof(list));
        listdata=T->listptr;
        while(listdata->next!=NULL&&listdata->data!=0)
        {
            INSERT(N,listdata->data);
            listdata=listdata->next;
        }
        eat(T->lChild,N,0,0);
        eat(T->rChild,N,1,0);
        return;
    }
    else if(check==0&&N->lower>T->upper)
    {
        eat(T->rChild,N,1,1);
        if(T->rChild!=NULL&&T->rChild->lower>=N->lower&&T->rChild->upper<=N->upper)
            T->rChild=NULL;
        if(flag==0)
            N->lChild=T;
    }
    else if(check==1&&T->lower>N->upper)
    {
        eat(T->lChild,N,0,1);
        if(T->lChild!=NULL&&T->lChild->lower>=N->lower&&T->lChild->upper<=N->upper)
            T->lChild=NULL;
        if(flag==0)
            N->rChild=T;
    }
    else if(check==0&&flag==0)
        N->lChild=T;
    else if(check==1&&flag==0)
        N->rChild=T;
}
Esempio n. 24
0
void add_quest( QUEST_DATA * quest )
{
    QUEST_DATA             *tmp;
    int                     qcount = 0;

    if ( !quest ) {
        bug( "%s", "Add_quest: NULL quest" );
        return;
    }

    if ( !quest->name ) {
        bug( "%s", "Add_quest: NULL quest->name" );
        return;
    }

    if ( quest->number != -1 && get_quest_from_number( quest->number ) != NULL ) {
        bug( "%s: Already a quest numbered %d!", __FUNCTION__, quest->number );
        return;
    }

    for ( tmp = first_quest; tmp; tmp = tmp->next ) {
        /*
         * Get the highest number used so far and use the one after that 
         */
        if ( qcount < tmp->number )
            qcount = tmp->number;

        if ( quest->number != -1 && quest->number < tmp->number ) {
            INSERT( quest, tmp, first_quest, next, prev );
            return;
        }
    }

    if ( quest->number == -1 )
        quest->number = ( qcount + 1 );

    LINK( quest, first_quest, last_quest, next, prev );
}
Esempio n. 25
0
/* Rechecking prototypes function
    checks if a new node is closer to its own prototype (becoming a new node)
    or if it is closer to the other prototype (becoming the new prototype) */
void recheckPrototype(Subgraph* sg, int newNode, int predecessor){
  // Clarification: 'inner prototype': prototype of newNode's tree
  //                'outer prototype': prototype of the closest distinct tree; pair of inner-prototype

  // If the inner prototype is alone (has no outer prototype), simply inserts
  if (sg->node[predecessor].prototypePair == NIL) {
    //insert();
    return;
  }
  // Measures the distance between newNode's prototype and its own pair
  float prototypesDistance = opf_ArcWeight(sg->node[sg->node[predecessor].prototypePair].feat, sg->node[predecessor].feat, sg->nfeats);
  // Measures the distance between newNode and its prototype's pair
  float newNodeDistance = opf_ArcWeight(sg->node[newNode].feat, sg->node[sg->node[predecessor].prototypePair].feat, sg->nfeats);

  // If newNode is closer to the outer prototype than the inner prototype, it becomes the new prototype
  if (newNodeDistance < prototypesDistance){
    // newNode becomes a prototype and begins reconquest
    sg->node[newNode].pred = NIL;
    sg->node[newNode].pathval = 0;

    //adds its former prototype as an adjacent and updates its pathval
    InsertSet(&(sg->node[newNode].incAdj), predecessor);
    sg->node[predecessor].pred = newNode;
    sg->node[predecessor].pathval = opf_ArcWeight(sg->node[predecessor].feat, sg->node[newNode].feat, sg->nfeats);

    //printf("\tThe new node is the new prototype! Begin the reconquest...");
    reconquest(sg, newNode);
  } else { // else, newNode simply gets inserted in the tree
    int* oldNodes = (int*)calloc(sg->nnodes, sizeof(int));
    int t = 0;

    //printf("\tThe new node is not a prototype! Begin INSERT...\n");
    INSERT(sg, newNode, predecessor, &t, oldNodes);

    free(oldNodes);
  }
}
Esempio n. 26
0
/*
 - repeat - generate code for a bounded repetition, recursively if needed
 */
static void
repeat(struct parse *p,
    sopno start,		/* operand from here to end of strip */
    int from,			/* repeated from this number */
    int to)			/* to this number of times (maybe INFINITY) */
{
	sopno finish = HERE();
#	define	N	2
#	define	INF	3
#	define	REP(f, t)	((f)*8 + (t))
#	define	MAP(n)	(((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N)
	sopno copy;

	if (p->error != 0)	/* head off possible runaway recursion */
		return;

	assert(from <= to);

	switch (REP(MAP(from), MAP(to))) {
	case REP(0, 0):			/* must be user doing this */
		DROP(finish-start);	/* drop the operand */
		break;
	case REP(0, 1):			/* as x{1,1}? */
	case REP(0, N):			/* as x{1,n}? */
	case REP(0, INF):		/* as x{1,}? */
		/* KLUDGE: emit y? as (y|) until subtle bug gets fixed */
		INSERT(OCH_, start);		/* offset is wrong... */
		repeat(p, start+1, 1, to);
		ASTERN(OOR1, start);
		AHEAD(start);			/* ... fix it */
		EMIT(OOR2, 0);
		AHEAD(THERE());
		ASTERN(O_CH, THERETHERE());
		break;
	case REP(1, 1):			/* trivial case */
		/* done */
		break;
	case REP(1, N):			/* as x?x{1,n-1} */
		/* KLUDGE: emit y? as (y|) until subtle bug gets fixed */
		INSERT(OCH_, start);
		ASTERN(OOR1, start);
		AHEAD(start);
		EMIT(OOR2, 0);			/* offset very wrong... */
		AHEAD(THERE());			/* ...so fix it */
		ASTERN(O_CH, THERETHERE());
		copy = dupl(p, start+1, finish+1);
		assert(copy == finish+4);
		repeat(p, copy, 1, to-1);
		break;
	case REP(1, INF):		/* as x+ */
		INSERT(OPLUS_, start);
		ASTERN(O_PLUS, start);
		break;
	case REP(N, N):			/* as xx{m-1,n-1} */
		copy = dupl(p, start, finish);
		repeat(p, copy, from-1, to-1);
		break;
	case REP(N, INF):		/* as xx{n-1,INF} */
		copy = dupl(p, start, finish);
		repeat(p, copy, from-1, to);
		break;
	default:			/* "can't happen" */
		SETERROR(REG_ASSERT);	/* just in case */
		break;
	}
}
Esempio n. 27
0
/*
 - p_simp_re - parse a simple RE, an atom possibly followed by a repetition
 */
static int			/* was the simple RE an unbackslashed $? */
p_simp_re(struct parse *p,
    int starordinary)		/* is a leading * an ordinary character? */
{
	int c;
	int count;
	int count2;
	sopno pos;
	int i;
	sopno subno;
#	define	BACKSL	(1<<CHAR_BIT)

	pos = HERE();		/* repetion op, if any, covers from here */

	assert(MORE());		/* caller should have ensured this */
	c = GETNEXT();
	if (c == '\\') {
		REQUIRE(MORE(), REG_EESCAPE);
		c = BACKSL | GETNEXT();
	}
	switch (c) {
	case '.':
		if (p->g->cflags&REG_NEWLINE)
			nonnewline(p);
		else
			EMIT(OANY, 0);
		break;
	case '[':
		p_bracket(p);
		break;
	case BACKSL|'{':
		SETERROR(REG_BADRPT);
		break;
	case BACKSL|'(':
		p->g->nsub++;
		subno = p->g->nsub;
		if (subno < NPAREN)
			p->pbegin[subno] = HERE();
		EMIT(OLPAREN, subno);
		/* the MORE here is an error heuristic */
		if (MORE() && !SEETWO('\\', ')'))
			p_bre(p, '\\', ')');
		if (subno < NPAREN) {
			p->pend[subno] = HERE();
			assert(p->pend[subno] != 0);
		}
		EMIT(ORPAREN, subno);
		REQUIRE(EATTWO('\\', ')'), REG_EPAREN);
		break;
	case BACKSL|')':	/* should not get here -- must be user */
	case BACKSL|'}':
		SETERROR(REG_EPAREN);
		break;
	case BACKSL|'1':
	case BACKSL|'2':
	case BACKSL|'3':
	case BACKSL|'4':
	case BACKSL|'5':
	case BACKSL|'6':
	case BACKSL|'7':
	case BACKSL|'8':
	case BACKSL|'9':
		i = (c&~BACKSL) - '0';
		assert(i < NPAREN);
		if (p->pend[i] != 0) {
			assert(i <= p->g->nsub);
			EMIT(OBACK_, i);
			assert(p->pbegin[i] != 0);
			assert(OP(p->strip[p->pbegin[i]]) == OLPAREN);
			assert(OP(p->strip[p->pend[i]]) == ORPAREN);
			(void) dupl(p, p->pbegin[i]+1, p->pend[i]);
			EMIT(O_BACK, i);
		} else
			SETERROR(REG_ESUBREG);
		p->g->backrefs = 1;
		break;
	case '*':
		REQUIRE(starordinary, REG_BADRPT);
		/* FALLTHROUGH */
	default:
		ordinary(p, (char)c);
		break;
	}

	if (EAT('*')) {		/* implemented as +? */
		/* this case does not require the (y|) trick, noKLUDGE */
		INSERT(OPLUS_, pos);
		ASTERN(O_PLUS, pos);
		INSERT(OQUEST_, pos);
		ASTERN(O_QUEST, pos);
	} else if (EATTWO('\\', '{')) {
		count = p_count(p);
		if (EAT(',')) {
			if (MORE() && isdigit((uch)PEEK())) {
				count2 = p_count(p);
				REQUIRE(count <= count2, REG_BADBR);
			} else		/* single number with comma */
				count2 = INFINITY;
		} else		/* just a single number */
			count2 = count;
		repeat(p, pos, count, count2);
		if (!EATTWO('\\', '}')) {	/* error heuristics */
			while (MORE() && !SEETWO('\\', '}'))
				NEXT();
			REQUIRE(MORE(), REG_EBRACE);
			SETERROR(REG_BADBR);
		}
	} else if (c == '$')	/* $ (but not \$) ends it */
		return(1);

	return(0);
}
Esempio n. 28
0
/*
 - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op
 */
static void
p_ere_exp(struct parse *p)
{
	char c;
	sopno pos;
	int count;
	int count2;
	sopno subno;
	int wascaret = 0;

	assert(MORE());		/* caller should have ensured this */
	c = GETNEXT();

	pos = HERE();
	switch (c) {
	case '(':
		REQUIRE(MORE(), REG_EPAREN);
		p->g->nsub++;
		subno = p->g->nsub;
		if (subno < NPAREN)
			p->pbegin[subno] = HERE();
		EMIT(OLPAREN, subno);
		if (!SEE(')'))
			p_ere(p, ')');
		if (subno < NPAREN) {
			p->pend[subno] = HERE();
			assert(p->pend[subno] != 0);
		}
		EMIT(ORPAREN, subno);
		MUSTEAT(')', REG_EPAREN);
		break;
#ifndef POSIX_MISTAKE
	case ')':		/* happens only if no current unmatched ( */
		/*
		 * You may ask, why the ifndef?  Because I didn't notice
		 * this until slightly too late for 1003.2, and none of the
		 * other 1003.2 regular-expression reviewers noticed it at
		 * all.  So an unmatched ) is legal POSIX, at least until
		 * we can get it fixed.
		 */
		SETERROR(REG_EPAREN);
		break;
#endif
	case '^':
		EMIT(OBOL, 0);
		p->g->iflags |= USEBOL;
		p->g->nbol++;
		wascaret = 1;
		break;
	case '$':
		EMIT(OEOL, 0);
		p->g->iflags |= USEEOL;
		p->g->neol++;
		break;
	case '|':
		SETERROR(REG_EMPTY);
		break;
	case '*':
	case '+':
	case '?':
		SETERROR(REG_BADRPT);
		break;
	case '.':
		if (p->g->cflags&REG_NEWLINE)
			nonnewline(p);
		else
			EMIT(OANY, 0);
		break;
	case '[':
		p_bracket(p);
		break;
	case '\\':
		REQUIRE(MORE(), REG_EESCAPE);
		c = GETNEXT();
		ordinary(p, c);
		break;
	case '{':		/* okay as ordinary except if digit follows */
		REQUIRE(!MORE() || !isdigit((uch)PEEK()), REG_BADRPT);
		/* FALLTHROUGH */
	default:
		ordinary(p, c);
		break;
	}

	if (!MORE())
		return;
	c = PEEK();
	/* we call { a repetition if followed by a digit */
	if (!( c == '*' || c == '+' || c == '?' ||
				(c == '{' && MORE2() && isdigit((uch)PEEK2())) ))
		return;		/* no repetition, we're done */
	NEXT();

	REQUIRE(!wascaret, REG_BADRPT);
	switch (c) {
	case '*':	/* implemented as +? */
		/* this case does not require the (y|) trick, noKLUDGE */
		INSERT(OPLUS_, pos);
		ASTERN(O_PLUS, pos);
		INSERT(OQUEST_, pos);
		ASTERN(O_QUEST, pos);
		break;
	case '+':
		INSERT(OPLUS_, pos);
		ASTERN(O_PLUS, pos);
		break;
	case '?':
		/* KLUDGE: emit y? as (y|) until subtle bug gets fixed */
		INSERT(OCH_, pos);		/* offset slightly wrong */
		ASTERN(OOR1, pos);		/* this one's right */
		AHEAD(pos);			/* fix the OCH_ */
		EMIT(OOR2, 0);			/* offset very wrong... */
		AHEAD(THERE());			/* ...so fix it */
		ASTERN(O_CH, THERETHERE());
		break;
	case '{':
		count = p_count(p);
		if (EAT(',')) {
			if (isdigit((uch)PEEK())) {
				count2 = p_count(p);
				REQUIRE(count <= count2, REG_BADBR);
			} else		/* single number with comma */
				count2 = INFINITY;
		} else		/* just a single number */
			count2 = count;
		repeat(p, pos, count, count2);
		if (!EAT('}')) {	/* error heuristics */
			while (MORE() && PEEK() != '}')
				NEXT();
			REQUIRE(MORE(), REG_EBRACE);
			SETERROR(REG_BADBR);
		}
		break;
	}

	if (!MORE())
		return;
	c = PEEK();
	if (!( c == '*' || c == '+' || c == '?' ||
				(c == '{' && MORE2() && isdigit((uch)PEEK2())) ) )
		return;
	SETERROR(REG_BADRPT);
}
Esempio n. 29
0
std::map<std::string, sf::Key::Code> ConfigOptions::getNamedKeys()
{
	std::map<std::string, sf::Key::Code> res;

	#define INSERT(identifier) res[#identifier]=sf::Key::identifier;

	INSERT(A);
	INSERT(B);
	INSERT(C);
	INSERT(D);
	INSERT(E);
	INSERT(F);
	INSERT(G);
	INSERT(H);
	INSERT(I);
	INSERT(J);
	INSERT(K);
	INSERT(L);
	INSERT(M);
	INSERT(N);
	INSERT(O);
	INSERT(P);
	INSERT(Q);
	INSERT(R);
	INSERT(S);
	INSERT(T);
	INSERT(U);
	INSERT(V);
	INSERT(W);
	INSERT(X);
	INSERT(Y);
	INSERT(Z);
	INSERT(Num0);
	INSERT(Num1);
	INSERT(Num2);
	INSERT(Num3);
	INSERT(Num4);
	INSERT(Num5);
	INSERT(Num6);
	INSERT(Num7);
	INSERT(Num8);
	INSERT(Num9);
	INSERT(Escape);
	INSERT(LControl);
	INSERT(LShift);
	INSERT(LAlt);
	INSERT(LSystem);
	INSERT(RControl);
	INSERT(RShift);
	INSERT(RAlt);
	INSERT(RSystem);
	INSERT(Menu);
	INSERT(LBracket);
	INSERT(RBracket);
	INSERT(SemiColon);
	INSERT(Comma);
	INSERT(Period);
	INSERT(Quote);
	INSERT(Slash);
	INSERT(BackSlash);
	INSERT(Tilde);
	INSERT(Equal);
	INSERT(Dash);
	INSERT(Space);
	INSERT(Return);
	INSERT(Back);
	INSERT(Tab);
	INSERT(PageUp);
	INSERT(PageDown);
	INSERT(End);
	INSERT(Home);
	INSERT(Insert);
	INSERT(Delete);
	INSERT(Add);
	INSERT(Subtract);
	INSERT(Multiply);
	INSERT(Divide);
	INSERT(Left);
	INSERT(Right);
	INSERT(Up);
	INSERT(Down);
	INSERT(Numpad0);
	INSERT(Numpad1);
	INSERT(Numpad2);
	INSERT(Numpad3);
	INSERT(Numpad4);
	INSERT(Numpad5);
	INSERT(Numpad6);
	INSERT(Numpad7);
	INSERT(Numpad8);
	INSERT(Numpad9);
	INSERT(F1);
	INSERT(F2);
	INSERT(F3);
	INSERT(F4);
	INSERT(F5);
	INSERT(F6);
	INSERT(F7);
	INSERT(F8);
	INSERT(F9);
	INSERT(F10);
	INSERT(F11);
	INSERT(F12);
	INSERT(F13);
	INSERT(F14);
	INSERT(F15);
	INSERT(Pause);

	#undef INSERT

	return res;
}
Esempio n. 30
0
void
test2()
{
    size_t i;
    cuex_t keys[KEY_CNT];
    cuex_t e0, e;
    for (i = 0; i < KEY_CNT; ++i)
	keys[i] = cudyn_int(lrand48() % KEY_MAX);

    /* Test hashcons equality for permuted constructions */
    e0 = aci_from_arr(keys, KEY_CNT);
    for (i = 0; i < REPEAT; ++i) {
	permute(keys, KEY_CNT);
	if (VERBOSE)
	    printf("%p %p %p %p\n", keys[0], keys[1], keys[2], keys[3]);
	e = aci_from_arr(keys, KEY_CNT);
	cu_debug_assert(e == e0);
    }

    /* Test equality for equivalent merges. */
    if (!VERBOSE)
	printf("Merge test");
    for (i = 0; i < 16; ++i) {
	cuex_t eJ, eM;
	if (!VERBOSE) {
	    fputc('.', stdout);
	    fflush(stdout);
	}
	size_t j;
	cuex_t x = cuex_aci_identity(OPR);
	cuex_t y = cuex_aci_identity(OPR);
	cuex_t xy = cuex_aci_identity(OPR);
	struct cucon_pmap_s x_pmap;
	permute(keys, KEY_CNT);
	cucon_pmap_cct(&x_pmap);
	for (j = 0; j < 2*KEY_CNT/3; ++j)
	    cucon_pmap_insert_void(&x_pmap, keys[j]);
	for (j = 0; j < 2*KEY_CNT/3; ++j) {
	    x = INSERT(x, keys[j]);
	    y = INSERT(y, keys[KEY_CNT - j - 1]);
	    if (cucon_pmap_find_void(&x_pmap, keys[KEY_CNT - j - 1]))
		xy = INSERT(xy, keys[KEY_CNT - j - 1]);
	}
	eJ = cuex_aci_join(OPR, x, y);
	eM = cuex_aci_meet(OPR, x, y);
	cu_debug_assert(cuex_aci_leq(OPR, x, eJ));
	cu_debug_assert(cuex_aci_leq(OPR, y, eJ));
	cu_debug_assert(cuex_aci_leq(OPR, eM, x));
	cu_debug_assert(cuex_aci_leq(OPR, eM, y));
	if (VERBOSE) {
	    fputs("x = ", stdout);
	    cuex_aci_dump(x, stdout);
	    fputs("y = ", stdout);
	    cuex_aci_dump(y, stdout);
	    fputs("xy = ", stdout);
	    cuex_aci_dump(xy, stdout);
	    fputc('\n', stdout);
	    fputs("x ∨ y = ", stdout);
	    cuex_aci_dump(eJ, stdout);
	    fputc('\n', stdout);
	    fputs("x ∧ y = ", stdout);
	    cuex_aci_dump(eM, stdout);
	    fputc('\n', stdout);
	}
	cu_debug_assert(eJ == e0);
	cu_debug_assert(eM == xy);
    }
    fputc('\n', stdout);
}