change sm->new_block() to return an optional

This commit is contained in:
Joe Thornber
2011-11-16 12:53:37 +00:00
parent 404ca5ba30
commit 876dd2427f
6 changed files with 59 additions and 22 deletions

View File

@@ -52,15 +52,19 @@ namespace persistent_data {
nr_free_++;
}
block_address new_block() {
for (block_address i = 0; i < counts_.size(); i++)
maybe_block new_block() {
return new_block(0, counts_.size());
}
maybe_block new_block(block_address begin, block_address end) {
for (block_address i = begin; i < min(end, counts_.size()); i++)
if (counts_[i] == 0) {
counts_[i] = 1;
nr_free_--;
return i;
}
throw std::runtime_error("no space");
return maybe_block();
}
bool count_possibly_greater_than_one(block_address b) const {