Beispiel #1
0
Tree setUnion (Tree A, Tree B)
{
	if (isNil(A)) 		return B;
	if (isNil(B)) 		return A;
	
	if (hd(A) == hd(B)) return cons(hd(A), setUnion(tl(A),tl(B)));
	if (hd(A) < hd(B)) 	return cons(hd(A), setUnion(tl(A),B));
	/* hd(A) > hd(B) */	return cons(hd(B), setUnion(A,tl(B)));
}
Beispiel #2
0
set* computeFollowSets(int id, prodRuleNode** rulelist, set **firststs, set** followsts, int** rec_stack, int stack_size)
{
    if(rulelist[id]->rhs_occ_cnt == 0)
    {
        set* st = createEmptySet();
        st->val = TK_DOLLAR;
        followsts[id] = st;
        return st;
    }
    if(rulelist[id]->follow_set_flag == 2)
        return followsts[id];
    if(rulelist[id]->follow_set_flag == 1)
    {
        set* com_st = NULL;
        int k;
        int idx;
        // to find the start of the cycle
        for (idx = 0; idx < stack_size; ++idx)
            if((*rec_stack)[idx] == id)
                break;
        for (k = idx; k < stack_size; ++k)
            com_st = setUnion(com_st, followsts[(*rec_stack)[k]]);
        for (k = idx; k < stack_size; ++k)
            followsts[(*rec_stack)[k]] = com_st;
        return followsts[id];
    }
    rulelist[id]->follow_set_flag = 1;
    followsts[id] = NULL;
    int rhs_cnt = rulelist[id]->rhs_occ_cnt;
    int i;
    for (i = 0; i < rhs_cnt; ++i)
    {
        rhsOcc temp = rulelist[id]->rhs_occs[i];
        bool term_flag = false;
        int j = temp.j + 1;
        while(j < rulelist[temp.ntid]->rule_length[temp.i])
        {
            set* fst = computeFirstSets(rulelist[temp.ntid]->prod_rules[temp.i][j], rulelist, firststs);
            followsts[id] = setUnion(followsts[id], fst);
            if(!isPresent(TK_EPS, fst))
            {
                term_flag = true;
                break;
            }
            j++;
        }
        if(term_flag)
            continue;
        (*rec_stack) = (int*) realloc((*rec_stack), sizeof(int) * (stack_size + 1));
        (*rec_stack)[stack_size] = temp.ntid;
        set* flst = computeFollowSets(temp.ntid, rulelist, firststs, followsts, rec_stack, stack_size + 1);
        followsts[id] = setUnion(followsts[id], flst);
    }
    rulelist[id]->follow_set_flag = 2;
    return followsts[id];
}
void testSetUnion(CuTest *tc) {
	char* input1;
	char* input2;
	char* expected;
	set setU;

	input1 = strdup("");  input2=strdup("a c b");  expected = "a b c"; 
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

	input1 = strdup("a b c");  input2=strdup("");  expected = "a b c"; 
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

	input1 = strdup("a b c");  input2=NULL;  expected = NULL; 
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

	input1 = NULL;  input2=strdup("c b a");  expected = NULL; 
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

	// Boundary case - 9 members in result - should be OK
	input1 = strdup("i h g f p a z");  input2=strdup("i h g f e d");  expected = "a d e f g h i p z"; 
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

	// Boundary case - 10 members in result which is ON THE LIMIT, and therefore should return NULL
	input1 = strdup("i h g f p a z x");  input2=strdup("i h g f e d");  expected = NULL;
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

	// Boundary case - 12 members in result which is OVER THE LIMIT, and therefore should return NULL
	input1 = strdup("i h g f p a z x");  input2=strdup("i h g f e d w y");  expected = NULL; //"a d e f g h i p w x y z"; 
	setU = setUnion(input1, input2); CuAssertStrEquals(tc, expected, setU); 

} //testSetUnion
Beispiel #4
0
int main() {
	DisjointSet<int> a, b;

	assert(setFind(&a) == &a);
	assert(setFind(&b) == &b);

	DisjointSet<int>* c = setUnion(&a, &b);
	assert(c == &a);
}
Beispiel #5
0
int main(){

std::cout << setCross (SetFactory(0), SetFactory(1)) << std::endl;
std::cout << setIntersect (SetFactory(0), SetFactory(1)) << std::endl;
std::cout << setMinus (SetFactory(0), SetFactory(1)) << std::endl;
std::cout << setUnion (SetFactory(0), SetFactory(1)) << std::endl;
std::cout << setCardinality (SetFactory(1).add( 2).add( 3)) << std::endl;
return 0;


}
int* findForFollow(Hashtable H, Lexeme L) {
	int i, j;
	int* set;
	int *fset;
	fset = (int*)malloc(FIRST_SET_SIZE*sizeof(int));
	set = (int*)malloc(FOLLOW_SET_SIZE*sizeof(int));
	for (i=0; i<FIRST_SET_SIZE; ++i) {
		fset[i] = 0;
		set[i] = 0;
	}

	for (i=0; i<HASHTABLE_SIZE; ++i) {
		for (j=0; j<HPR; ++j) {
			Lexeme* l;
			l = H[i].nextLexeme[j];
			if (l == NULL) {
				continue;
			}
			do {
				if (strcmp(L.lexName, l->lexName) == 0) {
					//printf("%s\n", H[i].lexemeName);
					if (l->next != NULL) {
						fset = getFirstSet(fset, H, *(l->next));
						set = setUnion(set, fset);
					} else {
						if (strcmp(l->lexName, H[i].lexemeName) == 0)
						{}
						else {
							fset = getFollowSet(H, *(lexemize(H[i].lexemeName)));
							set = setUnion(set, fset);
						}
					}
				}
				l = l->next;
			} while (l != NULL);
		}
	}
	
	return set;
}
Beispiel #7
0
 bool validTree(int n, vector<pair<int, int>>& edges) {
     vector<int> pre(n, 0);
     for (int i = 0; i < n; i++) {
         pre[i] = i;
     }
     for (int i = 0; i < edges.size(); i++) {
         setUnion(pre, edges[i].first, edges[i].second);
     }
     int count = 0;
     for (int i = 0; i < n; i++) {
         if (setFind(pre, i) == i) count++;
     }
     return count == 1 && edges.size() == n - 1;
 }
