| 1193 | } |
| 1194 | |
| 1195 | bool BTreeDatabase::flattenVisitor(BTreeImpl::Index& index, BlockIndex& count) { |
| 1196 | auto pointerCount = index->pointerCount(); |
| 1197 | count += pointerCount; |
| 1198 | bool canStore = !m_availableBlocks.empty(); |
| 1199 | |
| 1200 | bool needsStore = false; |
| 1201 | if (m_impl.indexLevel(index) == 0) { |
| 1202 | for (size_t i = 0; i != pointerCount; ++i) { |
| 1203 | auto indexPointer = index->pointer(i); |
| 1204 | auto tailBlocks = leafTailBlocks(indexPointer); |
| 1205 | if (canStore) { |
| 1206 | bool leafNeedsStore = m_availableBlocks.first() < indexPointer; |
| 1207 | |
| 1208 | if (!leafNeedsStore) |
| 1209 | for (size_t i = 0; !leafNeedsStore && i != tailBlocks.size(); ++i) |
| 1210 | if (m_availableBlocks.first() < tailBlocks[i]) |
| 1211 | leafNeedsStore = true; |
| 1212 | |
| 1213 | if (leafNeedsStore) { |
| 1214 | auto leaf = m_impl.loadLeaf(indexPointer); |
| 1215 | m_impl.deleteLeaf(leaf); |
| 1216 | leaf->self = InvalidBlockIndex; |
| 1217 | index->updatePointer(i, m_impl.storeLeaf(leaf)); |
| 1218 | tailBlocks = leafTailBlocks(leaf->self); |
| 1219 | needsStore = true; |
| 1220 | } |
| 1221 | canStore = !m_availableBlocks.empty(); |
| 1222 | } |
| 1223 | count += tailBlocks.size(); |
| 1224 | } |
| 1225 | } else { |
| 1226 | for (size_t i = 0; i != pointerCount; ++i) { |
| 1227 | auto childIndex = m_impl.loadIndex(index->pointer(i)); |
| 1228 | if (canStore && flattenVisitor(childIndex, count)) { |
| 1229 | m_impl.deleteIndex(childIndex); |
| 1230 | childIndex->self = InvalidBlockIndex; |
| 1231 | index->updatePointer(i, m_impl.storeIndex(childIndex)); |
| 1232 | canStore = !m_availableBlocks.empty(); |
| 1233 | needsStore = true; |
| 1234 | } |
| 1235 | } |
| 1236 | } |
| 1237 | return needsStore || (canStore && m_availableBlocks.first() < index->self); |
| 1238 | } |
| 1239 | |
| 1240 | void BTreeDatabase::checkIfOpen(char const* methodName, bool shouldBeOpen) const { |
| 1241 | if (shouldBeOpen && !m_open) |
nothing calls this directly
no test coverage detected