| 948 | } |
| 949 | |
| 950 | void BTreeDatabase::writeFreeIndexBlock(BlockIndex blockIndex, FreeIndexBlock indexBlock) { |
| 951 | checkBlockIndex(blockIndex); |
| 952 | |
| 953 | rawWriteBlock(blockIndex, 0, FreeIndexMagic, 2); |
| 954 | DataStreamBuffer buffer(max(sizeof(BlockIndex), (size_t)4)); |
| 955 | |
| 956 | buffer.seek(0); |
| 957 | buffer.write<BlockIndex>(indexBlock.nextFreeBlock); |
| 958 | rawWriteBlock(blockIndex, 2, buffer.ptr(), sizeof(BlockIndex)); |
| 959 | |
| 960 | buffer.seek(0); |
| 961 | buffer.write<uint32_t>(indexBlock.freeBlocks.size()); |
| 962 | rawWriteBlock(blockIndex, 2 + sizeof(BlockIndex), buffer.ptr(), 4); |
| 963 | |
| 964 | for (size_t i = 0; i < indexBlock.freeBlocks.size(); ++i) { |
| 965 | buffer.seek(0); |
| 966 | buffer.write<BlockIndex>(indexBlock.freeBlocks[i]); |
| 967 | rawWriteBlock(blockIndex, 6 + sizeof(BlockIndex) + sizeof(BlockIndex) * i, buffer.ptr(), sizeof(BlockIndex)); |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | uint32_t BTreeDatabase::leafSize(shared_ptr<LeafNode> const& leaf) const { |
| 972 | size_t s = 6; |