Beispiel #8
0
int main()
{
    char buffer[80];
    int i, index;
    Set set1, set2, set3;

    i = 0;  
    while ( (scanf("%s",buffer)) != EOF )
    {
        strcpy(names[i],buffer);
        i++;
    }
    printf("The initial data is:\n");
    print(names,i);
    bubbleSort(names,i);
    printf("\n\nThe sorted data is:\n");
    print(names,i);

    clearSet(set1);
    clearSet(set2);
    clearSet(set3);

    printf("Adding Warner, Faulk and Pace to set1:\n");
    addName2Set(set1,"Warner");
    addName2Set(set1,"Faulk");
    addName2Set(set1,"Pace");
    printf("Set1 = ");
    printSet(set1);

    printf("Adding Snider, Robinson and Koufax to set2:\n");
    addName2Set(set2,"Snider");
    addName2Set(set2,"Robinson");
    addName2Set(set2,"Koufax");
    printf("Set2 = ");
    printSet(set2);

    setUnion(set1, set2, set3);
    printf("The union of sets 1 and 2 is: ");
    printSet(set3);
    
    printf("The intersection of sets 3 and 2 is: ");
    setIntersection(set3, set2, set3);
    printSet(set3);

    printf("Deleting Snider from set3:\n");
    deleteNameFromSet(set3,"Snider");    
    printf("Set3 = ");
    printSet(set3);
}
/**
* @brief Finds a next SCC and its represent and returns them.
*
* @param[in] sccs All SCCs in the call graph.
* @param[in] computedFuncs Functions that already have been included in
*                          FuncInfoCompOrder::order.
* @param[in] remainingFuncs Functions that haven't been included in
*                           FuncInfoCompOrder::order.
*
* @par Preconditions
*  - @a remainingFuncs is non-empty
*  - @a remainingFuncs doesn't contain a function which calls just functions
*    from @a computedFuncs.
*/
CallInfoObtainer::SCCWithRepresent CallInfoObtainer::findNextSCC(const FuncSetSet &sccs,
		const FuncSet &computedFuncs, const FuncSet &remainingFuncs) const {
	PRECONDITION(!remainingFuncs.empty(), "it should not be empty");

	//
	// We try to locate an SCC whose members call just the functions in
	// the SCC or in computedFuncs. Then, if the found SCC contains a function
	// from remainingFuncs, return the function.
	//
	// For every SCC...
	for (const auto &scc : sccs) {
		bool sccFound = true;
		ShPtr<Function> funcFromRemainingFuncs;
		// For every function in the SCC...
		for (const auto &func : scc) {
			// Check whether the function calls just the functions in the SCC
			// or in computedFuncs.
			ShPtr<CG::CalledFuncs> calledFuncs(cg->getCalledFuncs(func));
			FuncSet mayCall(setUnion(scc, computedFuncs));
			if (!setDifference(calledFuncs->callees, mayCall).empty()) {
				sccFound = false;
			} else {
				// Have we encountered a function from remainingFuncs?
				if (hasItem(remainingFuncs, func)) {
					funcFromRemainingFuncs = func;
				}
			}
		}
		if (sccFound && funcFromRemainingFuncs) {
			return SCCWithRepresent(scc, funcFromRemainingFuncs);
		}
	}

	// TODO Can this happen?
	printWarningMessage("[SCCComputer] No viable SCC has been found.");
	FuncSet scc;
	ShPtr<Function> func(*(remainingFuncs.begin()));
	scc.insert(func);
	return SCCWithRepresent(scc, func);
}
Beispiel #10
0
/**
 * Find the Canonical set for the grammar.
 */
