void ProgressSubjectMultiStep::notifyPatchCountChanged() {
    // Must be copy of working list to avoid race condition!!
    TList listCopy(observerList_);
    TList::iterator i;
    for(i= listCopy.begin(); i!= listCopy.end(); i++)
        i->observer->updatePatchCount();
}
Beispiel #2
0
TEST_F(ForwardListTest, CopyWorks)
{

	sprawl::collections::ForwardList<int> forwardListCopyTest;
	forwardListCopyTest.PushFront(1);
	forwardListCopyTest.PushFront(2);
	forwardListCopyTest.PushFront(3);
	forwardListCopyTest.PushFront(4);
	forwardListCopyTest.PushFront(5);

	int lastItem = 6;
	for(auto& item : forwardListCopyTest)
	{
		EXPECT_EQ(lastItem - 1, item);
		lastItem = item;
	}

	lastItem = 6;
	sprawl::collections::ForwardList<int> listCopy(forwardListCopyTest);
	for(auto& item : listCopy)
	{
		EXPECT_EQ(lastItem - 1, item);
		lastItem = item;
	}

	EXPECT_EQ(1, lastItem);
}
void soc::SocSystem_Ors::clone(const SocSystem_Ors& sys){
  os = sys.os;
  dynamic = sys.dynamic;
  
  if(!sys.WS->newedOrs){
    gl = sys.gl;
    ors   = sys.ors;
    swift = sys.swift;
  }else{
    gl = new OpenGL;            gl->clone(*sys.gl);
    ors=new ::ors::Graph;     ors->clone(*sys.ors);
    swift=new SwiftModule;  swift->clone(*sys.swift,*ors);
    gl->remove(ors::glDrawGraph,sys.ors);
    gl->add   (ors::glDrawGraph,ors);
  }
  WS->newedOrs = sys.WS->newedOrs;

  listCopy(vars, sys.vars);
  uint i;  TaskVariable *y;
  for_list(i,y,vars) y->ors=ors;
  
  WS->Qlin = sys.WS->Qlin;
  WS->Qoff = sys.WS->Qoff;
  WS->Qinv = sys.WS->Qinv;
  WS->q0 = sys.WS->q0;
  WS->v0 = sys.WS->v0;
  WS->W = sys.WS->W;
  WS->H = sys.WS->H;
  WS->Q = sys.WS->Q;
  WS->v_act = sys.WS->v_act;
  WS->T = sys.WS->T;
  WS->tau = sys.WS->tau;
  WS->pseudoDynamic = sys.WS->pseudoDynamic=false;
}
Beispiel #4
0
/* 
 * Return a processed source line list of the file contents.
 */
SrcLineList
includeFile(FileName fname)
{
	String	      fnameString;
	SrcLineList   r;

	inclSerialLineNo    = 0;
	fnameString         = strCopy(fnameUnparseStatic(fname));
	inclBuffer          = bufNew();
	includedFileCodes   = 0;
	localAssertList     = listCopy(String)(globalAssertList);

	fileState.curDir    = osCurDirName();
	fileState.fileCodes = 0;
	fileState.fileNames = 0;

	r = listNReverse(SrcLine)(
		inclFile(fnameString, false, true, &inclFileLineNo));

	strFree(fnameString);
	bufFree(inclBuffer);
	listFree(String)(localAssertList);
	listFree(Hash)(includedFileCodes);

	return r;
}
Beispiel #5
0
TPoss
tpossCopy(TPoss tp)
{
	TPoss np;

	if (tp == NULL)
	       	return NULL;

	np = tpossAlloc();
	np->possl = listCopy(TForm)(tp->possl);
	np->possc = tp->possc;
	np->refc  = 1;
	return np;
}
Beispiel #6
0
/* ----------------
 *	_copyJInfo
 * ----------------
 */
static JInfo *
_copyJInfo(JInfo *from)
{
    JInfo *newnode = makeNode(JInfo);
    
    /* ----------------
     *	copy remainder of node
     * ----------------
     */
    newnode->otherrels = listCopy(from->otherrels);
    Node_Copy(from, newnode, jinfoclauseinfo);
    
    newnode->mergesortable = from->mergesortable;
    newnode->hashjoinable =  from->hashjoinable;
    newnode->inactive =      from->inactive;
    
    return newnode;
}
Beispiel #7
0
/* ----------------
 *	CopyPathFields
 *
 *	This function copies the fields of the Path node.  It is used by
 *	all the copy functions for classes which inherit from Path.
 * ----------------
 */
