From e95a0a3165a5091fef706ec988ed2a6baa64f8a0 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 23 Dec 2023 21:16:49 -0500 Subject: [PATCH] Add Directory::get_approx_byte_size and bump MSRV (#29) For cache eviction purposes, it is important to know the size of the directory objects. Also, I ran `cargo msrv` to figure out the minimal one. --- Cargo.toml | 4 ++-- src/directory.rs | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index db04d0b..5beb499 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "pmtiles" -version = "0.5.1" +version = "0.5.2" edition = "2021" authors = ["Luke Seelenbinder "] license = "MIT OR Apache-2.0" description = "Implementation of the PMTiles v3 spec with multiple sync and async backends." repository = "https://github.com/stadiamaps/pmtiles-rs" keywords = ["pmtiles", "gis", "geo"] -rust-version = "1.61.0" +rust-version = "1.68.2" categories = ["science::geo"] [features] diff --git a/src/directory.rs b/src/directory.rs index 1a5ff58..3a94541 100644 --- a/src/directory.rs +++ b/src/directory.rs @@ -17,6 +17,7 @@ impl Debug for Directory { } impl Directory { + /// Find the directory entry for a given tile ID. #[cfg(any(feature = "http-async", feature = "mmap-async-tokio"))] #[must_use] pub fn find_tile_id(&self, tile_id: u64) -> Option<&DirEntry> { @@ -37,6 +38,12 @@ impl Directory { } } } + + /// Get an estimated byte size of the directory object. Use this for cache eviction. + #[must_use] + pub fn get_approx_byte_size(&self) -> usize { + self.entries.capacity() * std::mem::size_of::() + } } impl TryFrom for Directory {