void Parser::findCanonicalSet() {
  std::set<char> symbols;
  auto current_item = Item(getStartProduction(), START_POS);
  auto current_closure = findClosure({current_item});
  _canon.insert(LRSet(current_closure, 0, '\0'));
  symbols = setUnion(_terminals, _non_terminals);
  int counter = 1;
  bool changed;
  do {
    changed = false;
    for (auto item : _canon) {
      for (auto symbol : symbols) {
        auto new_set = findGoto(item.data, symbol);
        if (!new_set.empty() && !isIn(_canon, new_set)) {
          _canon.insert({new_set, counter, symbol});
          changed = true;
          ++counter;
        }
      }
    }
  } while (changed);
}
Beispiel #11
0
void test()
{
    int s1Init[] = {1,6,7,3,99};
    VSet<int> s1(s1Init, ARRAYEND(s1Init));
    int s2Init[] = {1,-4,42,7,100};
    VSet<int> s2(s2Init, ARRAYEND(s2Init));
    std::cout << s1 << "\n";

    std::cout << "s1.contains(1) = " << s1.contains(1) << "\n";
    std::cout << "s1.contains(-1) = " << s1.contains(-1) << "\n";

    int smallInit[] = {1,6};
    VSet<int> small(smallInit, ARRAYEND(smallInit));
    std::cout << s1 << ".includes(" << small << ") = " << s1.includes(small) << "\n";


    VSet<int> u;
    setUnion(s1, s2, u);
    std::cout << "union(" << s1 << ", " << s2 << ") = " << u << "\n";
    VSet<int> i;
    setIntersection(s1, s2, i);
    std::cout << "intersection(" << s1 << ", " << s2 << ") = " << i << "\n";
}
Beispiel #12
0
set* computeFirstSets(int id, prodRuleNode** rulelist, set** firststs)
{
    if(isTerminal(id))
    {
        set* st = createEmptySet();
        st->val = id;
        return st;
    }
    if(firststs[id] != NULL)
        return firststs[id];
    set* st = NULL;
    prodRuleNode* p = rulelist[id];
    int i, j;
    for (i = 0; i < p->prod_rule_cnt; ++i)
    {
        if(p->prod_rules[i][0] == TK_EPS)
        {
            st = setAdd(TK_EPS, st);
            continue;
        }
        bool flag = false;
        for (j = 0; j < p->rule_length[i]; ++j)
        {
            set* st2 = computeFirstSets(p->prod_rules[i][j], rulelist, firststs);
            st = setUnion(st, st2);
            if(!isPresent(TK_EPS, st2))
            {
                flag = true;
                break;
            }
        }
        if(!flag)
            st = setAdd(TK_EPS, st);
    }
    firststs[id] = st;
    return st;
}
int* getfirstSet(int* firstSet, int firstsetsize, Hashtable H, Lexeme L, int hashtablesize)
{
	int *tset;
	tset = (int*)malloc(FIRST_SET_SIZE*sizeof(int));
	if (L.isTerminal == TRUE) {
		tset[0] = atoi(L.lexName);
		firstSet = setUnion(firstSet, tset);
		return firstSet;
	}
	int index;
	int j=0;
	
	Lexeme* temp;
	index = findinHashtable(H, L, hashtablesize);
	while(H[index].nextLexeme[j] != 0 && j<HPR)
	{
	 	temp = H[index].nextLexeme[j];
	 	if(temp->isTerminal==TRUE)
	 	{
	 		if(ifPresent(firstSet, atoi(temp->lexName), firstsetsize)==FALSE)
	 		{
		 		firstSet[fsc] = atoi(temp->lexName);
		 		fsc++;
		 		j++;
		 		continue; 
	 		}
	 		else continue;
	 	}
	 	else if(temp->isTerminal==FALSE)
	 	{
	 		firstSet = getFirstSet(firstSet, H, *temp);
	 		j++;
	 	}	
	}
	
	return firstSet;
}
Beispiel #14
0
huReturn hookUp(const vector<SplitEdge> &g, int s, vector<SplitEdge> &bIn, int k, vector<vector<int>> &Y, historyIndex &h)
{
	if (cG(s, g) != 0)
	{
		cout << "cG(s) problem in hookup" << endl;
		throw logic_error("");
	}
	vector<SplitEdge> H = g;
	vector<SplitEdge> G1 = g; 
	vector<SplitEdge> B = bIn;
	vector<SplitEdge> B1;
	vector<vector<int>> XS;
	int maxNodeInd = getMaxNodeInd(G1);
	for (int i = 0; i < maxNodeInd; i++)
		XS.push_back(vector<int>());
	for (int i = 0; i < maxNodeInd; i++)
		XS[i].push_back(i);
	//cout << "About to enter while loop" << endl;
	while (getNumUsedNodes(H) >= 4)
	{
		vector<int> ma = maOrderingHeap(H, s);
		int v = ma[ma.size() - 2];
		int w = ma[ma.size() - 1];
		if (v == s || w == s)
			throw logic_error("SET WAS V - S, S FOUND");
		vector<int> X1;
		H = combineVertices(H, v, w);
		H = compress(H);
		XS[v] = setUnion(XS[v], XS[w]);
		if (XS[w].size() == 0)
		{
			cout << "Error: W, " << w << " was merged twice. Quitting" << endl;
			throw logic_error("");
		}
		XS[w] = vector<int>();
		if (cG(v, H) < k)
		{
			int numToGet = (int)ceil(.5*(double(k) - double(cG(G1, XS[v]))));
			vector<SplitEdge> GX = inducedSubgraph(G1, XS[v]);
			vector<SplitEdge> delB;
			int added = 0;
			for (unsigned i = 0; i < GX.size(); i++)
			{
				SplitEdge e = SplitEdge(GX[i].end0, GX[i].end1, GX[i].weight, GX[i].orig0, GX[i].orig1);
				if (isMem(e, B))
				{
					int bW = B[indexOfEdge(B, e.end0, e.end1)].weight;
					if (bW < e.weight)
						e.weight = bW;
					if (e.weight > (numToGet - added))
					{
						e.weight = numToGet - added;
					}
					added += e.weight;
					delB.push_back(e);
				}
				if (added == numToGet)
					break;
			}
			if (added != numToGet)
			{
				cout << "Error: GX did not contain " << numToGet << " entries in B. Quitting." << endl;
				throw logic_error("");
			}
			if (!isSubset(delB, B))
			{
				cout << "ERROR: delB is not a subset of B." << endl;
				cout << "B:" << endl;
				output(B);
				cout << "delB:" << endl;
				output(delB);
				cout << "This was the GX to choose from:" << endl;
				output(GX);
				cout << "V: " << v << endl;
				cout << "W: " << w << endl;
				cout << "S: " << s << endl;
				throw logic_error("");
			}
			B = setRemove(delB, B);
			B = removeZeroWeighted(B);
			B1 = setUnion(delB, B1);
			H = removeZeroWeighted(H);
			G1 = hookUpHelper(s, G1, delB, h);
			G1 = removeZeroWeighted(G1);
			H = removeZeroWeighted(H);
			bool addedFromXSinH = false;
			numToGet *= 2;
			for (unsigned i = 0; i < H.size(); i++)
			{
				SplitEdge tester = SplitEdge(s, v, 0, 0, 0);
				if (equals(tester, H[i]))
				{
					//cout << "Increasing weight in hookUp in H between " << H[i].end0 << " and " << H[i].end1 << "from " << H[i].weight << " to " << H[i].weight + numToGet << endl;
					H[i].weight += numToGet;
					addedFromXSinH = true;
					break;
				}
			}
			if (!addedFromXSinH && numToGet != 0)
			{
				//cout << "Creating edge in hookUp in H between " << s << " and " << v << " with weight " << numToGet << endl;
				SplitEdge e(s, v, numToGet, s, v);
				H.push_back(e);
			}
			vector<vector<int>> newY;
			for (unsigned i = 0; i < Y.size(); i++)
			{
				if (!isProperSubset(Y[i], XS[v]))
					newY.push_back(Y[i]);
			}
			bool foundX1inY = false;
			for (unsigned i = 0; i < newY.size(); i++)
			{
				if (setsEqual(newY[i], XS[v]))
					foundX1inY = true;
			}
			if (!foundX1inY)
				newY.push_back(XS[v]);
			Y = newY;
		}
	}
	huReturn ret;
	ret.BP = B1;
	ret.G1 = G1;
	ret.Y = Y;
	return ret;
}
Beispiel #15
0
 void TagUnion<COUNT>::setPictures(const PictureMap &l)
 {
     setUnion(Pictures, l);
 }
Beispiel #16
0
 void TagUnion<COUNT>::setTrack(unsigned int i)
 {
   setUnion(Track, i);
 }
Beispiel #17
0
 void TagUnion<COUNT>::setYear(unsigned int i)
 {
   setUnion(Year, i);
 }
Beispiel #18
0
 void TagUnion<COUNT>::setGenre(const String &s)
 {
   setUnion(Genre, s);
 }
Beispiel #19
0
 void TagUnion<COUNT>::setComment(const String &s)
 {
   setUnion(Comment, s);
 }
Beispiel #20
0
 void TagUnion<COUNT>::setAlbum(const String &s)
 {
   setUnion(Album, s);
 }
Beispiel #21
0
valType dbGC(void)
{
    valType collected = 0, i;
    dictIterator *iter = NULL;
    dictEntry *entry = NULL;
    set *acc = NULL;

    lockWrite(objectIndex);
    lockRead(sets);

    // Step 1. Union all sets in db.
    if (NULL == (iter = dictGetIterator(sets)))
    {
        unlockRead(sets);
        unlockWrite(objectIndex);
        return 0;
    }

    if (NULL == (acc = setCreate()))
    {
        unlockRead(sets);
        unlockWrite(objectIndex);
        return 0;
    }

    while (NULL != (entry = dictNext(iter)))
    {
        valType currentSetId = 0;
        set *tmp = NULL, *currentSet = (set *) dictGetEntryVal(entry);
        set *flattened = setFlatten(currentSet, 0);

        if (NULL == flattened)
        {
            continue;
        }

        if (1 == dbFindSet(currentSet, &currentSetId, 0))
        {
            if (-1 == setAdd(acc, currentSetId))
            {
                setDestroy(acc);
                dictReleaseIterator(iter);
                unlockRead(sets);
                unlockWrite(objectIndex);
                return 0;
            }
        }

        if (NULL == (tmp = setUnion(acc, flattened)))
        {
            setDestroy(flattened);
            setDestroy(acc);
            dictReleaseIterator(iter);
            unlockRead(sets);
            unlockWrite(objectIndex);
            return 0;
        }

        setDestroy(flattened);
        setDestroy(acc);
        acc = tmp;
    }

    dictReleaseIterator(iter);

    // Step 2. Find objects not present in grand total union.
    for (i = 0; i < objectIndexLength; i++)
    {
        if (NULL != objectIndex[i] && !setIsMember(acc, i))
        {
            dbObjectRelease((dbObject *) objectIndex[i]);
            free((dbObject *) objectIndex[i]);
            objectIndex[i] = NULL;

            if (i < objectIndexFreeId)
            {
                objectIndexFreeId = i;
            }

            collected++;
        }
    }

    setDestroy(acc);

    unlockRead(sets);
    unlockWrite(objectIndex);

    return collected;
}
Beispiel #22
0
void PvObject::setUnion(const boost::python::tuple& pyTuple)
{
    std::string key = PyPvDataUtility::getValueOrSingleFieldName(pvStructurePtr);
    setUnion(key, pyTuple);
}
int main()
{
	int size;
	UnionSet* unionSet;
	ElementType data[] = {110, 245, 895, 658, 321, 852, 147, 458, 469, 159, 347, 28};

	size = 12;
	printf("\n\t====== test for union set by depth ======\n");
	//printf("\n\t=== the initial array is as follows ===\n");
	//printArray(data, depth); 
	
	printf("\n\t=== the init union set are as follows ===\n");
	unionSet = initUnionSet(size, data); // initialize the union set over
	printSet(unionSet, size);
	
	printf("\n\t=== after union(0, 1) + union(2, 3) + union(4, 5) + union(6, 7) + union(8, 9) + union(10 ,11) ===\n");
	setUnion(unionSet, 0, 1);
	setUnion(unionSet, 2, 3);
	setUnion(unionSet, 4, 5);
	setUnion(unionSet, 6, 7);
	setUnion(unionSet, 8, 9);	
	setUnion(unionSet, 10, 11);	
	printSet(unionSet, size);

	printf("\n\t=== after union(1, 3) + union(5, 7) + union(9, 11) ===\n");
	setUnion(unionSet, 1, 3);
	setUnion(unionSet, 5, 7);
	setUnion(unionSet, 9, 11);
	printSet(unionSet, size);  
	
	printf("\n\t=== after union(3, 7) + union(7, 11) ===\n");
	setUnion(unionSet, 3, 7);
	setUnion(unionSet, 7, 11);	
	printSet(unionSet, size); 

	return 0;
}
static int setTestDriver(int argc, UC8 **argv) {  
	const UC8 me[]="setTestDriver"; 
	 /* Lets keep complaints about not using argc/v quiet... */
	if (!argc) { 
		printf("%s: No Args: .\n", me);
	} else {
		int i;
		UC8 *mem;
		UC8 *otherSet;
		UC8 *uSet;
		UC8 newSet[300];
		UC8 newSet_B[300];
		myBool isMem;
		while (--argc > 0 && (*++argv)[0] == '-')
			switch ((*argv)[1]) {
			case 's':  
				--argc; argv++; i=setShow(mk0Null(*argv)); printf("\n");
				printf("%s: Show:          :%-15s: Result:           %3d\n", "set", *argv, i);
				return i;
			case 'c':
				--argc; argv++; i=setCardinal(mk0Null(*argv));
				printf("%s: Cardinal:      :%-15s:                : Result:%3d \n", "set", *argv, i);
				return i;
			case 'n':
				--argc; argv++; 
				// !! setNormalise writes to what's pointed at by its params. 
				//    That MUST be writable.  I don't think **argv is  is....
				if (*argv) strcpy(newSet, *argv); else newSet[0]=0;   // strcpy cant cope with NULLs.....
				i=setNormalise(mk0Null(newSet));
				printf("%s: Normalise:     :%-15s:%-15s : Status:%3d (%s)\n", "set", *argv, newSet, i, setStatus2Str(i) );
				return i;
			case 'm':
				--argc; argv++; mem=mk0Null(*argv);
				--argc; argv++; isMem=setIsNotMember(mem, mk0Null(*argv));
				printf("%s: isNotMember:   :%-15s:%-15s : Result:%3d (%s)\n", "set", mem, *argv, isMem, setStatus2Str(isMem));
				return isMem;
			case 'e': // Note - setIsNotEqual calls normalise, so *argv won't do......
				--argc; argv++; 
				otherSet=mk0Null(*argv);
				if (*argv) strcpy(newSet, otherSet); else newSet[0]=0;   // strcpy cant cope with NULLs.....
				--argc; argv++; 
				if (mk0Null(*argv)) strcpy(newSet_B, mk0Null(*argv)); else newSet_B[0]=0;   // strcpy cant cope with NULLs.....
				isMem=setIsNotEqual(newSet, newSet_B);
				printf("%s: setIsNotEqual: :%-15s, %-15s: Result:%3d (%s)\n", "set", otherSet, *argv, isMem, setStatus2Str(isMem));
				return isMem;
			case 'u':
				--argc; argv++; otherSet=mk0Null(*argv);
				--argc; argv++; uSet=setUnion(otherSet, mk0Null(*argv));
				printf("%s: setUnion:      :%-15s, %-15s: Result: %-15s\n", "set", otherSet, *argv, uSet);
				//printf("%s: : setUnion: Doing The CleanUp\n", me);
				setDelete(uSet);
				//printf("%s: : setUnion: CleanUp Done\n", me);
				// Like to return a decent value here
				break;
			case 'i':
				--argc; argv++; otherSet=mk0Null(*argv);
				--argc; argv++; uSet=setIntersection(otherSet, mk0Null(*argv));
				printf("%s: setIntersection:%-15s, %-15s: Result: %-15s\n", "set", otherSet, mk0Null(*argv), uSet);
				//printf("%s: : setIntersection: Doing The CleanUp\n", me);
				setDelete(uSet);
				//printf("%s: : setIntersection: CleanUp Done\n", me);
				// Like to return a decent value here
				break;
			default:
				printf("%s: : ERROR UNKNOWN: %c:\n", "set", (*argv)[1] );
			}
	}
	//printf("%s: Complete. No Status Value returned (only 0)\n", me);
	return 0; // What we return if we can't return anythingelse
}
Beispiel #25
0
 void TagUnion<COUNT>::setArtist(const String &s)
 {
   setUnion(Artist, s);
 }
