示例#1
0
osmium::object_id_type CommandRenumber::lookup(osmium::item_type type, osmium::object_id_type id) {
    try {
        return index(type).at(id);
    } catch (std::out_of_range&) {
        index(type)[id] = ++last_id(type);
        return last_id(type);
    }
}
示例#2
0
void CommandRenumber::read_index(osmium::item_type type, const std::string& name) {
    std::string f { filename(name) };
    int fd = ::open(f.c_str(), O_RDONLY);
    if (fd < 0) {
        // if the file is not there we don't have to read anything and can return
        if (errno == ENOENT) {
            return;
        }
        throw std::runtime_error(std::string("Can't open file '") + f + "': " + strerror(errno));
    }

    size_t file_size = osmium::util::file_size(fd);
    if (file_size % sizeof(remap_index_value_type) != 0) {
        throw std::runtime_error(std::string("index file '") + f + "' has wrong file size");
    }

    {
        osmium::util::TypedMemoryMapping<remap_index_value_type> mapping(file_size / sizeof(remap_index_value_type), false, fd);
        std::copy(mapping.begin(), mapping.end(), std::inserter(index(type), index(type).begin()));

        last_id(type) = std::max_element(mapping.begin(),
                                         mapping.end(),
                                         [](const remap_index_value_type& a,
                                            const remap_index_value_type& b) {
                                             return a.second < b.second;
                                         }
                        )->second;
    }

    close(fd);
}
示例#3
0
      TEST_F(BlStore_Test, InConsistency_Test) {
        // Adding blocks
        {
          std::vector<uint8_t> block(1000, 5);
          auto bl_store = FlatFile::create(block_store_path);
          ASSERT_TRUE(bl_store);
          // Adding three blocks
          auto id = 1u;
          bl_store->add(id, block);
          auto id2 = 2u;
          bl_store->add(id2, block);
          auto id3 = 3u;
          bl_store->add(id3, block);

          auto res = bl_store->get(id);
          ASSERT_TRUE(res);
          ASSERT_FALSE(res->empty());
          ASSERT_EQ(*res, block);
        }
        // Simulate removal of the block
        {
          // Remove file in the middle of the block store
          std::remove((block_store_path + "/0000000000000002").c_str());
          std::vector<uint8_t> block(1000, 5);
          auto bl_store = FlatFile::create(block_store_path);
          ASSERT_TRUE(bl_store);
          auto res = bl_store->last_id();
          // Must return 1
          ASSERT_EQ(res, 1);
        }
      }
示例#4
0
void MxHeap::insert(MxHeapable *t, float v)
{
    t->heap_key(v);

    add(t);
    unsigned int i = last_id();
    t->set_heap_pos(i);

    upheap(i);
}