Changeset 3bf812b for doc


Ignore:
Timestamp:
May 22, 2020, 4:32:11 PM (17 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast, new-ast-unique-expr
Children:
8e1b1bb
Parents:
8f4f3e0
Message:

snzi creator now supports m-ary trees

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/thierry_delisle_PhD/code/snzi.hpp

    r8f4f3e0 r3bf812b  
    1111        std::unique_ptr<snzi_t::node[]> nodes;
    1212
    13         snzi_t(unsigned depth);
     13        snzi_t(unsigned depth, unsigned base = 2);
    1414
    1515        void arrive(int idx) {
    16                 idx &= mask;
     16                idx %= mask;
    1717                nodes[idx].arrive();
    1818        }
    1919
    2020        void depart(int idx) {
    21                 idx &= mask;
     21                idx %= mask;
    2222                nodes[idx].depart();
    2323        }
     
    145145};
    146146
    147 snzi_t::snzi_t(unsigned depth)
    148         : mask((1 << depth) - 1)
    149         , root( ((1 << depth) * 2) - 2)
     147snzi_t::snzi_t(unsigned depth, unsigned base)
     148        : mask( std::pow(base, depth) )
     149        , root( ((std::pow(base, depth + 1) - 1) / (base -1)) - 1 )
    150150        , nodes(new node[ root + 1 ]())
    151151{
    152         int width = (1 << depth);
     152        int width = std::pow(base, depth);
    153153        for(int i = 0; i < root; i++) {
    154                 nodes[i].parent = &nodes[(i / 2) + width ];
     154                nodes[i].parent = &nodes[(i / base) + width ];
    155155        }
    156156}
Note: See TracChangeset for help on using the changeset viewer.