diff --git a/rust/radix204/Cargo.toml b/rust/radix204/Cargo.toml new file mode 100644 --- /dev/null +++ b/rust/radix204/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "radix204" +version = "0.1.0" + +[dependencies] +error-chain = "0.11" + +[dev-dependencies] +quickcheck = "0.4" +rand = "0.3" +rustc-test = "0.2" diff --git a/rust/radix204/README.md b/rust/radix204/README.md new file mode 100644 --- /dev/null +++ b/rust/radix204/README.md @@ -0,0 +1,19 @@ +# radix204 + +20-byte to 4-byte mapping using a radix tree stored on plain buffers. + +There are 2 plain buffers: + + - KeyBuffer: store 20-bytes keys and look them up using their offsets, read-only to the library. + - RadixBuffer: store radix tree nodes and key offsets, managed, read-write by the library. + +`radix204` was designed for some specific use-cases efficiently. So it does not have some generic interface, like: + + - Storing extra values + - Deletion + - Variant-length keys + - Long offset (64-bit integer) support + +Applications may want to change KeyBuffer format so a `Key` is followed by a `Value` that the application cares about. The `Value` could be a complex structure that includes a deletion flag or a link to another `Value` (linked list). + +Variant-length keys and long offsets could in theory be added at the cost of introducing many type parameters (especially around the iterator interface), and double the storage size. diff --git a/rust/radix204/src/constants.rs b/rust/radix204/src/constants.rs new file mode 100644 --- /dev/null +++ b/rust/radix204/src/constants.rs @@ -0,0 +1,9 @@ +// Copyright 2017 Facebook, Inc. +// +// This software may be used and distributed according to the terms of the +// GNU General Public License version 2 or any later version. + +use types::KeyId; + +pub const KEY_ID_MAX: KeyId = (1 << 31) - 1; +pub const KEY_LEN: usize = 20; diff --git a/rust/radix204/src/errors.rs b/rust/radix204/src/errors.rs new file mode 100644 --- /dev/null +++ b/rust/radix204/src/errors.rs @@ -0,0 +1,9 @@ +// Copyright 2017 Facebook, Inc. +// +// This software may be used and distributed according to the terms of the +// GNU General Public License version 2 or any later version. + +use types::KeyId; + +error_chain! { +} diff --git a/rust/radix204/src/lib.rs b/rust/radix204/src/lib.rs new file mode 100644 --- /dev/null +++ b/rust/radix204/src/lib.rs @@ -0,0 +1,21 @@ +// Copyright 2017 Facebook, Inc. +// +// This software may be used and distributed according to the terms of the +// GNU General Public License version 2 or any later version. + +#[cfg(test)] +extern crate test; + +#[macro_use] +extern crate error_chain; + +#[cfg(test)] +#[macro_use] +extern crate quickcheck; + +#[cfg(test)] +extern crate rand; + +pub mod types; +mod constants; +pub mod errors; diff --git a/rust/radix204/src/types.rs b/rust/radix204/src/types.rs new file mode 100644 --- /dev/null +++ b/rust/radix204/src/types.rs @@ -0,0 +1,13 @@ +// Copyright 2017 Facebook, Inc. +// +// This software may be used and distributed according to the terms of the +// GNU General Public License version 2 or any later version. + +use std::cell::RefCell; +use std::rc::Rc; + +pub type Shared = Rc>; + +pub type Key = [u8; 20]; +pub type KeyId = u32; +pub type Offset = KeyId;