pub struct NodeStore { /* private fields */ }Expand description
A node coordinate store with automatic backend selection.
Provides O(1) lookup of (lat, lon) by OSM node ID. Automatically selects
between a dense memory-mapped backend (for builds that fit in RAM), a
buffered file backend (for planet builds with --node-store), a
file-backed direct I/O backend, and a sparse HashMap backend (for regional
extracts).
Implementations§
Source§impl NodeStore
impl NodeStore
Sourcepub fn create(
path: &Path,
max_node_id: u64,
force_dense: bool,
) -> Result<NodeStore, GeolithError>
pub fn create( path: &Path, max_node_id: u64, force_dense: bool, ) -> Result<NodeStore, GeolithError>
Create a new node store with automatic backend selection.
If force_dense is true (i.e. --node-store was explicitly provided):
- When the required size fits within
MAX_RAM_FRACTIONof RAM, use dense mmap. - When it exceeds that threshold, use the buffered file backend which buffers writes in a sharded page cache and switches to mmap for reads after pass 1.
When force_dense is false, falls back to sparse HashMap for sizes
that exceed RAM (regional extract behaviour).
§Errors
Returns an error if the file cannot be created or opened.
Sourcepub fn check_reads(&self) -> Result<(), GeolithError>
pub fn check_reads(&self) -> Result<(), GeolithError>
Fail when a read of the backing file failed since the store was made.
NodeStore::get answers None for a node it cannot read, as it does
for an empty slot. Call this after the reads of a pass to tell the two
apart: a build must stop on a bad read rather than drop the nodes.
§Errors
GeolithError::NodeStore with the OS error of the first failed read.
Sourcepub fn open(path: &Path) -> Result<NodeStore, GeolithError>
pub fn open(path: &Path) -> Result<NodeStore, GeolithError>
Open an existing node store for reading and writing.
Attempts to open as dense mmap first. If the file is too large to mmap (e.g. a 97 GB planet node store), falls back to file-backed I/O.
§Errors
Returns an error if the file doesn’t exist or can’t be opened.
Sourcepub fn put(
&mut self,
node_id: u64,
lat: f64,
lon: f64,
) -> Result<(), GeolithError>
pub fn put( &mut self, node_id: u64, lat: f64, lon: f64, ) -> Result<(), GeolithError>
Store a node’s coordinates.
Encodes latitude and longitude as i32 fixed-point (1e-7 precision).
§Errors
Returns an error if node_id is outside a dense or file-backed
store, or if writing the backing file fails.
Sourcepub fn get(&self, node_id: u64) -> Option<(f64, f64)>
pub fn get(&self, node_id: u64) -> Option<(f64, f64)>
Look up a node’s coordinates by ID.
Returns None if the node ID is out of range or the slot is empty.
Sourcepub fn concurrent_writer(
&mut self,
) -> Result<ConcurrentNodeWriter<'_>, GeolithError>
pub fn concurrent_writer( &mut self, ) -> Result<ConcurrentNodeWriter<'_>, GeolithError>
Create a concurrent writer handle for parallel node collection.
For the dense backend, the returned ConcurrentNodeWriter allows
multiple threads to write node coordinates simultaneously without
locking (each node ID maps to a unique 8-byte slot).
For the buffered file backend, writes go through sharded page cache with per-shard locking for high concurrency.
For the file backend, uses pwrite which is thread-safe on Unix at
non-overlapping offsets (each node ID is unique).
For the sparse backend, writes go through a Mutex<HashMap>.
The writer borrows the store mutably until it is finished, so the store
cannot be read while the writer is alive. Call
ConcurrentNodeWriter::finish to give the data back.
§Errors
Returns an error if a page cache shard was poisoned by a panicked writer.
Sourcepub fn flush(&self) -> Result<(), GeolithError>
pub fn flush(&self) -> Result<(), GeolithError>
Flush all pending writes to the backing file.
- Dense: flushes the mmap to disk.
BufferedFile: flushes all remaining cached pages to the backing file.- File: no-op —
preadin the same process always seespwriteresults. - Sparse: no-op (data is in memory).
§Errors
Returns an error if the dense mmap flush or buffered file I/O fails.
Sourcepub fn prepare_for_reads(&mut self) -> Result<(), GeolithError>
pub fn prepare_for_reads(&mut self) -> Result<(), GeolithError>
Transition from write mode to read mode.
For the buffered file backend:
- Flushes all remaining cached pages to disk via
pwrite. - Drops the page cache (frees memory).
- Opens a read-only mmap over the completed file with
MADV_RANDOM. - Replaces the backend with
Densefor O(1) reads.
No-op for other backends (Dense already supports reads, File uses pread, Sparse is in-memory).
§Errors
Returns an error if the mmap creation fails.
Auto Trait Implementations§
impl !Freeze for NodeStore
impl !RefUnwindSafe for NodeStore
impl !UnwindSafe for NodeStore
impl Forget for NodeStore
impl Move for NodeStore
impl Send for NodeStore
impl Sync for NodeStore
impl Unpin for NodeStore
impl UnsafeUnpin for NodeStorewhere
*mut c_void: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Mutex<HashMap<u64, Box<[u8; 4096]>>>>: UnsafeUnpin,
*const ArcInner<File> is !null: UnsafeUnpin,
PhantomData<ArcInner<File>>: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<(u64, u64)>: UnsafeUnpin,
Align4<u32>: UnsafeUnpin,
*const () is !null: UnsafeUnpin,
PhantomData<ErrorData<CustomOwner>>: UnsafeUnpin,
PhantomData<Error>: UnsafeUnpin,
I32NotAllOnes: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.