Alex Bikfalvi
SimStream Documentation
ModelSelectRandom.cpp
00001 #include "Headers.h" 00002 #include "ModelSelectRandom.h" 00003 #include "Rand.h" 00004 00005 CModelSelectRandom::CModelSelectRandom( 00006 unsigned int numChannels, 00007 unsigned int numLayers, 00008 unsigned int numPeers 00009 ) : CModelSelect(numChannels, numLayers, numPeers) 00010 { 00011 this->candidates = new CPeer*[this->numPeers]; 00012 } 00013 00014 CModelSelectRandom::~CModelSelectRandom() 00015 { 00016 delete[] this->candidates; 00017 } 00018 00019 CPeer** CModelSelectRandom::Select(__time time, __uint32 channel, __uint32 child) 00020 { 00021 assert(channel < this->numChannels); 00022 assert(child < this->numPeers); 00023 00024 CPeer* peerChild = &this->peers[child]; 00025 00026 for(__uint32 layer = 0; layer < this->numLayers; layer++) 00027 { 00028 unsigned int count = 0; 00029 00030 for(set<CPeer*>::iterator iter = this->index[channel].begin(); iter != this->index[channel].end(); iter++) 00031 if(!this->IsResult(*iter, layer)) 00032 if(peerChild->VerifyParent(channel, layer, *iter)) 00033 this->candidates[count++] = *iter; 00034 00035 this->result[layer] = count ? this->candidates[CRand::Generate(count)] : NULL; 00036 } 00037 00038 return this->result; 00039 } 00040 00041 CPeer* CModelSelectRandom::Select(__time time, __uint32 channel, __uint32 layer, __uint32 child) 00042 { 00043 assert(channel < this->numChannels); 00044 assert(child < this->numPeers); 00045 00046 CPeer* peerChild = &this->peers[child]; 00047 00048 unsigned int count = 0; 00049 00050 for(set<CPeer*>::iterator iter = this->index[channel].begin(); iter != this->index[channel].end(); iter++) 00051 if(!this->IsResult(*iter, layer)) 00052 if(peerChild->VerifyParent(channel, layer, *iter)) 00053 this->candidates[count++] = *iter; 00054 00055 return count ? this->candidates[CRand::Generate(count)] : NULL; 00056 } 00057 00058
Last updated: February 8, 2011