Beispiel #26
0
int main() {
	int i, num, cNum;
	char temp1[257], temp2[257], classString[12], buffer[80], call[80], test[80], next[80];
	stack s;
	Set dset;
	initStack(&s);

	DBRecord **students;

	scanf("%d", &num);
	printf("%d \n", num);

    students = (DBRecord **) malloc(num * sizeof(DBRecord *));

	for(i = 0; i < num; i++) {
		students[i] = (DBRecord *) malloc (sizeof(DBRecord));
		students[i]->bitID = i;
		scanf("%s %s %s %d %s %f %d", temp1, temp2, students[i]->idNum, &students[i]->age, classString, &students[i]->gpa, &students[i]->expectedGrad);

		//  allocate space for character strings, and copy the strings */
		students[i]->lName = (char *) malloc(strlen(temp1) + 1);
		strcpy(students[i]->lName, temp1);
		students[i]->fName = (char *) malloc(strlen(temp2) + 1);
		strcpy(students[i]->fName, temp2);

		// set the year field from the strings of Class values
		if( (strcmp(classString,"firstYear")) == 0 )
			students[i]->year = firstYear;

		else if( (strcmp(classString,"sophmore")) == 0 )
			students[i]->year = sophomore;

		else if( (strcmp(classString,"junior")) == 0 )
			students[i]->year = junior;

		else if( (strcmp(classString,"senior")) == 0 )
			students[i]->year = senior;

		else if( (strcmp(classString,"grad")) == 0 )
			students[i]->year = grad;

		else
			assert(0);

	}
	printf("Done scanning \n");

	while (scanf("%s", buffer) != EOF) {
		if (strcmp(buffer, "create") == 0) {
			clearSet(dset);
			scanf("%s", call);
			scanf("%s", test);

			if (strcmp(call, "lastName") == 0) {
				scanf("%s", next);
				if (strcmp(test, "=") == 0) {
					for(i = 0; i < num; i++) {
						if (strcmp(students[i]->lName, next) == 0)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, "<") == 0) {
					for(i = 0; i < num; i++) {
						if (strcmp(students[i]->lName, next) < 0)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, ">") == 0) {
					for(i = 0; i < num; i++) {
						if (strcmp(students[i]->lName, next) > 0)
							add2Set(dset, students[i]->bitID);
					}
				}
			}
			if (strcmp(call, "firstName") == 0) {
				scanf("%s", next);
				if (strcmp(test, "=") == 0) {
					for(i = 0; i < num; i++) {
						if (strcmp(students[i]->fName, next) == 0)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, "<") == 0) {
					for(i = 0; i < num; i++) {
						if (strcmp(students[i]->fName, next) < 0)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, ">") == 0) {
					for(i = 0; i < num; i++) {
						if (strcmp(students[i]->fName, next) > 0)
							add2Set(dset, students[i]->bitID);
					}
				}
			}
			if (strcmp(call, "idNum") == 0) {
				scanf("%s", next);
				if (strcmp(test, "=") == 0) {
					for(i = 0; i < num; i++) {
						if (strcmp(students[i]->idNum, next) == 0)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, "<") == 0) {
					for(i = 0; i < num; i++) {
						if (strcmp(students[i]->idNum, next) < 0)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, ">") == 0) {
					for(i = 0; i < num; i++) {
						if (strcmp(students[i]->idNum, next) > 0)
							add2Set(dset, students[i]->bitID);
					}
				}
			}
			if (strcmp(call, "age") == 0) {
				scanf("%d", &cNum);
				if (strcmp(test, "=") == 0) {
					for(i = 0; i < num; i++) {
						if(students[i]->age == cNum)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, "<") == 0) {
					for(i = 0; i < num; i++) {
						if(students[i]->age == cNum)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, ">") == 0) {
					for(i = 0; i < num; i++) {
						if(students[i]->age == cNum)
							add2Set(dset, students[i]->bitID);
					}
				}
			}
			if (strcmp(call, "year") == 0) {
				scanf("%d", &cNum);
				if (strcmp(test, "=") == 0) {
					for(i = 0; i < num; i++) {
						if(students[i]->year == cNum)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, "<") == 0) {
					for(i = 0; i < num; i++) {
						if(students[i]->year == cNum)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, ">") == 0) {
					for(i = 0; i < num; i++) {
						if(students[i]->year == cNum)
							add2Set(dset, students[i]->bitID);
					}
				}
			}
			if (strcmp(call, "gpa") == 0) {
				scanf("%d", &cNum);
				if (strcmp(test, "=") == 0) {
					for(i = 0; i < num; i++) {
						if(students[i]->gpa == cNum)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, "<") == 0) {
					for(i = 0; i < num; i++) {
						if(students[i]->gpa == cNum)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, ">") == 0) {
					for(i = 0; i < num; i++) {
						if(students[i]->gpa == cNum)
							add2Set(dset, students[i]->bitID);
					}
				}
			}
			if (strcmp(call, "expectedGrad") == 0) {
				scanf("%d", &cNum);
				if (strcmp(test, "=") == 0) {
					for(i = 0; i < num; i++) {
						if(students[i]->expectedGrad == cNum)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, "<") == 0) {
					for(i = 0; i < num; i++) {
						if(students[i]->expectedGrad == cNum)
							add2Set(dset, students[i]->bitID);
					}
				}
				if (strcmp(test, ">") == 0) {
					for(i = 0; i < num; i++) {
						if(students[i]->expectedGrad == cNum)
							add2Set(dset, students[i]->bitID);
					}
				}
			}
			push(&s, dset);
			printf("Created & Pushed Set \n");
		}
		if (strcmp(buffer, "union")) {
			Set uset1, uset2, urset;
			memcpy(uset2, pop(&s), 10 * sizeof(unsigned int));
			memcpy(uset1, pop(&s), 10 * sizeof(unsigned int));
			setUnion(uset1, uset2, urset);
			push(&s, urset);
			printf("Pushed Set \n");
		}
		if (strcmp(buffer, "intersection")) {
			Set iset1, iset2, irset;
			memcpy(iset2, pop(&s), 10 * sizeof(unsigned int));
			memcpy(iset1, pop(&s), 10 * sizeof(unsigned int));
			setIntersection(iset1, iset2, irset);
			push(&s, irset);
			printf("Pushed Set \n");
		}
		if (strcmp(buffer, "print")) {
			Set pset;
			memcpy(pset, pop(&s), 10 * sizeof(unsigned int));
			printSet(pset);
		}
		
	}
}
Beispiel #27
0
void PvObject::setUnion(const PvObject& value)
{
    std::string key = PyPvDataUtility::getValueOrSingleFieldName(pvStructurePtr);
    setUnion(key, value);
}
Beispiel #28
0
void compJaccSimAccu(Data& data, Params& params) {

  std::vector<ModelMF> mfModels;
  std::vector<ModelMF> origModels;
  for (int i = 1; i < 3; i++) {
    std::string prefix = "mf_0_0_10_" + std::to_string(i);
    ModelMF fullModel(params, params.seed);
    fullModel.loadFacs(prefix.c_str());
    mfModels.push_back(fullModel);

    std::string uFName = "uFac_" + std::to_string(fullModel.nUsers) + "_10_0.txt";
    std::string iFName = "iFac_" + std::to_string(fullModel.nItems+1) + "_10_0.txt";
    ModelMF origModel(params, uFName.c_str(), iFName.c_str(), params.seed);
    origModels.push_back(origModel);
  }
  
  /*
  for (int i = 0; i < 2; i++) {
    std::string prefix = "mfrand_" + std::to_string(i) + "_0_20";
    ModelMF fullModel(params, params.seed);
    fullModel.loadFacs(prefix.c_str());
    mfModels.push_back(fullModel);

    std::string uFName = "uFac_" + std::to_string(fullModel.nUsers) + "_20_" 
      + std::to_string(i) + ".txt";
    std::string iFName = "iFac_" + std::to_string(fullModel.nItems) + "_20_" 
      + std::to_string(i) + ".txt";
    ModelMF origModel(params, uFName.c_str(), iFName.c_str(), params.seed);
    origModels.push_back(origModel);
  }
  */

  int nModels    = mfModels.size();

  std::unordered_set<int> invalidUsers;
  std::unordered_set<int> invalidItems;
  std::string modelSign = mfModels[0].modelSignature();
  std::cout << "\nModel sign: " << modelSign << std::endl;    
  std::string prefix = std::string(params.prefix) + "_" + modelSign + "_invalUsers.txt";
  std::vector<int> invalUsersVec = readVector(prefix.c_str());
  prefix = std::string(params.prefix) + "_" + modelSign + "_invalItems.txt";
  std::vector<int> invalItemsVec = readVector(prefix.c_str());
  for (auto v: invalUsersVec) {
    invalidUsers.insert(v);
  }
  for (auto v: invalItemsVec) {
    invalidItems.insert(v);
  }

  for (int i = 0; i < nModels; i++) {
    auto& fullModel = mfModels[i];
    auto& origModel = origModels[i];
    std::cout << "Model: " << i << std::endl;
    std::cout << "Train RMSE: " << fullModel.RMSE(data.trainMat, invalidUsers, 
        invalidItems, origModel) << std::endl;
    std::cout << "Test RMSE: " << fullModel.RMSE(data.testMat, invalidUsers, 
        invalidItems, origModel) << std::endl;
    std::cout << "Val RMSE: " << fullModel.RMSE(data.valMat, invalidUsers, 
        invalidItems, origModel) << std::endl;
    //std::cout << "Full RMSE: " << fullModel.fullLowRankErr(data, invalidUsers, 
    //    invalidItems, origModel) << std::endl;
  }

  std::vector<double> epsilons = {0.025, 0.05, 0.1, 0.25, 0.5, 1.0};
  //std::vector<double> epsilons = {0.5};
  int nUsers     = data.trainMat->nrows;
  int nItems     = data.trainMat->ncols;

  std::cout << "nModels: " << nModels << std::endl;

  for (auto&& epsilon: epsilons) {
    std::cout << "epsilon: " << epsilon << std::endl;
    std::vector<std::vector<float>> itemsJacSims(nItems);
    std::vector<std::vector<float>> itemAccuCount(nItems);
    std::vector<std::vector<float>> itemPearsonCorr(nItems);

#pragma omp parallel for
    for (int item = 0; item < nItems; item++) {
      if (invalidItems.count(item) > 0) {
        continue;
      }
      
      std::vector<std::unordered_set<int>> modelAccuItems(nModels);
      std::vector<std::vector<float>> itemErr(nModels);
      std::vector<float> itemErrMean(nModels, 0);
      std::vector<bool> ratedUsers(nUsers, false);
      int count = 0;

      for (int uu = data.trainMat->colptr[item]; 
          uu < data.trainMat->colptr[item+1]; uu++) {
        ratedUsers[data.trainMat->colind[uu]] = true;
      }

      for (int user = 0; user < nUsers; user++) {
        
        if (invalidUsers.count(user) > 0) {
          continue;
        }

        if (ratedUsers[user]) {
          continue;
        }
        
        for (int i = 0; i < nModels; i++) {
          auto& mfModel = mfModels[i];
          auto& origModel = origModels[i];
          float r_ui_est = mfModel.estRating(user, item);
          float r_ui = origModel.estRating(user, item);
          float diff = fabs(r_ui - r_ui_est);
          itemErr[i].push_back(diff);
          itemErrMean[i] += diff;
          if (diff <= epsilon) {
             modelAccuItems[i].insert(user);
          }
        }
        count++;
      }
      
      for (int i = 0; i < nModels; i++) {
        itemErrMean[i] /= count;
      }

      for (int i = 0; i < nModels; i++) {
        itemAccuCount[item].push_back(modelAccuItems[i].size());
        for (int j = i+1; j < nModels; j++) {
          //compute overlap between model i and model j
          float intersectCount = (float) setIntersect(modelAccuItems[i], modelAccuItems[j]);
          float unionCount = (float) setUnion(modelAccuItems[i], modelAccuItems[j]);
          float jacSim = 0;
          if (unionCount > 0) {
            jacSim = intersectCount/unionCount;
          }
          itemsJacSims[item].push_back(jacSim);
          //compute correlation between model i & j for the item
          itemPearsonCorr[item].push_back(pearsonCorr(itemErr[i], itemErr[j], 
                itemErrMean[i], itemErrMean[j])); 
        }
      }

    }
    

    std::string opFName = std::string(params.prefix) + "_" + 
      std::to_string(epsilon) + "_modelsJacSim.txt";
    
    std::string opFName2 = std::string(params.prefix) + "_" + 
      std::to_string(epsilon) + "_modelsPearson.txt";

    std::cout << "Writing... " << opFName << std::endl;

    std::ofstream opFile(opFName.c_str());
    std::ofstream opFile2(opFName2.c_str());

    for (int item  = 0; item < nItems; item++) {
      opFile << item << " ";
      for (auto&& sim: itemsJacSims[item]) {
        opFile << sim << " ";
      }
      for (auto&& accu: itemAccuCount[item]) {
        opFile << accu << " ";
      }
      opFile << std::endl;

      opFile2 << item << " ";
      for (auto&& corr: itemPearsonCorr[item]) {
        opFile2 << corr << " ";
      }
      opFile2 << std::endl;
    }

    opFile.close();
    opFile2.close();
  }

}
Beispiel #29
0
static Tree realeval (Tree exp, Tree visited, Tree localValEnv)
{
	//Tree 	def;
	Tree 	fun;
	Tree 	arg;
	Tree	var, num, body, ldef;
	Tree 	label;
	Tree	cur, lo, hi, step;
	Tree	e1, e2, exp2, notused, visited2, lenv2;
	Tree	rules;
	Tree	id;

	//cerr << "EVAL " << *exp << " (visited : " << *visited << ")" << endl;
    //cerr << "REALEVAL of " << *exp << endl;
	
	xtended* xt = (xtended*) getUserData(exp);

	// constants
	//-----------
	
	if ( 	xt || 
			isBoxInt(exp) || isBoxReal(exp) || 
			isBoxWire(exp) || isBoxCut(exp) ||
			isBoxPrim0(exp) || isBoxPrim1(exp) || 
			isBoxPrim2(exp) || isBoxPrim3(exp) || 
			isBoxPrim4(exp) || isBoxPrim5(exp) ||
            isBoxFFun(exp) || isBoxFConst(exp) || isBoxFVar(exp) ||
            isBoxWaveform(exp)) {
		return exp;

	// block-diagram constructors
	//---------------------------
	
	} else if (isBoxSeq(exp, e1, e2)) {
		return boxSeq(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));

	} else if (isBoxPar(exp, e1, e2)) {
		return boxPar(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));

	} else if (isBoxRec(exp, e1, e2)) {
		return boxRec(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));

	} else if (isBoxSplit(exp, e1, e2)) {
		return boxSplit(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));

	} else if (isBoxMerge(exp, e1, e2)) {
		return boxMerge(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));
		
	// Modules
	//--------

    } else if (isBoxAccess(exp, body, var)) {
        Tree val = eval(body, visited, localValEnv);
        if (isClosure(val, exp2, notused, visited2, lenv2)) {
            // it is a closure, we have an environment to access
            return eval(closure(var,notused,visited2,lenv2), visited, localValEnv);
        } else {
            evalerror(getDefFileProp(exp), getDefLineProp(exp), "no environment to access", exp);
        }

//////////////////////en chantier////////////////////////////

    } else if (isBoxModifLocalDef(exp, body, ldef)) {
        Tree val = eval(body, visited, localValEnv);
        if (isClosure(val, exp2, notused, visited2, lenv2)) {
            // we rebuild the closure using a copy of the original environment
            // modified with some new definitions
            Tree lenv3 = copyEnvReplaceDefs(lenv2, ldef, visited2, localValEnv);
            return eval(closure(exp2,notused,visited2,lenv3), visited, localValEnv);
        } else {
            evalerror(getDefFileProp(exp), getDefLineProp(exp), "not a closure", val);
            evalerror(getDefFileProp(exp), getDefLineProp(exp), "no environment to access", exp);
        }

///////////////////////////////////////////////////////////////////

    } else if (isBoxComponent(exp, label)) {
        string  fname   = tree2str(label);
        Tree    eqlst   = gGlobal->gReader.expandlist(gGlobal->gReader.getlist(fname));
        Tree    res     = closure(boxIdent("process"), gGlobal->nil, gGlobal->nil, pushMultiClosureDefs(eqlst, gGlobal->nil, gGlobal->nil));
        setDefNameProperty(res, label);
        //cerr << "component is " << boxpp(res) << endl;
        return res;

    } else if (isBoxLibrary(exp, label)) {
        string  fname   = tree2str(label);
        Tree    eqlst   = gGlobal->gReader.expandlist(gGlobal->gReader.getlist(fname));
        Tree    res     = closure(boxEnvironment(), gGlobal->nil, gGlobal->nil, pushMultiClosureDefs(eqlst, gGlobal->nil, gGlobal->nil));
        setDefNameProperty(res, label);
        //cerr << "component is " << boxpp(res) << endl;
        return res;

	// user interface elements
	//------------------------
	
	} else if (isBoxButton(exp, label)) {
		const char* l1 = tree2str(label);
     	const char* l2 = evalLabel(l1, visited, localValEnv);
		//cout << "button label : " << l1 << " become " << l2 << endl;
		return ((l1 == l2) ? exp : boxButton(tree(l2)));

	} else if (isBoxCheckbox(exp, label)) {
		const char* l1 = tree2str(label);
    	const char* l2 = evalLabel(l1, visited, localValEnv);
		//cout << "check box label : " << l1 << " become " << l2 << endl;
		return ((l1 == l2) ? exp : boxCheckbox(tree(l2)));

	} else if (isBoxVSlider(exp, label, cur, lo, hi, step)) {
		const char* l1 = tree2str(label);
        const char* l2 = evalLabel(l1, visited, localValEnv);
		return ( boxVSlider(tree(l2),
					tree(eval2double(cur, visited, localValEnv)),
					tree(eval2double(lo, visited, localValEnv)),
					tree(eval2double(hi, visited, localValEnv)),
					tree(eval2double(step, visited, localValEnv))));

	} else if (isBoxHSlider(exp, label, cur, lo, hi, step)) {
		const char* l1 = tree2str(label);
     	const char* l2 = evalLabel(l1, visited, localValEnv);
		return ( boxHSlider(tree(l2),
					tree(eval2double(cur, visited, localValEnv)),
					tree(eval2double(lo, visited, localValEnv)),
					tree(eval2double(hi, visited, localValEnv)),
					tree(eval2double(step, visited, localValEnv))));

	} else if (isBoxNumEntry(exp, label, cur, lo, hi, step)) {
		const char* l1 = tree2str(label);
      	const char* l2 = evalLabel(l1, visited, localValEnv);
		return (boxNumEntry(tree(l2),
					tree(eval2double(cur, visited, localValEnv)),
					tree(eval2double(lo, visited, localValEnv)),
					tree(eval2double(hi, visited, localValEnv)),
					tree(eval2double(step, visited, localValEnv))));

	} else if (isBoxVGroup(exp, label, arg)) {
		const char* l1 = tree2str(label);
        const char* l2 = evalLabel(l1, visited, localValEnv);
		return boxVGroup(tree(l2),	eval(arg, visited, localValEnv) );

	} else if (isBoxHGroup(exp, label, arg)) {
		const char* l1 = tree2str(label);
 		const char* l2 = evalLabel(l1, visited, localValEnv);
		return boxHGroup(tree(l2),	eval(arg, visited, localValEnv) );

	} else if (isBoxTGroup(exp, label, arg)) {
		const char* l1 = tree2str(label);
    	const char* l2 = evalLabel(l1, visited, localValEnv);
		return boxTGroup(tree(l2),	eval(arg, visited, localValEnv) );

	} else if (isBoxHBargraph(exp, label, lo, hi)) {
		const char* l1 = tree2str(label);
    	const char* l2 = evalLabel(l1, visited, localValEnv);
		return boxHBargraph(tree(l2),
					tree(eval2double(lo, visited, localValEnv)),
					tree(eval2double(hi, visited, localValEnv)));

	} else if (isBoxVBargraph(exp, label, lo, hi)) {
		const char* l1 = tree2str(label);
  		const char* l2 = evalLabel(l1, visited, localValEnv);
		return boxVBargraph(tree(l2),
					tree(eval2double(lo, visited, localValEnv)),
					tree(eval2double(hi, visited, localValEnv)));

	// lambda calculus
	//----------------
		
	} else if (isBoxIdent(exp)) {
		return evalIdDef(exp, visited, localValEnv);

	} else if (isBoxWithLocalDef(exp, body, ldef)) {
		return eval(body, visited, pushMultiClosureDefs(ldef, visited, localValEnv));
	
	} else if (isBoxAppl(exp, fun, arg)) {
        return applyList( eval(fun, visited, localValEnv),
						  revEvalList(arg, visited, localValEnv) );

    } else if (isBoxAbstr(exp)) {
        // it is an abstraction : return a closure
        return closure(exp, gGlobal->nil, visited, localValEnv);

    } else if (isBoxEnvironment(exp)) {
        // environment : return also a closure
        return closure(exp, gGlobal->nil, visited, localValEnv);

	} else if (isClosure(exp, exp2, notused, visited2, lenv2)) {

        if (isBoxAbstr(exp2)) {
            // a 'real' closure
            return closure(exp2, gGlobal->nil, setUnion(visited,visited2), lenv2);
        } else if (isBoxEnvironment(exp2)) {
            // a 'real' closure
            return closure(exp2, gGlobal->nil, setUnion(visited,visited2), lenv2);
        } else {
			// it was a suspended evaluation
			return eval(exp2, setUnion(visited,visited2), lenv2);
		}

	// Algorithmic constructions
	//--------------------------
	
	} else if (isBoxIPar(exp, var, num, body)) {
		int n = eval2int(num, visited, localValEnv);
		return iteratePar(var, n, body, visited, localValEnv);

	} else if (isBoxISeq(exp, var, num, body)) {
		int n = eval2int(num, visited, localValEnv);
		return iterateSeq(var, n, body, visited, localValEnv);

	} else if (isBoxISum(exp, var, num, body)) {
		int n = eval2int(num, visited, localValEnv);
		return iterateSum(var, n, body, visited, localValEnv);

    } else if (isBoxIProd(exp, var, num, body)) {
        int n = eval2int(num, visited, localValEnv);
        return iterateProd(var, n, body, visited, localValEnv);

    // static
    } else if (isBoxInputs(exp, body)) {
        int ins, outs;
        Tree b = a2sb(eval(body, visited, localValEnv));
        if (getBoxType (b, &ins, &outs)) {
            return boxInt(ins);
        } else {
            stringstream error;
            error << "ERROR : can't evaluate ' : " << *exp << endl;
            throw faustexception(error.str());
        }
  
    } else if (isBoxOutputs(exp, body)) {
        int ins, outs;
        Tree b = a2sb(eval(body, visited, localValEnv));
        if (getBoxType (b, &ins, &outs)) {
            return boxInt(outs);
        } else {
            stringstream error;
            error << "ERROR : can't evaluate ' : " << *exp << endl;
            throw faustexception(error.str());
        }

	} else if (isBoxSlot(exp)) 		{ 
		return exp; 
	
	} else if (isBoxSymbolic(exp)) 	{
	 	return exp;

	// Pattern matching extension
	//---------------------------
	
	} else if (isBoxCase(exp, rules)) {
        return evalCase(rules, localValEnv);

	} else if (isBoxPatternVar(exp, id)) {
		return exp;
		//return evalIdDef(id, visited, localValEnv);

	} else if (isBoxPatternMatcher(exp)) {
		return exp;

    } else {
        stringstream error;
        error << "ERROR : EVAL doesn't intercept : " << *exp << endl;
        throw faustexception(error.str());
    }
	return NULL;
}
Beispiel #30
0
 void TagUnion<COUNT>::setTitle(const String &s)
 {
   setUnion(Title, s);
 }