| 173 | } |
| 174 | |
| 175 | bool test_compact() { |
| 176 | IndexFixture f("test_compact"); |
| 177 | if (!f.init()) return false; |
| 178 | |
| 179 | f.add_batch(0, 20); |
| 180 | |
| 181 | struct stat st_before; |
| 182 | stat((f.path() + "/index.bin").c_str(), &st_before); |
| 183 | |
| 184 | f.del({0, 2, 4, 6, 8, 10, 12, 14, 16, 18}); // Delete even IDs |
| 185 | f.compact(); |
| 186 | |
| 187 | struct stat st_after; |
| 188 | stat((f.path() + "/index.bin").c_str(), &st_after); |
| 189 | |
| 190 | if (st_after.st_size >= st_before.st_size) return false; |
| 191 | |
| 192 | if (f.get(1).second != "doc1") return false; |
| 193 | if (f.get(19).second != "doc19") return false; |
| 194 | |
| 195 | if (f.get(0).first == 0) return false; |
| 196 | |
| 197 | return true; |
| 198 | } |
| 199 | |
| 200 | bool test_persistence() { |
| 201 | IndexFixture f("test_persist"); |