Overpass API regression suite coverage (Nova Scotia) / template_db/random_file.h
template_db/random_file.h
45 of 132 instrumented lines run by the suite (34.1%) at 8edf11b0419c (this file on GitHub).
runnever runcolumns: line, executions, queries (click for the queries that run the line)
1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.2 *3 * This file is part of Overpass_API.4 *5 * Overpass_API is free software: you can redistribute it and/or modify6 * it under the terms of the GNU Affero General Public License as7 * published by the Free Software Foundation, either version 3 of the8 * License, or (at your option) any later version.9 *10 * Overpass_API is distributed in the hope that it will be useful,11 * but WITHOUT ANY WARRANTY; without even the implied warranty of12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 * GNU General Public License for more details.14 *15 * You should have received a copy of the GNU Affero General Public License16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.17 */19#ifndef DE__OSM3S___TEMPLATE_DB__RANDOM_FILE_H20#define DE__OSM3S___TEMPLATE_DB__RANDOM_FILE_H22#include "random_file_index.h"23#include "types.h"24#include "lz4_wrapper.h"25#include "zlib_wrapper.h"27#include <unistd.h>29#include <cerrno>30#include <cstdio>31#include <cstdlib>32#include <limits>33#include <map>34#include <vector>37template< typename Key, typename Value >38struct Random_File39{40private:41 Random_File(const Random_File& f) {}43public:44 Random_File(Random_File_Index*);45 ~Random_File();47 Value get(Key pos);48 void put(Key pos, const Value& index);50private:51 bool changed;52 uint32 index_size;53 uint32 compression_factor;55 Raw_File val_file;56 Random_File_Index* index;57 Void_Pointer< uint8 > cache;58 uint32 cache_pos;59 uint32 block_size;61 Void_Pointer< uint8 > buffer;63 void move_cache_window(uint32 pos);64 uint32 allocate_block(uint32 data_size);65};68/** Implementation Random_File: ---------------------------------------------*/71template< typename Key, typename Value >72Random_File< Key, Value >::Random_File(Random_File_Index* index_)792644168 q cache(index_->get_block_size() * index_->get_compression_factor()), cache_pos(index->npos),812644168 q buffer(index_->get_block_size() * index_->get_compression_factor() * 2) // increased buffer size for lz485template< typename Key, typename Value >86Random_File< Key, Value >::~Random_File()89 //delete index;93template< typename Key, typename Value >94Value Random_File< Key, Value >::get(Key pos)97899582151 q return Value(cache.ptr + (pos.val() % (block_size*compression_factor/index_size))*index_size);101template< typename Key, typename Value >102void Random_File< Key, Value >::put(Key pos, const Value& val)113template< typename Key, typename Value >114void Random_File< Key, Value >::move_cache_window(uint32 pos)116 // The cache already contains the needed position.1350 .compress(cache.ptr, block_size * compression_factor, target, block_size * index->get_compression_factor());1430 .compress(cache.ptr, block_size * compression_factor, target, block_size * index->get_compression_factor() * 2);150 // Save the found position to the index.156 // Write the data at the found position.16526028151 q if ((index->get_blocks().size() <= pos) || (index->get_blocks()[pos].pos == index->npos))167 // Reset the whole cache to zero.1800 (buffer.ptr, block_size * index->get_blocks()[pos].size, cache.ptr, block_size * index->get_compression_factor());18423446146 q val_file.read(buffer.ptr, block_size * index->get_blocks()[pos].size, "Random_File:26");18623446146 q (buffer.ptr, block_size * index->get_blocks()[pos].size, cache.ptr, block_size * index->get_compression_factor());193// Finds an appropriate block, removes it from the list of available blocks, and returns it194template< typename Key, typename Value >195uint32 Random_File< Key, Value >::allocate_block(uint32 data_size)2040 = std::lower_bound(this->index->get_void_blocks().begin(), this->index->get_void_blocks().end(),209 // We have a gap of exactly the needed size.222 // We have a gap size that appears twice (or more often).223 // This is a good heuristic choice.236 // If no really matching block exists then we choose the largest one.251#endif