static void
CopyPathFields(Path *from, Path *newnode)
{
    newnode->pathtype =  	from->pathtype;
    /* Modify the next line, since it causes the copying to cycle
       (i.e. the parent points right back here! 
       -- JMH, 7/7/92.
       Old version:
       Node_Copy(from, newnode, parent);
       */
    newnode->parent =           from->parent;
    
    newnode->path_cost = 	from->path_cost;

    newnode->p_ordering.ordtype = from->p_ordering.ordtype;
    if (from->p_ordering.ordtype == SORTOP_ORDER) {
	int len, i;
	Oid *ordering = from->p_ordering.ord.sortop;

	if (ordering) {
	    for(len=0; ordering[len]!=0; len++)
		;
	    newnode->p_ordering.ord.sortop =
		(Oid *)palloc(sizeof(Oid) * (len+1));
	    for(i=0; i < len; i++) {
		newnode->p_ordering.ord.sortop[i] = ordering[i];
	    }
	    newnode->p_ordering.ord.sortop[len] = 0;
	} else {
	    newnode->p_ordering.ord.sortop = NULL;
	}
    } else {
	Node_Copy(from, newnode, p_ordering.ord.merge);
    }

    Node_Copy(from, newnode, keys);
    
    newnode->outerjoincost = 	from->outerjoincost;
    
    newnode->joinid = listCopy(from->joinid);
    Node_Copy(from, newnode, locclauseinfo);
}
Beispiel #8
0
/* ----------------
 *	_copyIndexPath
 * ----------------
 */
static IndexPath *
_copyIndexPath(IndexPath *from)
{
    IndexPath *newnode = makeNode(IndexPath);
    
    /* ----------------
     *	copy the node superclass fields
     * ----------------
     */
    CopyPathFields((Path*)from, (Path*)newnode);
    
    /* ----------------
     *	copy remainder of node
     * ----------------
     */
    newnode->indexid = listCopy(from->indexid);
    Node_Copy(from, newnode, indexqual);
    
    return newnode;
}
Beispiel #9
0
/* ----------------
 *	_copyCInfo
 * ----------------
 */
static CInfo *
_copyCInfo(CInfo *from)
{
    CInfo *newnode = makeNode(CInfo);
    
    /* ----------------
     *	copy remainder of node
     * ----------------
     */
    Node_Copy(from, newnode, clause);
    
    newnode->selectivity = 	from->selectivity;
    newnode->notclause = 	from->notclause;
    
    Node_Copy(from, newnode, indexids);
    Node_Copy(from, newnode, mergesortorder);
    newnode->hashjoinoperator = from->hashjoinoperator;
    newnode->cinfojoinid = listCopy(from->cinfojoinid);
    
    return newnode;
}
Beispiel #10
0
Value *valueAdd(Value *v1, Value *v2) {
  switch (v1->type) {
    case INT_VALUE_TYPE:
      switch (v2->type) {
        case INT_VALUE_TYPE:
          return newIntValue((long)v1->data + (long)v2->data);
        default:
          error("int can only add to int\n");
      }
    case LIST_VALUE_TYPE: {
      List *res = listCopy(v1->data);
      int i;
      assert(v2->type == LIST_VALUE_TYPE);
      List *l = v2->data;
      for (i = 0; i < listSize(l); i++) {
        listPush(res, listGet(l, i));
      }
      return newListValue(res);
    }
    case STRING_VALUE_TYPE: {
      if (v2->type == STRING_VALUE_TYPE) {
        char *s1 = (char *)v1->data, *s2 = (char *)v2->data;
        char *res = (char *)tlMalloc(strlen(s1) + strlen(s2) + 1);
        *res = 0;
        strcat(res, s1);
        strcat(res, s2);
        return newStringValue(res);
      } else {
        error("can only add string to string\n");
      }
    }
    case CLOSURE_VALUE_TYPE:
      error("Closure value cannot add to anything\n");
    case ENV_VALUE_TYPE:
      error("Environment value cannot add to anything\n");
    default:
      error("unknown value type passed to valueAdd: %d\n", v1->type);
  }
  return 0;  // never reach here
}
Beispiel #11
0
/* ----------------
 *	_copyIndexScan
 * ----------------
 */
