summaryrefslogtreecommitdiffstats
path: root/vendor/gix-hashtable
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gix-hashtable')
-rw-r--r--vendor/gix-hashtable/.cargo-checksum.json1
-rw-r--r--vendor/gix-hashtable/Cargo.toml38
-rw-r--r--vendor/gix-hashtable/src/lib.rs72
3 files changed, 111 insertions, 0 deletions
diff --git a/vendor/gix-hashtable/.cargo-checksum.json b/vendor/gix-hashtable/.cargo-checksum.json
new file mode 100644
index 000000000..8fdb7129f
--- /dev/null
+++ b/vendor/gix-hashtable/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{"Cargo.toml":"9abbc611ecef09f9b709e86303afac73ecbe0af12dc6ff81fabece8454c12207","src/lib.rs":"735d08f7852539e0c50e99220535db407800392c0b61ed05c31181747e7f4dd1"},"package":"9609c1b8f36f12968e6a6098f7cdb52004f7d42d570f47a2d6d7c16612f19acb"} \ No newline at end of file
diff --git a/vendor/gix-hashtable/Cargo.toml b/vendor/gix-hashtable/Cargo.toml
new file mode 100644
index 000000000..7ff4013fb
--- /dev/null
+++ b/vendor/gix-hashtable/Cargo.toml
@@ -0,0 +1,38 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies.
+#
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
+
+[package]
+edition = "2021"
+rust-version = "1.64"
+name = "gix-hashtable"
+version = "0.1.2"
+authors = ["Pascal Kuthe <pascal.kuthe@semimod.de>"]
+include = ["src/**/*"]
+description = "A crate that provides hashtable based data structures optimized to utilize ObjectId keys"
+license = "MIT/Apache-2.0"
+repository = "https://github.com/Byron/gitoxide"
+
+[lib]
+doctest = false
+
+[dependencies.gix-hash]
+version = "^0.10.2"
+
+[dependencies.hashbrown]
+version = "0.13.1"
+features = [
+ "inline-more",
+ "raw",
+]
+default-features = false
+
+[dependencies.parking_lot]
+version = "0.12.1"
diff --git a/vendor/gix-hashtable/src/lib.rs b/vendor/gix-hashtable/src/lib.rs
new file mode 100644
index 000000000..6392a9a5c
--- /dev/null
+++ b/vendor/gix-hashtable/src/lib.rs
@@ -0,0 +1,72 @@
+//! Customized HashMap and Hasher implementation optimized for using `ObjectId`s as keys.
+//!
+//! The crate mirrors `std::collections` in layout for familiarity.
+#![deny(missing_docs, rust_2018_idioms)]
+#![forbid(unsafe_code)]
+
+use gix_hash::ObjectId;
+pub use hashbrown::{hash_map, hash_set, raw, Equivalent};
+
+/// thread-safe types
+pub mod sync {
+ /// A map for associating data with object ids in a thread-safe fashion. It should scale well up to 256 threads.
+ pub struct ObjectIdMap<V> {
+ /// Sharing is done by the first byte of the incoming object id.
+ shards: [parking_lot::Mutex<super::HashMap<gix_hash::ObjectId, V>>; 256],
+ }
+
+ impl<V> Default for ObjectIdMap<V> {
+ fn default() -> Self {
+ Self {
+ shards: std::array::from_fn(|_| parking_lot::Mutex::new(super::HashMap::default())),
+ }
+ }
+ }
+
+ /// access and modifications - we only implement what's used within the `gix-*` ecosystem.
+ impl<V> ObjectIdMap<V> {
+ /// Insert `value` at `key` and return `None` if it's the first value at that location, or `Some(previous-value)`
+ /// if `key` was already set.
+ pub fn insert(&self, key: gix_hash::ObjectId, value: V) -> Option<V> {
+ self.shards[key.as_slice()[0] as usize].lock().insert(key, value)
+ }
+ }
+}
+
+///
+pub mod hash {
+ /// A Hasher for usage with HashMap keys that are already robust hashes (like an `ObjectId`).
+ /// The first `8` bytes of the hash are used as the `HashMap` hash
+ #[derive(Default, Clone, Copy)]
+ pub struct Hasher(u64);
+
+ impl std::hash::Hasher for Hasher {
+ fn finish(&self) -> u64 {
+ self.0
+ }
+
+ #[inline(always)]
+ fn write(&mut self, bytes: &[u8]) {
+ self.0 = u64::from_ne_bytes(bytes[..8].try_into().unwrap());
+ }
+ }
+
+ /// A Hasher for usage with HashMap keys that are already robust hashes (like an `ObjectId`).
+ /// The first `8` bytes of the hash are used as the `HashMap` hash
+ #[derive(Default, Clone, Copy)]
+ pub struct Builder;
+ impl std::hash::BuildHasher for Builder {
+ type Hasher = Hasher;
+
+ fn build_hasher(&self) -> Self::Hasher {
+ Hasher::default()
+ }
+ }
+}
+
+/// A HashMap for usage with keys that are already robust hashes (like an `ObjectId`).
+/// The first `8` bytes of the hash are used as the `HashMap` hash
+pub type HashMap<K, V> = hashbrown::HashMap<K, V, hash::Builder>;
+/// A HashSet for usage with keys that are already robust hashes (like an `ObjectId`).
+/// The first `8` bytes of the hash are used as the `HashMap` hash
+pub type HashSet<T = ObjectId> = hashbrown::HashSet<T, hash::Builder>;