util docs cleanup pt.1

This commit is contained in:
debris 2016-02-01 14:48:38 +01:00
parent 694590e19d
commit ea13fd3c0e
3 changed files with 39 additions and 50 deletions

View File

@ -1,3 +1,5 @@
//! Calculates heapsize of util types.
use uint::*;
use hash::*;

View File

@ -8,30 +8,55 @@
//! Ethcore-util library
//!
//! ### Rust version:
//! - beta
//! - nightly
//!
//! ### Supported platforms:
//! - OSX
//! - Linux
//!
//! ### Dependencies:
//! - RocksDB 3.13
//! ### Building:
//!
//! ### Dependencies Installation:
//! - Ubuntu 14.04 and later:
//!
//! ```bash
//! # install rocksdb
//! add-apt-repository "deb http://ppa.launchpad.net/giskou/librocksdb/ubuntu trusty main"
//! apt-get update
//! apt-get install -y --force-yes librocksdb
//!
//! # install multirust
//! curl -sf https://raw.githubusercontent.com/brson/multirust/master/blastoff.sh | sh -s -- --yes
//!
//! # install nightly and make it default
//! multirust update nightly && multirust default nightly
//!
//! # export rust LIBRARY_PATH
//! export LIBRARY_PATH=/usr/local/lib
//!
//! # download and build parity
//! git clone https://github.com/ethcore/parity
//! cd parity
//! cargo build --release
//! ```
//!
//! - OSX:
//!
//! ```bash
//! # install rocksdb && multirust
//! brew update
//! brew install rocksdb
//! ```
//! brew install multirust
//!
//! - From source:
//! # install nightly and make it default
//! multirust update nightly && multirust default nightly
//!
//! ```bash
//! wget https://github.com/facebook/rocksdb/archive/rocksdb-3.13.tar.gz
//! tar xvf rocksdb-3.13.tar.gz && cd rocksdb-rocksdb-3.13 && make shared_lib
//! sudo make install
//! # export rust LIBRARY_PATH
//! export LIBRARY_PATH=/usr/local/lib
//!
//! # download and build parity
//! git clone https://github.com/ethcore/parity
//! cd parity
//! cargo build --release
//! ```
extern crate slab;
@ -89,8 +114,7 @@ pub mod triehash;
/// TODO [Gav Wood] Please document me
pub mod trie;
pub mod nibbleslice;
/// TODO [Gav Wood] Please document me
pub mod heapsizeof;
mod heapsizeof;
pub mod squeeze;
/// TODO [Gav Wood] Please document me
pub mod semantic_version;
@ -114,7 +138,6 @@ pub use crypto::*;
pub use triehash::*;
pub use trie::*;
pub use nibbleslice::*;
pub use heapsizeof::*;
pub use squeeze::*;
pub use semantic_version::*;
pub use network::*;

View File

@ -1,40 +1,4 @@
//! vector util functions
use std::ptr;
/// TODO [debris] Please document me
pub trait InsertSlice<T> {
/// TODO [debris] Please document me
fn insert_slice(&mut self, index: usize, elements: &[T]);
}
/// based on `insert` function implementation from standard library
impl<T> InsertSlice<T> for Vec<T> {
fn insert_slice(&mut self, index: usize, elements: &[T]) {
let e_len = elements.len();
if e_len == 0 {
return;
}
let len = self.len();
assert!(index <= len);
// space for the new element
self.reserve(e_len);
unsafe {
{
let p = self.as_mut_ptr().offset(index as isize);
let ep = elements.as_ptr().offset(0);
// shift everything by e_len, to make space
ptr::copy(p, p.offset(e_len as isize), len - index);
// write new element
ptr::copy(ep, p, e_len);
}
self.set_len(len + e_len);
}
}
}
//! Vector extensions.
/// Returns len of prefix shared with elem
///