static IndexScan *
_copyIndexScan(IndexScan *from)
{
    IndexScan *newnode = makeNode(IndexScan);
    
    /* ----------------
     *	copy node superclass fields
     * ----------------
     */
    CopyPlanFields((Plan*)from, (Plan*)newnode);
    CopyScanFields((Scan*)from, (Scan*)newnode);
    
    /* ----------------
     *	copy remainder of node 
     * ----------------
     */
    newnode->indxid = listCopy(from->indxid);
    Node_Copy(from, newnode, indxqual);
    Node_Copy(from, newnode, indxstate);
    
    return newnode;
}
Beispiel #12
0
void ProgressSubjectMultiStep::notifyPerStepProgress() {
    // Must be copy of working list to avoid race condition!!
    TList listCopy(observerList_);
    TList::iterator i;
    for(i= listCopy.begin(); i!= listCopy.end(); i++) {
        // Must be original item (not copy)
        TList::iterator originalItem = std::find_if(
                observerList_.begin(),
                observerList_.end(),
                ObserverFinder(i->observer));
        TItem &item = *originalItem;

        int count = currentPatch()-item.offset+1;
        if (count < 0)
            count = 0;

        int n = (item.ratio)?count/item.ratio:(item.last+1);
        if (n != item.last) {
            item.last = n;
            item.observer->updatePerStepProgress();
        }
    }
}
Beispiel #13
0
/**
* Creates a new filtered copy of a list.
*
* This creates a new list with only the elements for which the filtering
* function returned true.
*
* For example, the following code creates a new list, given a list of strings
* containing only the strings which are longer than 10 characters.
* @code
*
* bool isLongerThan(ListElement string, ListFilterKey key) {
*   return strlen(string) > *(int*)key;
* }
*
* List createFilteredList(List listOfStrings) {
*   int key = 10;
*   return listFilter(listOfStrings, isLongerThan, &key);
* }
* @endcode
*
* @param list The list for which a filtered copy will be made
* @param filterElement The function used for determining whether a given
* element should be in the resulting list or not.
* @param key Any extra values that need to be sent to the filtering function
* when called
* @return
* NULL if list or filterElement are NULL or a memory allocation failed.
* A List containing only elements from list which filterElement returned true
* for.
*/
List listFilter(List list, FilterListElement filterElement, ListFilterKey key){
	if((list == NULL) && (filterElement == NULL)) return NULL;
	List filtered = listCopy(list);
	if (filtered == NULL) return NULL;
	if (filtered->First != NULL) {
		filtered->Current = filtered->First;
		while((filtered != NULL) && (filtered->Current != NULL)) {
			if (!filterElement(filtered->Current->Element, key)) {
				ListItem new_current = filtered->Current->Next;
				if (listRemoveCurrent(filtered) != LIST_SUCCESS) {
					listDestroy(filtered);
					filtered = NULL;
				} else {
					filtered->Current = new_current;
				}
			} else {
				filtered->Current = filtered->Current->Next;
			}
		}
	}
	if (filtered != NULL) filtered->Current = filtered->First;
	return filtered;
}
Beispiel #14
0
int main(int argc, char *argv[])
{
	/* Save start time of program for later use */
	const time_t startTime = time(NULL);

	srand(startTime);

	/* Create pointers to manipulate with */
	Firm * firm = (Firm *) calloc(1, sizeof(Firm));

	Employee* employees = NULL;
	Employee ** sortedEmployes;

	/* Loads data from the file in the correct file in the correct directory */
	char runPath[strlen(argv[0]) + 20];
	getRunPath(argv[0], runPath);

	loadDataFromFile(firm, &employees, runPath);

	sortedEmployes = sortEmployeesBy(employees, firm->skills);

	int validCounter = 0;
	int randomCounter;

	float highestScore = 0;

	firm->bestSchedule = generateBestRandomSchedule(firm, employees, sortedEmployes, &randomCounter, &validCounter);

	if(!firm->bestSchedule)
	{
		printf("Error, no result from random generation\n");
		exit(-1);
	}

	highestScore = genScore(firm, firm->bestSchedule, employees);

	//int swapsTries;

	/**
	 * findBestRoughSwap
	 */
	firm->bestSchedule = findBestRoughSwap(firm, firm->bestSchedule, employees, &highestScore);

	/**
	 * fineSwap
	 */

	findBestFineSwap(firm, &(firm->bestSchedule), employees, &highestScore);


	Shift * tmpShift = listCopy((void*) firm->bestSchedule, sizeof(Shift));

	Employee * unassignedEmployeeList = generateUnassignedEmployeeList(tmpShift, employees);

	assignEmployeeListRandomly(tmpShift, employees, &unassignedEmployeeList);

	tmpShift = findBestRoughSwap(firm, tmpShift, employees, &highestScore);

	findBestFineSwap(firm, &tmpShift, employees, &highestScore);

	if(isValid(tmpShift, employees) && genScore(firm, firm->bestSchedule, employees) < highestScore)
	{
		listClean((void **) &(firm->bestSchedule), sizeof(Shift));
		firm->bestSchedule = tmpShift;
	}
	else
	{
		listClean((void **) &tmpShift, sizeof(Shift));
	}

	printHLine(129);
	printf("PRINTING BEST SCHEDULE (THAT I FOUND) - BY THE WAY, THE BEST SCORE WAS: %f\n", highestScore);
	printHLine(129);
	if(printScheduleHeadline(""))
	{
		printSchedule(firm->bestSchedule, employees);
	}
	printHLine(129);

	/**
	 * TODO: Clean bedstscore osv.
	 */

	cleanUp(&firm, &employees, &sortedEmployes);

	return EXIT_SUCCESS;
}
Beispiel #15
0
/*
 ** when you change this, also make sure to fix up xfunc_copyRel in 
 ** planner/path/xfunc.c accordingly!!!
 **         -- JMH, 8/2/93
 */
