nibble_vec-0.1.0/.cargo_vcs_info.json0000644000000001121367575120400132240ustar00{ "git": { "sha1": "7b8ab556683ee134e5f1d6e41ae681cb51afa54b" } } nibble_vec-0.1.0/.gitignore010064400007650000024000000000541367550224200140140ustar0000000000000000/target /Cargo.lock *.swp .DS_Store .vscode nibble_vec-0.1.0/.travis.yml010064400007650000024000000002451344777537500141570ustar0000000000000000language: rust os: - linux before_script: - rustup component add rustfmt script: - cargo fmt --all -- --check - cargo test --verbose - cargo doc --no-deps nibble_vec-0.1.0/CHANGELOG.md010064400007650000024000000005451367575114500136520ustar0000000000000000Changelog ==== 0.1.0: * Semver-corrected re-release of 0.0.5 * Released 28/06/2020 0.0.5 (YANKED): * Yanked 28/06/2020 due to semver-incompatible version change * Released 27/06/2020 * Optimise implementation by using `SmallVec` (thanks @DevinR528) 0.0.4: * Released 07/11/2017 * Implement `From` and `Into` conversion traits nibble_vec-0.1.0/Cargo.lock0000644000000656151367575120400112220ustar00# This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "hermit-abi 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "autocfg" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bstr" version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "regex-automata 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "bumpalo" version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cast" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "clap" version = "2.33.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "criterion" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)", "criterion-plot 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "csv 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", "oorandom 11.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "plotters 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)", "tinytemplate 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "criterion-plot" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "crossbeam-deque" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-epoch 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "crossbeam-epoch" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "crossbeam-queue" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "crossbeam-utils" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "csv" version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bstr 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "csv-core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "csv-core" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "either" version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hermit-abi" version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "itertools" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "itoa" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "js-sys" version = "0.3.40" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "wasm-bindgen 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "log" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "maybe-uninit" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "memchr" version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "memoffset" version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "nibble_vec" version = "0.1.0" dependencies = [ "criterion 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num_cpus" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "hermit-abi 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "oorandom" version = "11.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "plotters" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "js-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)", "web-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro2" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "quote" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rayon" version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-deque 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "rayon-core 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rayon-core" version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-queue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex" version = "1.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "regex-syntax 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex-automata" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex-syntax" version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rustc_version" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ryu" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "same-file" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "semver" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "semver-parser" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde_derive" version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_json" version = "1.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "smallvec" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "textwrap" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tinytemplate" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "unicode-width" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "unicode-xid" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "walkdir" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen" version = "0.2.63" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-macro 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-backend" version = "0.2.63" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bumpalo 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-shared 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-macro" version = "0.2.63" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-macro-support 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-macro-support" version = "0.2.63" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-backend 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-shared 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-shared" version = "0.2.63" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "web-sys" version = "0.3.40" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "js-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi-util" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum bstr 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931" "checksum bumpalo 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" "checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" "checksum cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" "checksum criterion 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "63f696897c88b57f4ffe3c69d8e1a0613c7d0e6c4833363c8560fbde9c47b966" "checksum criterion-plot 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ddeaf7989f00f2e1d871a26a110f3ed713632feac17f65f03ca938c542618b60" "checksum crossbeam-deque 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" "checksum crossbeam-epoch 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" "checksum crossbeam-queue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" "checksum crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" "checksum csv 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279" "checksum csv-core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum hermit-abi 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909" "checksum itertools 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" "checksum itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" "checksum js-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "ce10c23ad2ea25ceca0093bd3192229da4c5b3c0f2de499c1ecac0d98d452177" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)" = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" "checksum maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" "checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" "checksum memoffset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8" "checksum num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" "checksum num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" "checksum oorandom 11.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a170cebd8021a008ea92e4db85a72f80b35df514ec664b296fdcbb654eac0b2c" "checksum plotters 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0d1685fbe7beba33de0330629da9d955ac75bd54f33d7b79f9a895590124f6bb" "checksum proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" "checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" "checksum rayon 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "62f02856753d04e03e26929f820d0a0a337ebe71f849801eea335d464b349080" "checksum rayon-core 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e92e15d89083484e11353891f1af602cc661426deb9564c298b270c726973280" "checksum regex 1.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" "checksum regex-automata 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" "checksum regex-syntax 0.6.18 (registry+https://github.com/rust-lang/crates.io-index)" = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum ryu 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" "checksum same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" "checksum scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)" = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" "checksum serde_derive 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)" = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" "checksum serde_json 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)" = "ec2c5d7e739bc07a3e73381a39d61fdb5f671c60c1df26a130690665803d8226" "checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" "checksum syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "e8d5d96e8cbb005d6959f119f773bfaebb5684296108fb32600c00cde305b2cd" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" "checksum tinytemplate 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6d3dc76004a03cec1c5932bca4cdc2e39aaa798e3f82363dd94f9adf6098c12f" "checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" "checksum unicode-xid 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" "checksum walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" "checksum wasm-bindgen 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)" = "4c2dc4aa152834bc334f506c1a06b866416a8b6697d5c9f75b9a689c8486def0" "checksum wasm-bindgen-backend 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)" = "ded84f06e0ed21499f6184df0e0cb3494727b0c5da89534e0fcc55c51d812101" "checksum wasm-bindgen-macro 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)" = "838e423688dac18d73e31edce74ddfac468e37b1506ad163ffaf0a46f703ffe3" "checksum wasm-bindgen-macro-support 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)" = "3156052d8ec77142051a533cdd686cba889537b213f948cd1d20869926e68e92" "checksum wasm-bindgen-shared 0.2.63 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ba19973a58daf4db6f352eda73dc0e289493cd29fb2632eb172085b6521acd" "checksum web-sys 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "7b72fe77fd39e4bd3eaa4412fd299a0be6b3dfe9d2597e2f1c20beb968f41d17" "checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" nibble_vec-0.1.0/Cargo.toml0000644000000022751367575120400112360ustar00# 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 believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "nibble_vec" version = "0.1.0" authors = ["Michael Sproul "] description = "Vector data-structure for half-byte values." documentation = "https://docs.rs/rust_nibble_vec" readme = "README.md" keywords = ["vector", "nibble", "slice", "data-structure", "collection"] categories = ["data-structures"] license = "MIT" repository = "https://github.com/michaelsproul/rust_nibble_vec" [lib] bench = false [[bench]] name = "nib_bench" harness = false [dependencies.smallvec] version = "1.0" [dev-dependencies.criterion] version = "0.3" [badges.maintenance] status = "as-is" [badges.travis-ci] repository = "michaelsproul/rust_nibble_vec" nibble_vec-0.1.0/Cargo.toml.orig010064400007650000024000000012511367575103000147140ustar0000000000000000[package] name = "nibble_vec" version = "0.1.0" description = "Vector data-structure for half-byte values." license = "MIT" authors = ["Michael Sproul "] repository = "https://github.com/michaelsproul/rust_nibble_vec" documentation = "https://docs.rs/rust_nibble_vec" readme = "README.md" keywords = ["vector", "nibble", "slice", "data-structure", "collection"] categories = ["data-structures"] edition = "2018" [dependencies] smallvec = "1.0" [dev-dependencies] criterion = "0.3" [[bench]] name = "nib_bench" harness = false [lib] bench = false [badges] travis-ci = { repository = "michaelsproul/rust_nibble_vec" } maintenance = { status = "as-is" } nibble_vec-0.1.0/LICENSE010064400007650000024000000020711344777041700130420ustar0000000000000000The MIT License (MIT) Copyright (c) 2015 Michael Sproul Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. nibble_vec-0.1.0/README.md010064400007650000024000000022061367550462700133150ustar0000000000000000NibbleVec ==== [![Build Status](https://travis-ci.org/michaelsproul/rust_nibble_vec.svg)](https://travis-ci.org/michaelsproul/rust_nibble_vec) Data-structure for storing a sequence of half-bytes. Wraps a `Vec`, providing safe and memory-efficient storage of 4-bit values. In terms of supported operations, the structure behaves kind of like a fixed length array, in that insertions into the middle of the vector are difficult (and unimplemented at present). ## Usage This code is available on the Rust package host: https://crates.io/crates/nibble_vec You can use it in your own projects by adding `nibble_vec` as a dependency in your `Cargo.toml`. ```toml [dependencies] nibble_vec = "0.0.5" ``` ## Documentation API documentation is available here: https://docs.rs/nibble_vec ## Contributors Made by: * Alexander Andreev ([@andreevlex](https://github.com/andreevlex)) * Devin Ragotzy ([@DevinR528](https://github.com/DevinR528)) * Michael Sproul ([@michaelsproul](https://github.com/michaelsproul)) * Vinzent Steinberg ([@vks](https://github.com/vks)) ## License MIT License. Copyright © Michael Sproul and contributors 2015-present. nibble_vec-0.1.0/benches/nib_bench.rs010064400007650000024000000050711367550375200157230ustar0000000000000000use criterion::{criterion_group, criterion_main, Criterion}; use nibble_vec::Nibblet; fn even_8to5() -> Nibblet { Nibblet::from_byte_vec(vec![8 << 4 | 7, 6 << 4 | 5]) } fn odd_11to9() -> Nibblet { let mut result = Nibblet::from_byte_vec(vec![11 << 4 | 10]); result.push(9); result } fn split_test(nibble_vec: &Nibblet, idx: usize) { let mut init = nibble_vec.clone(); let _tail = init.split(idx); } fn nib_split_even_bench(b: &mut Criterion) { let even_length = even_8to5(); b.bench_function("nibvec split even", |b| { b.iter(|| { split_test(&even_length, 1); split_test(&even_length, 2); }) }); } fn nib_make_split_bench(b: &mut Criterion) { b.bench_function("nibvec split odd", |b| { let odd_length = odd_11to9(); b.iter(|| { split_test(&odd_length, 0); split_test(&odd_length, 1); }) }); } fn nib_get_bench(b: &mut Criterion) { b.bench_function("nib get on vec of 9 elements", |b| { let v = vec![243, 2, 3, 251, 5, 6, 7, 8, 255]; let nv = Nibblet::from(v.clone()); b.iter(|| { for (i, _) in v.iter().enumerate() { nv.get(i); } }) }); } fn join_test(vec1: &Nibblet, vec2: &Nibblet) { let _joined = vec1.clone().join(vec2); } fn nib_join_bench(b: &mut Criterion) { b.bench_function("join even nibvec to odd nib", |b| { b.iter(|| { let v1 = even_8to5(); let v2 = odd_11to9(); join_test(&v1, &v2); join_test(&v1, &v1); }); }); } fn nib_from_into_bench(b: &mut Criterion) { b.bench_function("nib from vec and into vec", |b| { b.iter(|| { let x = vec![10, 11, 12, 13, 14, 15, 16]; let nv = Nibblet::from_byte_vec(x); let v: Vec = nv.into(); let _nv2 = Nibblet::from(v); }); }); } fn nib_cmp_bench(b: &mut Criterion) { b.bench_function("bench eq and not eq", |b| { let nv = Nibblet::from_byte_vec(vec![10, 11, 12, 13, 14, 15, 16]); let nv_eq = Nibblet::from_byte_vec(vec![10, 11, 12, 13, 14, 15, 16]); let nv_not_eq = Nibblet::from_byte_vec(vec![1, 1, 2, 3, 4, 5, 6]); b.iter(|| { let _a = nv == nv_eq; let _b = nv == nv_not_eq; let _c = nv_eq != nv_not_eq; }); }); } criterion_group!( benches, nib_split_even_bench, nib_make_split_bench, nib_join_bench, nib_get_bench, nib_from_into_bench, nib_cmp_bench ); criterion_main!(benches); nibble_vec-0.1.0/examples/debug.rs010064400007650000024000000002771367550224200153050ustar0000000000000000extern crate nibble_vec; use nibble_vec::Nibblet; fn main() { let mut v = Nibblet::from_byte_vec(vec![1 << 4 | 11, 2 << 4 | 12, 3 << 4 | 13]); v.push(4); println!("{:?}", v); } nibble_vec-0.1.0/src/lib.rs010064400007650000024000000224431367550371300137410ustar0000000000000000#[cfg(test)] mod test; use smallvec::{Array, SmallVec}; use std::convert::{From, Into}; use std::fmt::{self, Debug, Formatter}; use std::iter::FromIterator; /// A `NibbleVec` backed by a `SmallVec` with 64 inline element slots. /// This will not allocate until more than 64 elements are added. pub type Nibblet = NibbleVec<[u8; 64]>; /// A data-structure for storing a sequence of 4-bit values. /// /// Values are stored in a `Vec`, with two values per byte. /// /// Values at even indices are stored in the most-significant half of their byte, /// while values at odd indices are stored in the least-significant half. /// /// Imagine a vector of [MSB][msb-wiki] first bytes, and you'll be right. /// /// n = [_ _ | _ _ | _ _] /// /// [msb-wiki]: http://en.wikipedia.org/wiki/Most_significant_bit #[derive(Clone, Default)] pub struct NibbleVec> { length: usize, data: SmallVec, } impl> NibbleVec { /// Create an empty nibble vector. pub fn new() -> NibbleVec { NibbleVec { length: 0, data: SmallVec::new(), } } /// Create a nibble vector from a vector of bytes. /// /// Each byte is split into two 4-bit entries (MSB, LSB). #[inline] pub fn from_byte_vec(vec: Vec) -> NibbleVec { let length = 2 * vec.len(); NibbleVec { length, data: SmallVec::from_iter(vec), } } /// Returns a byte slice of the nibble vector's contents. #[inline] pub fn as_bytes(&self) -> &[u8] { &self.data[..] } /// Converts a nibble vector into a byte vector. /// /// This consumes the nibble vector, so we do not need to copy its contents. #[inline] pub fn into_bytes(self) -> Vec { self.data.to_vec() } /// Get the number of elements stored in the vector. #[inline] pub fn len(&self) -> usize { self.length } /// Returns `true` if the nibble vector has a length of 0. #[inline] pub fn is_empty(&self) -> bool { self.data.is_empty() } /// Fetch a single entry from the vector. /// /// Guaranteed to be a value in the interval [0, 15]. /// /// **Panics** if `idx >= self.len()`. #[inline] pub fn get(&self, idx: usize) -> u8 { if idx >= self.length { panic!( "NibbleVec index out of bounds: len is {}, index is {}", self.length, idx ); } let vec_idx = idx / 2; match idx % 2 { // If the index is even, take the first (most significant) half of the stored byte. 0 => self.data[vec_idx] >> 4, // If the index is odd, take the second (least significant) half. _ => self.data[vec_idx] & 0x0F, } } /// Add a single nibble to the vector. /// /// Only the 4 least-significant bits of the value are used. #[inline] pub fn push(&mut self, val: u8) { if self.length % 2 == 0 { self.data.push(val << 4); } else { let vec_len = self.data.len(); // Zero the second half of the last byte just to be safe. self.data[vec_len - 1] &= 0xF0; // Write the new value. self.data[vec_len - 1] |= val & 0x0F; } self.length += 1; } /// Split the vector into two parts. /// /// All elements at or following the given index are returned in a new `NibbleVec`, /// with exactly `idx` elements remaining in this vector. /// /// **Panics** if `idx > self.len()`. pub fn split(&mut self, idx: usize) -> NibbleVec { // assert! is a few percent slower surprisingly if idx > self.length { panic!( "attempted to split past vector end. len is {}, index is {}", self.length, idx ); } else if idx == self.length { NibbleVec::new() } else if idx % 2 == 0 { self.split_even(idx) } else { self.split_odd(idx) } } /// Split function for odd *indices*. #[inline] fn split_odd(&mut self, idx: usize) -> NibbleVec { let mut tail = NibbleVec::new(); // Perform an overlap copy, copying the last nibble of the original vector only if // the length of the new tail is *odd*. let tail_length = self.length - idx; let take_last = tail_length % 2 == 1; self.overlap_copy( idx / 2, self.data.len(), &mut tail.data, &mut tail.length, take_last, ); // Remove the copied bytes, being careful to skip the idx byte. for _ in (idx / 2 + 1)..self.data.len() { self.data.pop(); } // Zero the second half of the index byte so as to maintain the last-nibble invariant. self.data[idx / 2] &= 0xF0; // Update the length of the first NibbleVec. self.length = idx; tail } /// Split function for even *indices*. #[inline] fn split_even(&mut self, idx: usize) -> NibbleVec { // Avoid allocating a temporary vector by copying all the bytes in order, then popping them. // Possible to prove: l_d - ⌊i / 2⌋ = ⌊(l_v - i + 1) / 2⌋ // where l_d = self.data.len() // l_v = self.length let half_idx = idx / 2; let mut tail = NibbleVec::new(); // Copy the bytes. for i in half_idx..self.data.len() { tail.data.push(self.data[i]); } // Pop the same bytes. for _ in half_idx..self.data.len() { self.data.pop(); } // Update lengths. tail.length = self.length - idx; self.length = idx; tail } /// Copy data between the second half of self.data[start] and /// self.data[end - 1]. The second half of the last entry is included /// if include_last is true. #[inline] fn overlap_copy( &self, start: usize, end: usize, vec: &mut SmallVec, length: &mut usize, include_last: bool, ) { // Copy up to the first half of the last byte. for i in start..(end - 1) { // The first half is the second half of the old entry. let first_half = self.data[i] & 0x0f; // The second half is the first half of the next entry. let second_half = self.data[i + 1] >> 4; vec.push((first_half << 4) | second_half); *length += 2; } if include_last { let last = self.data[end - 1] & 0x0f; vec.push(last << 4); *length += 1; } } /// Append another nibble vector whilst consuming this vector. #[inline] pub fn join(mut self, other: &NibbleVec) -> NibbleVec { // If the length is even, we can append directly. if self.length % 2 == 0 { self.length += other.length; self.data.extend_from_slice(&other.data); return self; } // If the other vector is empty, bail out. if other.is_empty() { return self; } // If the length is odd, we have to perform an overlap copy. // Copy the first half of the first element, to make the vector an even length. self.push(other.get(0)); // Copy the rest of the vector using an overlap copy. let take_last = other.len() % 2 == 0; other.overlap_copy( 0, other.data.len(), &mut self.data, &mut self.length, take_last, ); self } } impl> PartialEq> for NibbleVec { #[inline] fn eq(&self, other: &NibbleVec) -> bool { self.length == other.length && self.data == other.data } } impl> Eq for NibbleVec {} /// Compare a `NibbleVec` and a slice of bytes *element-by-element*. /// Bytes are **not** interpreted as two `NibbleVec` entries. impl> PartialEq<[u8]> for NibbleVec { #[inline] fn eq(&self, other: &[u8]) -> bool { if other.len() != self.len() { return false; } for (i, x) in other.iter().enumerate() { if self.get(i) != *x { return false; } } true } } impl> Debug for NibbleVec { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { write!(fmt, "NibbleVec [")?; if !self.is_empty() { write!(fmt, "{}", self.get(0))?; } for i in 1..self.len() { write!(fmt, ", {}", self.get(i))?; } write!(fmt, "]") } } impl> From> for NibbleVec { #[inline] fn from(v: Vec) -> NibbleVec { NibbleVec::from_byte_vec(v) } } impl<'a, A: Array> From<&'a [u8]> for NibbleVec { #[inline] fn from(v: &[u8]) -> NibbleVec { NibbleVec::from_byte_vec(v.into()) } } impl> Into> for NibbleVec { #[inline] fn into(self) -> Vec { self.data.to_vec() } } impl<'a, A: Array> Into> for &'a NibbleVec { #[inline] fn into(self) -> Vec { self.data.to_vec() } } nibble_vec-0.1.0/src/test.rs010064400007650000024000000070061367550224200141440ustar0000000000000000use crate::{NibbleVec, Nibblet}; fn v8_7_6_5() -> Nibblet { NibbleVec::from_byte_vec(vec![8 << 4 | 7, 6 << 4 | 5]) } fn v11_10_9() -> Nibblet { let mut result = Nibblet::from_byte_vec(vec![11 << 4 | 10]); result.push(9); result } #[test] fn get() { let nv = Nibblet::from_byte_vec(vec![3 << 4 | 7]); assert_eq!(nv.get(0), 3u8); assert_eq!(nv.get(1), 7u8); } #[test] fn push() { let mut nv = Nibblet::new(); let data = vec![0, 1, 3, 5, 7, 9, 11, 15]; for val in data.iter() { nv.push(*val); } for (i, val) in data.iter().enumerate() { assert_eq!(nv.get(i), *val); } } fn split_test(nibble_vec: &Nibblet, idx: usize, first: Vec, second: Vec) { let mut init = nibble_vec.clone(); let tail = init.split(idx); assert!(init == first[..]); assert!(tail == second[..]); } #[test] fn split_even_length() { let even_length = v8_7_6_5(); split_test(&even_length, 0, vec![], vec![8, 7, 6, 5]); split_test(&even_length, 1, vec![8], vec![7, 6, 5]); split_test(&even_length, 2, vec![8, 7], vec![6, 5]); split_test(&even_length, 4, vec![8, 7, 6, 5], vec![]); } #[test] fn split_odd_length() { let odd_length = v11_10_9(); split_test(&odd_length, 0, vec![], vec![11, 10, 9]); split_test(&odd_length, 1, vec![11], vec![10, 9]); split_test(&odd_length, 2, vec![11, 10], vec![9]); split_test(&odd_length, 3, vec![11, 10, 9], vec![]); } /// Join vec2 onto vec1 and ensure that the results matches the one expected. fn join_test(vec1: &Nibblet, vec2: &Nibblet, result: Vec) { let joined = vec1.clone().join(vec2); assert!(joined == result[..]); } #[test] fn join_even_length() { let v1 = v8_7_6_5(); let v2 = v11_10_9(); join_test(&v1, &v2, vec![8, 7, 6, 5, 11, 10, 9]); join_test(&v1, &v1, vec![8, 7, 6, 5, 8, 7, 6, 5]); join_test(&v1, &Nibblet::new(), vec![8, 7, 6, 5]); join_test(&Nibblet::new(), &v1, vec![8, 7, 6, 5]); } #[test] fn join_odd_length() { let v1 = v8_7_6_5(); let v2 = v11_10_9(); join_test(&v2, &v1, vec![11, 10, 9, 8, 7, 6, 5]); join_test(&v2, &v2, vec![11, 10, 9, 11, 10, 9]); join_test(&v2, &Nibblet::new(), vec![11, 10, 9]); } #[test] fn clone() { #[allow(clippy::redundant_clone)] let v1 = v8_7_6_5().clone(); assert_eq!(v1.len(), 4); } /// Ensure that the last nibble is zeroed before reuse. #[test] fn memory_reuse() { let mut vec = Nibblet::new(); vec.push(10); vec.push(1); // Pushing. vec.split(1); vec.push(2); assert_eq!(vec.get(1), 2); // Joining. vec.split(1); vec = vec.join(&Nibblet::from_byte_vec(vec![1 << 4 | 3, 5 << 4])); assert_eq!(vec.get(1), 1); } #[test] fn from() { let v = vec![243, 2, 3, 251, 5, 6, 7, 8, 255]; let n = Nibblet::from_byte_vec(v.clone()); let n2 = Nibblet::from(&v[..]); assert_eq!(n, n2); let n3 = Nibblet::from(v); assert_eq!(n, n3); } #[test] fn into() { let v = vec![243, 2, 3, 251, 5, 6, 7, 8, 255]; { let n = Nibblet::from_byte_vec(v.clone()); let v2: Vec = n.into(); assert_eq!(v, v2); } { let n = Nibblet::from_byte_vec(v.clone()); let v2: Vec = (&n).into(); assert_eq!(v, v2); } } #[test] fn as_bytes() { let v = vec![243, 2, 3, 251, 5, 6, 7, 8, 255]; let n = Nibblet::from(&v[..]); assert_eq!(&v[..], n.as_bytes()); } #[test] fn into_bytes() { let v = vec![243, 2, 3, 251, 5, 6, 7, 8, 255]; let n = Nibblet::from(&v[..]); assert_eq!(v, n.into_bytes()); }