diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/fst/src/raw/registry_minimal.rs | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/fst/src/raw/registry_minimal.rs')
-rw-r--r-- | vendor/fst/src/raw/registry_minimal.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/fst/src/raw/registry_minimal.rs b/vendor/fst/src/raw/registry_minimal.rs new file mode 100644 index 000000000..663b0123a --- /dev/null +++ b/vendor/fst/src/raw/registry_minimal.rs @@ -0,0 +1,53 @@ +// This module is a drop-in but inefficient replacement of the LRU registry. +// In particular, this registry will never forget a node. In other words, if +// this registry is used during construction, then you're guaranteed a minimal +// FST. +// +// This is really only meant to be used for debugging and experiments. It is +// a memory/CPU hog. +// +// One "easy" improvement here is to use an FNV hash instead of the super +// expensive SipHasher. + +#![allow(dead_code)] + +use std::collections::hash_map::{Entry, HashMap}; + +use crate::raw::build::BuilderNode; +use crate::raw::CompiledAddr; + +#[derive(Debug)] +pub struct Registry { + table: HashMap<BuilderNode, RegistryCell>, +} + +#[derive(Debug)] +pub enum RegistryEntry<'a> { + Found(CompiledAddr), + NotFound(&'a mut RegistryCell), + Rejected, +} + +#[derive(Clone, Copy, Debug)] +pub struct RegistryCell(CompiledAddr); + +impl Registry { + pub fn new(table_size: usize, _lru_size: usize) -> Registry { + Registry { table: HashMap::with_capacity(table_size) } + } + + pub fn entry<'a>(&'a mut self, bnode: &BuilderNode) -> RegistryEntry<'a> { + match self.table.entry(bnode.clone()) { + Entry::Occupied(v) => RegistryEntry::Found(v.get().0), + Entry::Vacant(v) => { + RegistryEntry::NotFound(v.insert(RegistryCell(0))) + } + } + } +} + +impl RegistryCell { + pub fn insert(&mut self, addr: CompiledAddr) { + self.0 = addr; + } +} |