static Rel *
_copyRel(Rel *from)
{
    Rel *newnode = makeNode(Rel);
    int i, len;

    /* ----------------
     *	copy remainder of node
     * ----------------
     */
    newnode->relids = listCopy(from->relids);
    
    newnode->indexed = from->indexed;
    newnode->pages =   from->pages;
    newnode->tuples =  from->tuples;
    newnode->size =    from->size;
    newnode->width =   from->width;
    newnode->indproc = from->indproc;
    
    Node_Copy(from, newnode, targetlist);
    Node_Copy(from, newnode, pathlist);
    Node_Copy(from, newnode, unorderedpath);
    Node_Copy(from, newnode, cheapestpath);
    newnode->pruneable = from->pruneable;
    newnode->relam = from->relam;

    if (from->classlist) {
	for(len=0; from->classlist[len]!=0; len++)
	    ;
	newnode->classlist = (Oid *)palloc(sizeof(Oid) * (len+1));
	for(i=0; i < len; i++) {
	    newnode->classlist[i] = from->classlist[i];
	}
	newnode->classlist[len] = 0;
    }

    if (from->indexkeys) {
	for(len=0; from->indexkeys[len]!=0; len++)
	    ;
	newnode->indexkeys = (int *)palloc(sizeof(int) * (len+1));
	for(i=0; i < len; i++) {
	    newnode->indexkeys[i] = from->indexkeys[i];
	}
	newnode->indexkeys[len] = 0;
    }
    
    if (from->ordering) {
	for(len=0; from->ordering[len]!=0; len++)
	    ;
	newnode->ordering = (Oid *)palloc(sizeof(Oid) * (len+1));
	for(i=0; i < len; i++) {
	    newnode->ordering[i] = from->ordering[i];
	}
	newnode->ordering[len] = 0;
    }

    Node_Copy(from, newnode, clauseinfo);
    Node_Copy(from, newnode, joininfo);
    Node_Copy(from, newnode, innerjoin);
    Node_Copy(from, newnode, superrels);
    
    return newnode;
}