Changeset 211

Show
Ignore:
Timestamp:
08/22/10 21:53:08 (1 year ago)
Author:
dsimcha
Message:

Fix ranges: Add save() and @property stuff.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/alloc.d

    r209 r211  
    601601        uint num; 
    602602        uint upTo; 
    603         uint front() { 
     603        @property size_t front() { 
    604604            return num; 
    605605        } 
     
    607607            num++; 
    608608        } 
    609         bool empty() { 
     609        @property bool empty() { 
    610610            return num >= upTo; 
    611611        } 
     
    758758public: 
    759759    /// 
    760     void popFront() { 
     760    void popFront() 
     761    in { 
     762        assert(!empty); 
     763    } body { 
    761764        this._length--; 
    762765        if(next is null) { 
     
    786789    /// 
    787790    static if(vals) { 
    788         ref Unqual!(K) front() { 
     791        @property ref Unqual!(K) front() 
     792        in { 
     793            assert(!empty); 
     794        } body { 
    789795            return *frontElem; 
    790796        } 
    791797    } else { 
    792        Unqual!(K) front() { 
     798       @property Unqual!(K) front() 
     799       in { 
     800            assert(!empty); 
     801       } body { 
    793802            return *frontElem; 
    794803        } 
     
    796805 
    797806    /// 
    798     bool empty() { 
     807    @property bool empty() { 
    799808        return index == size_t.max; 
    800809    } 
    801810 
    802811    /// 
    803     size_t length() { 
     812    @property size_t length() { 
    804813        return _length; 
     814    } 
     815 
     816    /// 
     817    @property typeof(this) save() { 
     818        return this; 
    805819    } 
    806820} 
     
    10721086 
    10731087    /// 
    1074     size_t length() const { 
     1088    @property size_t length() const { 
    10751089        return _length; 
    10761090    } 
     
    14231437 
    14241438    /// 
    1425     size_t length() { 
     1439    @property size_t length() { 
    14261440       return _length; 
    14271441    } 
     
    19982012 
    19992013    /**Number of elements in the tree.*/ 
    2000     size_t length() const pure nothrow @property { 
     2014    @property size_t length() const pure nothrow @property { 
    20012015        return _length; 
    20022016    } 
     
    20952109 
    20962110    /// 
    2097     size_t length() const pure nothrow { 
     2111    @property size_t length() const pure nothrow { 
    20982112        return tree.length; 
    20992113    } 
     
    21662180 
    21672181    /// 
    2168     size_t length() const pure nothrow { 
     2182    @property size_t length() const pure nothrow { 
    21692183        return tree.length; 
    21702184    } 
  • trunk/base.d

    r209 r211  
    511511    } 
    512512 
    513     size_t length() { 
     513    @property size_t length() { 
    514514        return indices.length; 
    515515    } 
     
    796796        tn--; 
    797797        fp++; 
    798         auto ret = classA.front()
     798        auto ret = classA.front
    799799        classA.popFront(); 
    800800        return ret; 
     
    804804        fn--; 
    805805        tp++; 
    806         auto ret = classB.front()
     806        auto ret = classB.front
    807807        classB.popFront(); 
    808808        return ret; 
     
    811811    double area = 0; 
    812812    while(!classA.empty && !classB.empty) { 
    813         if(classA.front() < classB.front()) { 
     813        if(classA.front < classB.front) { 
    814814            currentVal = popA(); 
    815815        } else { 
     
    818818 
    819819        // Handle ties. 
    820         while(!classA.empty && classA.front() == currentVal) { 
     820        while(!classA.empty && classA.front == currentVal) { 
    821821            popA(); 
    822822        } 
    823823 
    824         while(!classB.empty && classB.front() == currentVal) { 
     824        while(!classB.empty && classB.front == currentVal) { 
    825825            popB(); 
    826826        } 
     
    931931} 
    932932 
    933 /**A struct that generates all possible permutations of a sequence.  Due to 
    934  * some optimizations done under the hood, this works as an input range if 
    935  * T.sizeof > 1, or a forward range if T.sizeof == 1. 
     933/**A struct that generates all possible permutations of a sequence. 
    936934 * 
    937935 * Note:  Permutations are output in undefined order. 
     
    10231021     * depending on whether bufType == Buf.DUP or Buf.RECYCLE. 
    10241022     */ 
    1025     PermArray front() { 
     1023    @property PermArray front() { 
    10261024        static if(bufType == Buffer.DUP) { 
    10271025            return perm[0..len].dup; 
     
    10641062 
    10651063    /// 
    1066     bool empty() @property
     1064    @property bool empty()
    10671065        return nPerms == 0; 
    10681066    } 
     
    10701068    /**The number of permutations left. 
    10711069     */ 
    1072     size_t length() const pure nothrow { 
     1070    @property size_t length() const pure nothrow { 
    10731071        return nPerms; 
     1072    } 
     1073 
     1074    /// 
     1075    @property typeof(this) save() { 
     1076        auto ret = this; 
     1077        static if(T.sizeof > 1) { 
     1078            ret.perm = (ret.perm[0..len].dup).ptr; 
     1079        } 
     1080        return ret; 
    10741081    } 
    10751082} 
     
    13051312    } 
    13061313 
    1307     CombArray front() { 
     1314    @property CombArray front() { 
    13081315        static if(bufType == Buffer.RECYCLE) { 
    13091316            static if(!is(T == uint)) { 
     
    13261333 
    13271334    /// 
    1328     bool empty() const pure nothrow { 
     1335    @property bool empty() const pure nothrow { 
    13291336        return length == 0; 
    13301337    } 
    13311338 
    13321339    /// 
    1333     size_t length() const pure nothrow { 
     1340    @property size_t length() const pure nothrow { 
    13341341        return _length; 
     1342    } 
     1343 
     1344    /// 
     1345    @property typeof(this) save() { 
     1346        auto ret = this; 
     1347        ret.pos = (pos[0..R].dup).ptr; 
     1348 
     1349        if(chosen !is null) { 
     1350            ret.chosen = (chosen[0..R].dup).ptr; 
     1351        } 
     1352 
     1353        return ret; 
    13351354    } 
    13361355} 
     
    14911510    } 
    14921511 
    1493     real front() { 
     1512    @property real front() { 
    14941513        return _front; 
    14951514    } 
     
    15171536    } 
    15181537 
    1519     bool empty() { 
     1538    @property bool empty() { 
    15201539        return inputRange.empty; 
    15211540    } 
  • trunk/cor.d

    r209 r211  
    140140        uint num; 
    141141        uint upTo; 
    142         uint front() { 
     142        @property size_t front() { 
    143143            return num; 
    144144        } 
     
    146146            num++; 
    147147        } 
    148         bool empty() { 
     148        @property bool empty() { 
    149149            return num >= upTo; 
    150150        } 
     
    409409        uint num; 
    410410        uint upTo; 
    411         uint front() { 
     411        @property size_t front() { 
    412412            return num; 
    413413        } 
     
    415415            num++; 
    416416        } 
    417         bool empty() { 
     417        @property bool empty() { 
    418418            return num >= upTo; 
    419419        } 
     
    703703        uint num; 
    704704        uint upTo; 
    705         uint front() { 
     705        @property size_t front() { 
    706706            return num; 
    707707        } 
     
    709709            num++; 
    710710        } 
    711         bool empty() { 
     711        @property bool empty() { 
    712712            return num >= upTo; 
    713713        } 
  • trunk/infotheory.d

    r209 r211  
    142142} 
    143143 
    144 /**Iterate over a set of ranges in lockstep and return an ObsEnt, 
     144/**Iterate over a set of ranges by value in lockstep and return an ObsEnt, 
    145145 * which is used internally by entropy functions on each iteration.*/ 
    146146struct Joint(T...) { 
    147147    T _jointRanges; 
    148148 
    149     ObsEnt!(ElementsTuple!(T)) front() { 
     149    @property ObsEnt!(ElementsTuple!(T)) front() { 
    150150        alias ElementsTuple!(T) E; 
    151151        alias ObsEnt!(E) rt; 
     
    163163    } 
    164164 
    165     bool empty() { 
     165    @property bool empty() { 
    166166        foreach(elem; _jointRanges) { 
    167167            if(elem.empty) { 
     
    173173 
    174174    static if(T.length > 0 && allSatisfy!(dstats.base.hasLength, T)) { 
    175         uint length() { 
    176             uint ret = uint.max; 
     175        @property size_t length() { 
     176            size_t ret = size_t.max; 
    177177            foreach(range; _jointRanges) { 
    178178                auto len = range.length; 
  • trunk/random.d

    r209 r211  
    183183    } 
    184184 
    185     typeof(randFun(args)) front() { 
     185    @property typeof(randFun(args)) front() { 
    186186        return frontElem; 
    187187    } 
     
    202202    } 
    203203 
    204     typeof(this) save() @property
     204    @property typeof(this) save()
    205205        return this; 
    206206    } 
  • trunk/regress.d

    r209 r211  
    6363    } 
    6464 
    65     double front() const pure nothrow { 
     65    @property double front() const pure nothrow { 
    6666        return cache; 
    6767    } 
     
    7474    } 
    7575 
    76     typeof(this) save() @property
     76    @property typeof(this) save()
    7777        return this; 
    7878    } 
    7979 
    80     bool empty() @property
     80    @property bool empty()
    8181        return range.empty; 
    8282    } 
     
    277277        size_t i = 0; 
    278278        foreach(elem; X) { 
    279             double frnt = elem.front()
     279            double frnt = elem.front
    280280            sum += frnt * betas[i]; 
    281281            i++; 
     
    309309    } 
    310310 
    311     double front() const pure nothrow { 
     311    @property double front() const pure nothrow { 
    312312        return residual; 
    313313    } 
     
    329329    } 
    330330 
    331     bool empty() const pure nothrow { 
     331    @property bool empty() const pure nothrow { 
    332332        return _empty; 
    333333    } 
    334334 
    335     typeof(this) save() @property
     335    @property typeof(this) save()
    336336        auto ret = this; 
    337337        ret.Y = ret.Y.save; 
     
    512512        double residual = residuals.front; 
    513513        S += residual * residual; 
    514         double Yfront = residuals.Y.front()
     514        double Yfront = residuals.Y.front
    515515        double predicted = Yfront - residual; 
    516516        R2Calc.put(predicted, Yfront); 
  • trunk/summary.d

    r207 r211  
    152152        uint num; 
    153153        uint upTo; 
    154         uint front() { 
     154        @property size_t front() { 
    155155            return num; 
    156156        } 
     
    158158            num++; 
    159159        } 
    160         bool empty() { 
     160        @property bool empty() { 
    161161            return num >= upTo; 
    162162        } 
     
    10981098 
    10991099    /// 
    1100     double front() { 
     1100    @property double front() { 
    11011101        return z(range.front); 
    11021102    } 
     
    11081108 
    11091109    /// 
    1110     bool empty() { 
     1110    @property bool empty() { 
    11111111        return range.empty; 
     1112    } 
     1113 
     1114    static if(isForwardRange!(T)) { 
     1115        /// 
     1116        @property typeof(this) save() { 
     1117            auto ret = this; 
     1118            ret.range = range.save; 
     1119            return ret; 
     1120        } 
    11121121    } 
    11131122 
     
    11211130    static if(isBidirectionalRange!(T)) { 
    11221131        /// 
    1123         double back() { 
     1132        @property double back() { 
    11241133            return z(range.back); 
    11251134        } 
     
    11331142    static if(dstats.base.hasLength!(T)) { 
    11341143        /// 
    1135         size_t length() { 
     1144        @property size_t length() { 
    11361145            return range.length; 
    11371146        }