void RotateManipulator::doMovement(      Transform    *t,
                                   const Int32         coord,
                                   const Real32        value,
                                   const Vec3f        &translation,
                                   const Quaternion   &rotation,
                                   const Vec3f        &scaleFactor,
                                   const Quaternion   &scaleOrientation)
{
    Vec3f axis(0.0f, 0.0f, 0.0f);
    axis[coord] = 1.0;
    const Quaternion rot(axis, value);

    Matrix ma, mb, mc, md, me, mf, mg;
    
    Vec3f sp( getPivot()[0] * scaleFactor[0],
              getPivot()[1] * scaleFactor[1],
              getPivot()[2] * scaleFactor[2]);
             
    ma.setTranslate( - translation      );
    mb.setRotate   ( rotation.inverse() );
    mc.setTranslate( - sp               );
    md.setRotate   ( rot                );
    me.setTranslate( sp                 );
    mf.setRotate   ( rotation           );
    mg.setTranslate( translation        );
    
    
    t->editMatrix().multLeft(ma);
    t->editMatrix().multLeft(mb);
    t->editMatrix().multLeft(mc);
    t->editMatrix().multLeft(md);
    t->editMatrix().multLeft(me);
    t->editMatrix().multLeft(mf);
    t->editMatrix().multLeft(mg);
}
Esempio n. 2
0
glm::mat4 AreaNode::calcTransform()
{
    glm::vec3 pos(m_RelViewport.tl.x, m_RelViewport.tl.y, 0);
    glm::vec3 pivot(getPivot().x, getPivot().y, 0);
    glm::mat4 transform = glm::translate(glm::mat4(1.0f), pos);
    transform = glm::translate(transform, pivot);
    transform = glm::rotate(transform, (180.f/PI)*m_Angle, glm::vec3(0,0,1));
    transform = glm::translate(transform, -pivot);
    return transform;
}
	void SfmlBoxInstanceInfo::render()
	{
		if (Settings::renderDebugBoxes)
		{
			rectangle.setPosition(getPosition().x, getPosition().y);
			rectangle.setRotation(toDegrees(getAngle()));
			rectangle.setScale(getScale().x, getScale().y);
			rectangle.setOrigin(getPivot().x*getSize().x, getPivot().y*getSize().y);
			renderWindow->draw(rectangle);
		}
	}
Esempio n. 4
0
void AreaNode::calcTransform()
{
    if (m_bTransformChanged) {
        glm::vec3 pos(m_RelViewport.tl.x, m_RelViewport.tl.y, 0);
        glm::vec3 pivot(getPivot().x, getPivot().y, 0);
        glm::mat4 transform = glm::translate(glm::mat4(1.0f), pos);
        transform = glm::translate(transform, pivot);
        transform = glm::rotate(transform, (180.f/PI)*m_Angle, glm::vec3(0,0,1));
        m_LocalTransform = glm::translate(transform, -pivot);
        m_bTransformChanged = false;
    }
}
Esempio n. 5
0
static int partition(int arr[], int start, int end)
{
    int lh, rh;
    int pivot, pivotVal;

    //init the handlers
    lh = start + 1;
    rh = end;
    //get pivot
    pivot = getPivot(start, end);
    pivotVal = arr[pivot];
    //swap pivot with the 1st element
    swap(arr, start, pivot);
    //sort the partitions
    while (1) {
        while ((arr[rh]>=pivotVal) && (rh>lh)) rh--;
        while ((arr[lh]<pivotVal) && (rh>lh)) lh++;

        if (rh==lh) break;

        swap(arr, lh, rh);
    }
    if (arr[lh] >= pivotVal) return start; //XXX: you may pick the smallest as pivot,
                                       //in which case you don't want to swap
    //swap back pivot with the 1st element
    swap(arr, start, lh);

    return rh;
    
}
Esempio n. 6
0
void quickSort(std::vector<int> &arr, int left, int right) {

	if (left >= right) { return; } //If left is ever higher than right, something is wrong. But if they are equal the point terminate recursion
	if (right == left + 1) { //If only two, this is quicker
		if (arr[left]>arr[right]) {
			std::swap(arr[left], arr[right]); //Swap if needed
		}
		return;
	}

	int pivot = getPivot(left, right); //Pick a pivot point
	std::swap(arr[left], arr[pivot]); //Move the pivot to the leftmost point, the entire array will get rearranged now.

	int j = left + 1; //j will be the point were swapping into but arr[left] is reserved for the pivot
	for (int i = left + 1; i <= right; i++) { //Start the partitioning

		if (arr[i] <= arr[left]) //If arr[i] is less than the pivot, we need to swap it
			std::swap(arr[i], arr[j++]);

		//If they aren't, just move on
	}

	std::swap(arr[left], arr[--j]);//Restore the pivot to it's position, since j - 1 was the last position we swapped into, we cant safely assume it's less than the pivot

	quickSort(arr, left, j - 1); //Call the sort on the left
	quickSort(arr, j + 1, right); //and to the right of the pivot

	return; //When the above is done, this branch is done

}
Esempio n. 7
0
/* For all the rows, get the pivot and eliminate all rows and columns
 * for that particular pivot row. */
void computeGauss(int task_id)
{
    int i, j, k;
    double pivotval;
	
    for (i = 0; i < nsize; i++) { 
	if(task_id == 0) {
		getPivot(nsize,i);
		pivotval_global = matrix[i][i];
	
	    /* Scale the main row. */	
	    if (pivotval_global != 1.0) {
	        matrix[i][i] = 1.0;
	        for (j = i + 1; j < nsize; j++) {
		    matrix[i][j] /= pivotval_global;
	        }  
	       R[i] /= pivotval_global; 
	    }	
	} 
	barrier(task_num);
	/* Factorize the rest of the matrix. */
	for (j = i +1 + task_id; j < nsize; j = j + task_num ) {
	pivotval = matrix[j][i];
        matrix[j][i] = 0.0;  	
	    for (k = i + 1; k < nsize; k++) {
                matrix[j][k] -= pivotval * matrix[i][k];
            }          
            R[j] -= pivotval * R[i];
	}
        barrier(task_num);
   }
}
int getPivot(const vector<int>& A,int start,int end)
{
    if(start>end)
        return -1;
    if(start==end)
        return start;
    
    int mid=start+(end-start)/2;
    if(mid<end && A[mid]>A[mid+1])
        return mid;
    else if(mid>start && A[mid]<A[mid-1])
        return mid-1;
    else if(A[mid]>A[end])
        return getPivot(A,mid+1,end);
    else
        return getPivot(A,start,mid-1);
}
void Manipulator::updateHandleTransform()
{
    if ( getTarget() != NULL )
    {
        Transform *t = dynamic_cast<Transform *>(getTarget()->getCore());
        Matrix     m,n,o;

        Vec3f      translation;
        Quaternion rotation;
        Vec3f      scaleFactor;
        Quaternion scaleOrientation;

        m = t->getMatrix();
        m.getTransform(translation, rotation, scaleFactor, scaleOrientation);

        if( false == o.invertFrom(m) )
        {
            SWARNING << "Matrix is SINGULAR!!!\n";
        }
        else
        {
            Matrix n,ma,mb,mc,md;
            
            mb.setTranslate(translation);
            ma.setTranslate(Vec3f(getPivot()[0] * scaleFactor[0], 
                                  getPivot()[1] * scaleFactor[1], 
                                  getPivot()[2] * scaleFactor[2]) 
                            );
            mc.setRotate(rotation);
           
            n.multLeft(ma);
            n.multLeft(mc);
            n.multLeft(mb);
            n.multLeft(o);

            setMatrix(n);
        }
    }
}
Esempio n. 10
0
void ParallelSort::quickSortParallel(vector<T>* array, int lb, int ub, int level)
{
    if(ub <= lb)
        return;
    
    int pivotnum = getPivot(array,lb,ub);
    T pivot = (*array)[pivotnum];
    
    //int i = lb;
    //int j;
    T temp;
    
    // Swap pivot to bottom of list
    temp = (*array)[pivotnum];
    (*array)[pivotnum] = (*array)[lb];
    (*array)[lb] = temp;
    
    int left = lb;
    int right = ub;
    
    while(left < right)
    {
        while((*array)[left] <= pivot)
            left++;
        while(pivot < (*array)[right])
            right--;
        if(left < right)
        {
            temp = (*array)[left];
            (*array)[left] = (*array)[right];
            (*array)[right] = temp;
        }
    }
    (*array)[lb] = (*array)[right];
    (*array)[right] = pivot;
    
    if(level < RECTHRESH)
    {
#       pragma omp task shared(array, right, level)
        quickSortParallel(array, lb, right-1, level+1);
        quickSortParallel(array, right+1, ub, level+1);
#       pragma omp taskwait
    }
    else
    {
        quickSortLinear(array, lb, right-1);
        quickSortLinear(array, right+1, ub);
    }
}
Esempio n. 11
0
void quicksort2(
    const IT1& first1,
    const IT1& last1,
    const IT2& first2,
    const IT2& last2)
{
    typedef typename std::iterator_traits<IT1>::difference_type DT;
    DT DT1 = OrdinalTraits<DT>::one();
    if(last1-first1 > DT1) {
        IT1 pivot = getPivot(first1, last1);
        pivot = partition2(first1, last1, first2, last2, pivot);
        quicksort2(first1, pivot, first2, first2+(pivot-first1));
        quicksort2(pivot+1, last1, first2+(pivot-first1)+1, last2);
    }
}
Esempio n. 12
0
void computeGauss(int task_id)
{
    int i, j, k, begin, end;
    double localPivot;
    
    for (i = 0; i < nsize; i++) {

        if (task_id == 0) {

        	getPivot(nsize,i);
                
        	/* Scale the main row. */
            pivotval = matrix[i][i]; 

        	if (pivotval != 1.0) {
        	    matrix[i][i] = 1.0;
        	    for (j = i + 1; j < nsize; j++) {
        		  matrix[i][j] /= pivotval;
        	    }
        	    R[i] /= pivotval;
        	}

            numberOfRows = nsize-i-1;     
        }

        barrier(task_num); 

        /*Divide the divided task*/

        begin = ((numberOfRows * task_id) / task_num) + i;
        end = ((numberOfRows * (task_id + 1)) / task_num) + i;

    	/* Factorize the rest of the matrix. */
        for (j = begin+1; j <= end; j++) {
            localPivot = matrix[j][i];   
            matrix[j][i] = 0.0;
            for (k = i + 1; k < nsize; k++) {
                matrix[j][k] -= localPivot * matrix[i][k];
            }
            R[j] -= localPivot * R[i];
        }


        barrier(task_num);
    }
}
Esempio n. 13
0
int main(int argc, char ** argv) {

	FILE *file = fopen(argv[1], "r");
	char line[1024];

	while(fgets(line, 1024, file)) {

		int arraySize = processInput(line);	
		int *array;
		bool validInput = false;
		if(arraySize == -1) {
			printf("%s\n", "invalid input");
		} else {
			validInput = true;
		}

		if(validInput == true) {
			array = (int *) malloc(arraySize * sizeof(int));
			if(array == NULL) {
				perror("malloc failed");
				exit(1);
			}
			createArray(array, line, arraySize);
			printf("%s\n", "before sorting");
			printArray(array, arraySize);
			int lastIndex = arraySize - 1;
			int firstPivot = getPivot(array, 0, lastIndex);
			sort(array, 0, lastIndex, arraySize);
			printf("%s\n", "after sorting");
			printArray(array, arraySize);

		}

		if(validInput == true) {
			free(array);
		}	

	}

	fclose(file);

	return 0;
}
Esempio n. 14
0
void computeGauss(int nsize, int task_id)
{
    int i, j, k;
    double pivotval;
    int begin, end;
    for (i = 0; i < nsize; i++) {
        num_iter = nsize - i - 1;
        begin = (num_iter * task_id) / task_num + 1;
        end = (num_iter * (task_id + 1)) / task_num;
        barrier(task_num);
        if (task_id == 0) {
            if (i==9) printf("matrix[9][9] = %f, iteration = %d\n", matrix[9][9], i);    
            getPivot(nsize,i);        
	        /* Scale the main row. */
            pivotval = matrix[i][i];
            if (pivotval != 1.0) {
                matrix[i][i] = 1.0;
                for (j = i + 1; j < nsize; j++) {
                    matrix[i][j] /= pivotval;
                }
                R[i] /= pivotval;
            }
        }
        barrier (task_num);
        printf("proc %d: begin = %d, end = %d\n", proc_id, begin ,end);
        /* Factorize the rest of the matrix. */
        for (j = begin + i; j <= end + i; j++) {
            pivotval = matrix[j][i];
            matrix[j][i] = 0.0;
            for (k = i + 1; k < nsize; k++) {
                matrix[j][k] -= pivotval * matrix[i][k];
                if (j==9 && i==8)
                    printf("matrix[9][9] = %f, iteration = %d\n", matrix[9][9], i);    
            }
            R[j] -= pivotval * R[i];
            
        }
        barrier (task_num);
    }
}
Esempio n. 15
0
void ParallelSort::quickSortLinear(vector<T>* array, int lb, int ub)
{
    // Base Case
    if(ub <= lb)
        return;
   
    int pivotnum = getPivot(array,lb,ub);
    T pivot = (*array)[pivotnum];
    
    //int i = lb;
    //int j;
    T temp;
    
    // Swap pivot to bottom of list
    temp = (*array)[pivotnum];
    (*array)[pivotnum] = (*array)[lb];
    (*array)[lb] = temp;
    
    int left = lb;
    int right = ub;

    while(left < right)
    {
        while((*array)[left] <= pivot && (left < ub))
            left++;
        while(pivot < (*array)[right] && (right > lb))
            right--;
        if (left < right)
        {
            temp = (*array)[left];
            (*array)[left] = (*array)[right];
            (*array)[right] = temp;
        }
    }
    (*array)[lb] = (*array)[right];
    (*array)[right] = pivot;
    
    quickSortLinear(array,lb,right-1);
    quickSortLinear(array,right+1,ub);
}
void *work_thread(void *id){
    int i,j,k;
    double pivotVal;
    double hrtime1, hrtime2;
    int task_id = *((int *) id);


    barrier(task_num); //wait for all threads to come and then start
    if(task_id == 0){
        hrtime1 = gethrtime_x86();
    }

    for(i=0; i<nsize; i++){
        if(task_id == i % task_num){
            getPivot(nsize,i); // select corresponding thread to find pivot in row
        }
        barrier(task_num); //wait for all threads finish 
        pivotVal = matrix[i][i];

        for (j = i + 1 ; j < nsize; j++){

            if(task_id == j % task_num){
                pivotVal = matrix[j][i];
                matrix[j][i] = 0.0;
                for (k = i + 1 ; k < nsize; k++){
                    matrix[j][k] -= pivotVal * matrix[i][k];
                }
                B[j] -= pivotVal * B[i];
            }
        }
        barrier(task_num);
    }
    hrtime2 = gethrtime_x86();

    if(task_id==0){
        printf("Hrtime = %f seconds\n", hrtime2 - hrtime1);
    }
    return NULL;
}
int Solution::search(const vector<int> &A, int B) {
    // Do not write main() function.
    // Do not read input, instead use the arguments to the function.
    // Do not print the output, instead return values as specified
    // Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details
    if(A.size()==0)
        return -1;
    int pivot=0;
    if(A[0]<A[A.size()-1])
        pivot=-1;
    if(pivot==-1)
        return binarySearch(A,B,0,A.size()-1);
    else
    {
        pivot=getPivot(A,0,A.size()-1);
        if(A[pivot]==B)
            return pivot;
        else if(B>=A[0])
            return binarySearch(A,B,0,pivot-1);
        else
            return binarySearch(A,B,pivot+1,A.size()-1);
    }
    return 0;
}
Esempio n. 18
0
static void quick_sort(int32_t* array,int32_t left,int32_t right)
{
    if(right > left)
    {
        int32_t pivot = getPivot(array,left,right);
        int32_t i     = left;
        int32_t j     = right;

        if(pivot != -1)
        {
            while(1)
            {
                while(array[i] < pivot) i++;
                while(array[j] > pivot) j--;
                if(i >= j) break;
                SWAP(int32_t,array[i],array[j]);
                i++;
                j--;
            }
        }
        if(left < i - 1) quick_sort(array,left,i -1);
        if(j+1 < right) quick_sort(array,j+1,right);
    }
}
Esempio n. 19
0
glm::vec2 AreaNode::toGlobal(const glm::vec2& localPos) const
{
    glm::vec2 globalPos = getRotatedPivot(localPos, getAngle(), getPivot());
    return globalPos+m_RelViewport.tl;
}
Esempio n. 20
0
glm::vec2 AreaNode::toLocal(const glm::vec2& globalPos) const
{
    glm::vec2 localPos = globalPos-m_RelViewport.tl;
    return getRotatedPivot(localPos, -getAngle(), getPivot());
}
Esempio n. 21
0
int main(int argc, char * argv[])
{
    int nproc, iproc;
    MPI_Status status;
    MPI_Init(&argc, &argv);

    int i = 0;
    double starttime;
    /*All for the sending / recieving */
    int* pivot=(int*)malloc(sizeof(int));
    int* send=(int*)malloc(sizeof(int));
    int* recv=(int*)malloc(sizeof(int));
    
    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
    MPI_Comm_rank(MPI_COMM_WORLD, &iproc);
    
    int mySize=SIZE/nproc;
    
    //my values
    int* vals = (int*)malloc( SIZE * sizeof(int));
    //for holding their values that come in
    int* theirs = (int*)malloc( SIZE * sizeof(int));
    //for joining the two and
    int* tmp = (int*)malloc( SIZE * sizeof(int));
    
    //sort our values
    qsort(vals, mySize, sizeof(int), sort);
    
    for (i=0; i<mySize; i++) 
        vals[i]=arc4random();
    /*Create the communicator for use throughout*/
    MPI_Comm newcomm;
    MPI_Comm_split(MPI_COMM_WORLD, 1, iproc, &newcomm);    

    int groupSize=nproc;
    starttime = When();

    while (groupSize>1) {
        /* Get the new rank/size */
        MPI_Comm_size(newcomm, &nproc);
        MPI_Comm_rank(newcomm, &iproc);        
        //Find the Pivot
        *pivot=getPivot(vals, mySize);
        
        if(1){
            //send it out among the group
            MPI_Bcast(pivot, 1, MPI_INT, 0, newcomm);
        }
        else{
            //median of all in group
            if(iproc==0){
                //we recieve them all
                for (i=1; i<nproc; i++) {
                    MPI_Recv(recv, 1, MPI_INT, i, 0, newcomm, &status);
                    tmp[i]=*recv;
                }
                tmp[0]=*pivot;
                qsort(tmp, nproc, sizeof(int), sort);
                *pivot=tmp[(nproc/2)];
                //fprintf(stderr, "pivot=%i\n",*pivot);
                for (i=1; i<nproc; i++) {
                    MPI_Send(pivot, 1, MPI_INT, i, 0, newcomm);
                }

            }
            else{
                //we all send it to zero and let it decide.
                MPI_Send(pivot, 1, MPI_INT, 0, 0, newcomm);
                MPI_Recv(pivot, 1, MPI_INT, 0, 0, newcomm, &status);
                
            }
            
        }
        //calculate how many we will send
        *send=0;
        for (i=0; i<mySize; i++) {
            if(iproc < nproc / 2){
                if (vals[i] >= *pivot) {
                    tmp[*send]=vals[i];
                    (*send)++;
                    
                }
            }
            else{
                if (vals[i] <= *pivot) {
                    tmp[*send]=vals[i];
                    (*send)++;
                }
            }
        }
        
        //smalls send first
        if(iproc < nproc/2){
            
            //send the size then the values
            //fprintf(stderr,"\t\t\t%d: sending %d to %d\n", iproc, *send, iproc+(nproc/2));
            MPI_Send(send, 1, MPI_INT, iproc+(nproc/2), 0, newcomm);
            MPI_Send(tmp, *send, MPI_INT, iproc+(nproc/2), 0, newcomm);
            //we recieve the two
            MPI_Recv(recv, 1, MPI_INT, iproc+(nproc/2), 0, newcomm, &status);
            //fprintf(stderr,"\t\t\t\t%d: reciving %d from %d\n", iproc, *recv, iproc+(nproc/2));
            MPI_Recv(theirs, *recv, MPI_INT, iproc+(nproc/2), 0, newcomm, &status);
        }
        else {
            
            //we recieve the two
            MPI_Recv(recv, 1, MPI_INT, iproc-(nproc/2), 0, newcomm, &status);
            //fprintf(stderr,"\t\t\t\t%d: reciving %d from %d\n", iproc, *recv, iproc-(nproc/2));
            MPI_Recv(theirs, *recv, MPI_INT, iproc-(nproc/2), 0, newcomm, &status);
            
            //send the size then the values
            //fprintf(stderr,"\t\t\t%d: sending %d to %d\n", iproc, *send, iproc-(nproc/2));
            MPI_Send(send, 1, MPI_INT, iproc-(nproc/2), 0, newcomm);
            MPI_Send(tmp, *send, MPI_INT, iproc-(nproc/2), 0, newcomm);
        }
        //now we combine the theirs and what is left of ours.
        
        if(iproc<nproc/2){
            mySize-=*send;

            for (i=0; i<*recv; i++) {
                vals[mySize]=theirs[i];
                mySize++;
                
            }
        }
        else{
            int off=0;
            for (i=0; i<mySize; i++) {
                if(vals[i]>= *pivot){
                    theirs[*recv+off]=vals[i];
                    off++;
                }
            }
            int* temp=vals;
            vals=theirs;
            theirs=temp;
            mySize=*recv+(mySize-*send);
        }
        //fprintf(stderr,"%d:my size:%i,\n",iproc, mySize);
        qsort(vals, mySize, sizeof(int), sort);
        
        //reset the size of the group
        MPI_Comm_split(newcomm, iproc < nproc/2 , iproc, &newcomm);
        groupSize /= 2;
    }
    
    MPI_Comm_rank(MPI_COMM_WORLD, &iproc);

    fprintf(stderr,"\n%d:done: %f elements: %i\n", iproc, (When()-starttime),mySize);
    free(vals);
    free(theirs);
    free(tmp);
    free(send);
    free(recv);
   
    MPI_Finalize();
   
    
    return 0;
}
Esempio n. 22
0
int GOConstraint::methodsBridge(lua_State* luaVM) {
	if (isCurrentMethod("getFullID")) {
		lua_pushstring(luaVM, id.c_str());
		return 1;
	}
	if (isCurrentMethod("setPivot")) {
		setPivot(CVector(lua_tonumber(luaVM, 1), lua_tonumber(luaVM, 2), lua_tonumber(luaVM, 3)));
		return 0;
	}
	if (isCurrentMethod("getPivot")) {
		luaPushVector(luaVM, getPivot().x, getPivot().y, getPivot().z);
		return 1;
	}
	if (isCurrentMethod("getConstraintType")) {
		lua_pushinteger(luaVM, getConstraintType());
		return 1;
	}
	if (isCurrentMethod("setSecondObject")) {
		if (lua_isnil(luaVM, 1)) {
			setSecondObject(NULL);
			return 0;
		}
		lua_pushstring(luaVM, "cpointer");
		lua_gettable(luaVM, -2);
		PhysicObject* o = (PhysicObject*)lua_tointeger(luaVM, -1);
		setSecondObject(o);
		lua_pop(luaVM, -1);
		return 0;
	}
	if (isCurrentMethod("getSecondObject")) {
		if (getSecondObject() == NULL || getSecondObject()->getObjectID() == "") {
			lua_pushnil(luaVM);
		}
		lua_getglobal(luaVM, getSecondObject()->getObjectID().c_str());
		return 1;
	}
	if (isCurrentMethod("setSecondPivot")) {
		setSecondPivot(CVector(lua_tonumber(luaVM, 1), lua_tonumber(luaVM, 2), lua_tonumber(luaVM, 3)));
		return 0;
	}
	if (isCurrentMethod("getSecondPivot")) {
		luaPushVector(luaVM, getSecondPivot().x, getSecondPivot().y, getSecondPivot().z);
		return 1;
	}
	if (isCurrentMethod("setSecondObjectID")) {
		string objid = lua_tostring(luaVM, 1);
		PhysicObject* obj = (PhysicObject*)Game::instance->mapManager->findByID(objid);
		setSecondObject(obj);
		return 0;
	}
	if (isCurrentMethod("getSecondObjectID")) {
		if (getSecondObject() == NULL) {
			lua_pushstring(luaVM, "");
			return 0;
		}
		lua_pushstring(luaVM, getSecondObject()->getObjectID().c_str());
		return 1;
	}


	return LuaBridge::methodsBridge(luaVM);
}
Esempio n. 23
0
void sort(int * ar, int i0, int i1, int s) {

	int size = s;
	int x0;
	int x1;
	int lowOpen;
	int upOpen;
	int counter;
	int inPlaceIndex;

	bool keepSorting = true;

	if(i0 == i1) {
		keepSorting = false;
	}

	if(keepSorting == true) {
		x0 = *(ar + i0);
		x1 = *(ar + i1);

		if(i0 + 1 == i1) {
			if(x0 > x1) {
				swap(ar, i0, i1);
			}
			keepSorting = false;
		}

		lowOpen = i0;
		upOpen = i1 - 1;
		counter = i0;

	}

	if(keepSorting == true) {
		int pivotIndex = getPivot(ar, i0, i1);
		int pivot = *(ar + pivotIndex);
		swap(ar, pivotIndex, i1);
		while(lowOpen != upOpen) {
			int currentInt = *(ar + counter);
			if(currentInt > pivot) {
				swap(ar, counter, upOpen);
				upOpen--;
			} else {
				counter++;
				lowOpen++;
			}

		}
		int midIndex = lowOpen;
		int mid = *(ar + midIndex);
		if(mid > pivot) {
			swap(ar, i1, midIndex);
			inPlaceIndex = midIndex;
		} else {
			swap(ar, i1, midIndex + 1);
			inPlaceIndex = midIndex + 1;
		}

		int leftListIndex = inPlaceIndex - 1;
		int rightListIndex = inPlaceIndex + 1;

		if(i0 <= leftListIndex) {
			sort(ar, i0, leftListIndex, size);
		}
		if(i1 >= rightListIndex) {
			sort(ar, rightListIndex, i1, size);
		}

	}

}