// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include #include #include #include #include #include namespace vespalib::alloc { /* * Class that tracks free areas in a file. */ class FileAreaFreeList { std::map _free_areas; // map from offset to size std::map> _free_sizes; // map from size to set of offsets vespalib::hash_set _fences; void remove_from_size_set(uint64_t offset, size_t size); std::pair prepare_reuse_area(size_t size); public: FileAreaFreeList(); ~FileAreaFreeList(); uint64_t alloc(size_t size); void free(uint64_t offset, size_t size); void add_premmapped_area(uint64_t offset, size_t size); void remove_premmapped_area(uint64_t offset, size_t size); static constexpr uint64_t bad_offset = std::numeric_limits::max(); }; }