Expand description
Generate a random directory tree that can be commited to disk all at once. The general formula goes like this -
use {rand::{Rng, SeedableRng, rngs::StdRng}, static_tree::{EntryDistribution, DirectoryEntry}};
let mut rng = StdRng::seed_from_u64(seed);
let dist = EntryDistribution::new(depth);
let tree: DirectoryEntry = rng.sample(&dist);
tree.write_tree_at(root).expect("failed to write tree");
Structs§
- A directory entry in the generated tree. Contains a randomly generated u64 for a name and a vector of randomly generated directory entries, with a number of entries somewhere in the range of [0, 6). The sample function generates the entire subtree depth-first before returning, and is mutually recursive with the
Entry
sample function. - A random distribution specialized to generation of random directory trees. This distribution decreases the likelyhood of a directory being generated linearly relative to the depth of the subset of the tree being generated, until it’s 0% at the maximum depth.
- A file entry in the generated tree. Contains a randomly generated u64 for a name and randomly generated byte contents. The file size is random, in a range of 1 byte to 2^16 bytes (~65kb).
Enums§
- An entry of either File or Directory. The chance of it being a directory is relative to the depth recorded in EntryDistribution. The associated entry is also then generated.