Last active
December 14, 2015 22:49
-
-
Save coldcue/5161663 to your computer and use it in GitHub Desktop.
Unatkoztam, ezért optimalizáltam a kódot, szóval profilerben is jól fut már, de a cporta nem fogadja el :D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "vektor.h" | |
unsigned int Vektor::defSize = 13; | |
double Vektor::defValue = -435; | |
Vektor::Vektor(const Vektor& v) { | |
nElements = v.nElements; | |
pVec = new double[nElements]; | |
register double *vit, *it, *end; | |
for(vit=v.pVec, end=v.pVec+nElements, it=pVec; vit!=end; vit++, it++) | |
*it=*vit; | |
} | |
Vektor::~Vektor() { | |
delete[] pVec; | |
} | |
Vektor& Vektor::operator=(const Vektor& v) { | |
if(this==&v) return *this; | |
if(v.nElements != nElements) { | |
delete[] pVec; | |
nElements = v.nElements; | |
pVec = new double[nElements]; | |
} | |
register double *vit, *it, *end; | |
for(vit=v.pVec, end=v.pVec+nElements, it=pVec; vit!=end; vit++, it++) | |
*it=*vit; | |
return *this; | |
} | |
double& Vektor::operator[](unsigned int idx) { | |
if(idx>=nElements) throw "DP1FGW"; | |
return pVec[idx]; | |
} | |
const double& Vektor::operator[](unsigned int idx) const { | |
if(idx>=nElements) throw "DP1FGW"; | |
return pVec[idx]; | |
} | |
Vektor operator*(register double val, const Vektor& vec) | |
{ | |
register Vektor v = vec; | |
register double *it, *end; | |
for(it=v.pVec, end=v.pVec+v.nElements; it!=end; it++) | |
(*it)*=val; | |
return v; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment