34 template <
typename Iterator>
40 (1u << log_size) < size ?
44 return padded_size * 2u - 1u;
49 template <
typename Iterator>
55 (1u << nvbio::
log2( size )) < size ?
56 1u << (nvbio::
log2( size )+1u) :
57 1u << nvbio::
log2( size ) )
62 template <
typename Iterator>
67 for (
uint32 i = m_size; i < m_padded_size; ++i)
72 for (
uint32 n = m_padded_size; n >= 2; n >>= 1)
74 const uint32 dst = src + n;
77 for (
uint32 i = 0; i < m; ++i)
78 m_cells[ dst + i ] = (m_cells[ src + i*2 ] + m_cells[ src + i*2 + 1u ]);
86 template <
typename Iterator>
92 for (
uint32 m = m_padded_size; m >= 2; m >>= 1, j >>= 1)
94 m_cells[ dst + j ] += v;
102 template <
typename Iterator>
110 uint32 parent_base = m_padded_size;
113 for (
uint32 m = m_padded_size >> 1; parent_base + parent < nodes(); m >>= 1)
115 m_cells[ parent_base +
parent ] =
116 m_cells[ prev_base + parent*2 ] +
117 m_cells[ prev_base + parent*2+1 ];
119 prev_base = parent_base;
127 template <
typename Iterator>
134 uint32 node_base = padded_size*2u - 4u;
140 for (
uint32 m = 2; m < padded_size; m *= 2)
143 const float l = float(tree.
cell( node_base + node_index ));
144 const float r = float(tree.
cell( node_base + node_index + 1u ));
145 const float sum = float( l + r );
151 if (v * sum < l || r == 0.0f)
153 node_index = node_index * 2u;
158 node_index = (node_index + 1u) * 2u;
170 const float l = node_index < size ? float(tree.
cell( node_index )) : 0.0f;
171 const float r = node_index + 1u < size ? float(tree.
cell( node_index + 1u )) : 0.0f;
172 const float sum = float( l + r );
174 node_index = (v * sum < l || r == 0.0f) ? node_index : node_index + 1u;
178 return node_index < size ? node_index : size - 1u;