当前位置: 首页>>代码示例>>C++>>正文


C++ Bounds::getMiddle方法代码示例

本文整理汇总了C++中Bounds::getMiddle方法的典型用法代码示例。如果您正苦于以下问题:C++ Bounds::getMiddle方法的具体用法?C++ Bounds::getMiddle怎么用?C++ Bounds::getMiddle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bounds的用法示例。


在下文中一共展示了Bounds::getMiddle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SplitData

size_t SplitData(
    std::vector<CellData<D,C>*>& vdata, SplitMethod sm, 
    size_t start, size_t end, const Position<C>& meanpos)
{
    Assert(end-start > 1);
    size_t mid=0;

    Bounds<C> b;
    for(size_t i=start;i<end;++i) b += vdata[i]->getPos();

    int split = b.getSplit();

    switch (sm) { // three different split methods
      case MIDDLE :
           { // Middle is the average of the min and max value of x or y
               double splitvalue = b.getMiddle(split);
               DataCompareToValue<D,C> comp(split,splitvalue);
               typename std::vector<CellData<D,C>*>::iterator middle =
                   std::partition(vdata.begin()+start,vdata.begin()+end,comp);
               mid = middle - vdata.begin();
           } break;
      case MEDIAN :
           { // Median is the point which divides the group into equal numbers
               DataCompare<D,C> comp(split);
               mid = (start+end)/2;
               typename std::vector<CellData<D,C>*>::iterator middle = vdata.begin()+mid;
               std::nth_element(vdata.begin()+start,middle,vdata.begin()+end,comp);
           } break;
      case MEAN :
           { // Mean is the weighted average value of x or y
               double splitvalue = meanpos.get(split);
               DataCompareToValue<D,C> comp(split,splitvalue);
               typename std::vector<CellData<D,C>*>::iterator middle =
                   std::partition(vdata.begin()+start,vdata.begin()+end,comp);
               mid = middle - vdata.begin();
           } break;
      case RANDOM :
           { // Random is a random point from the first quartile to the third quartile
               DataCompare<D,C> comp(split);

               // The code for RANDOM is same as MEDIAN except for the next line.
               // Note: The lo and hi values are slightly subtle.  We want to make sure if there
               // are only two values, we actually split.  So if start=1, end=3, the only possible
               // result should be mid=2.  Otherwise, we want roughly 1/4 and 3/4 of the span.
               mid = select_random(end-3*(end-start)/4,start+3*(end-start)/4);

               typename std::vector<CellData<D,C>*>::iterator middle = vdata.begin()+mid;
               std::nth_element(vdata.begin()+start,middle,vdata.begin()+end,comp);
           } break;
      default :
           myerror("Invalid SplitMethod");
    }

    if (mid == start || mid == end) {
        xdbg<<"Found mid not in middle.  Probably duplicate entries.\n";
        xdbg<<"start = "<<start<<std::endl;
        xdbg<<"end = "<<end<<std::endl;
        xdbg<<"mid = "<<mid<<std::endl;
        xdbg<<"sm = "<<sm<<std::endl;
        xdbg<<"b = "<<b<<std::endl;
        xdbg<<"split = "<<split<<std::endl;
        for(size_t i=start; i!=end; ++i) {
            xdbg<<"v["<<i<<"] = "<<vdata[i]<<std::endl;
        }
        // With duplicate entries, can get mid == start or mid == end. 
        // This should only happen if all entries in this set are equal.
        // So it should be safe to just take the mid = (start + end)/2.
        // But just to be safe, re-call this function with sm = MEDIAN to 
        // make sure.
        Assert(sm != MEDIAN);
        return SplitData(vdata,MEDIAN,start,end,meanpos);
    }
    Assert(mid > start);
    Assert(mid < end);
    return mid;
}
开发者ID:inonchiu,项目名称:TreeCorr,代码行数:76,代码来源:Cell.cpp


注:本文中的Bounds::getMiddle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。