text: #include "HSDistinctMass.h"
  using namespace std;
  
  Forest createForest(long int* numNodes, long int* sizeForest, vector <vector <float>> &data, vector <int> &trainingIndices, int numTree,
  int numDim, int* sizeLimit, int* depthLimit, time_t rseed, int* splitPointStrategy, int* subSamplingSize){
      
      int dimInst = data[0].size() - 1;
      int numSub = trainingIndices.size();
  
      //Initialise parameters.
      struct Forest forest;
      forest.numTree=numTree;
      forest.numSub=numSub;
      forest.numDim=numDim;
      forest.sizeLimit=*sizeLimit;
      forest.depthLimit=*depthLimit;
      forest.rseed=rseed;
      forest.Trees=new Tree[numTree];
  
      srand(rseed);
      clock_t start, end;
      start=clock();
  
      for(int i=0; i<numTree; i++){
  
          
          //Indices of randomly selected dimensions
          vector <int> indexDim;
  
          if(numDim<dimInst && numDim>0){
  
              //Randomly select dimensions.
              vector<pair<int, int> > selectIndex;
              for(int j=0; j<dimInst; j++){
                  selectIndex.push_back(make_pair(rand(), j));
              }
              sort(selectIndex.begin(), selectIndex.end());
              for(int j=0; j<numDim; j++){
                  indexDim.push_back(selectIndex[j].second);
              }
          }
          else{
  
              for(int j=0; j<dimInst; j++){
                  indexDim.push_back(j);
              }
  
          }
  
          //We only need max and min values for attributes in indexDim.
          float *maxAtt = new float[dimInst]; 
          float *minAtt = new float[dimInst]; 
          
          vector <int> subSamplingIndices;
  
          //Randomly selected sub-samples
          vector<pair<int, int> > selectIndex;
          for(int j=0; j<trainingIndices.size(); j++){
              selectIndex.push_back(make_pair(rand(), j));
          }
          sort(selectIndex.begin(), selectIndex.end());
  
          if(*subSamplingSize == 0){
              *subSamplingSize = trainingIndices.size();
          }
          
          for(int j=0; j<*subSamplingSize; j++){
              subSamplingIndices.push_back(trainingIndices[selectIndex[j].second]);
          }
       
          initWorkspace(data, subSamplingIndices, maxAtt, minAtt);   //Initialise the work space.
          int curtDepth = 0;
          
          //Create a half space tree.
          createTree(numNodes, sizeForest, &forest.Trees[i], data, subSamplingIndices, maxAtt, minAtt, &curtDepth, indexDim, sizeLimit, depthLimit, splitPointStrategy); 
          
      }
  
      end=clock();
      forest.elapsedTime=(double)(end-start)/double(CLOCKS_PER_SEC);
  
      return forest;
      
  }